Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU is always disabled when running in headless mode. #1260

Closed
stephenash opened this issue Nov 2, 2017 · 14 comments
Closed

GPU is always disabled when running in headless mode. #1260

stephenash opened this issue Nov 2, 2017 · 14 comments

Comments

@stephenash
Copy link

I'm trying to use puppeteer to interact with a webpage that requires WebGL support. When puppeteer launches Chromium in headless mode, the --disable-gpu flag is always used. Based on https://bugs.chromium.org/p/chromium/issues/detail?id=737678#c1, that flag is not necessary on Linux or MacOS anymore.

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 0.12.0
  • Platform / OS version: macOS 10.12.6

What steps will reproduce the problem?

  1. Execute the below script (used node 8.9.0 locally).
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    // headless: false,
  });
  const page = await browser.newPage();

  // Test for webgl support
  // e.g. https://developer.mozilla.org/en-US/docs/Learn/WebGL/By_example/Detect_WebGL
  const webgl = await page.evaluate(() => {
    const canvas = document.createElement('canvas');
    const gl = canvas.getContext('webgl');
    const expGl = canvas.getContext('experimental-webgl');

    return {
      gl: gl && gl instanceof WebGLRenderingContext,
      expGl: expGl && expGl instanceof WebGLRenderingContext,
    };
  });

  console.log('WebGL Support:', webgl);

  await browser.close();
})();

What is the expected result?
WebGL Support: { gl: true, expGl: true }

What happens instead?
WebGL Support: { gl: null, expGl: null }

@ebidel
Copy link
Contributor

ebidel commented Nov 2, 2017

@aslushnikov should we only use this flag on Windows? https://chromium-review.googlesource.com/c/chromium/src/+/522068 fixed the libmesa issue on Linux.

@stephenash
Copy link
Author

I did try to add that type of logic in locally [0], but that seems to cause unit tests to fail. I'm not sure why that is, so I haven't opened a PR yet.

[0] stephenash@73387fd

@aslushnikov
Copy link
Contributor

@ebidel @stephenash it looks like protocol's Emulation.setDefaultBackgroundColorOverride doesn't work well without --disable-gpu flag.

@dosentmatter
Copy link

dosentmatter commented Dec 4, 2017

If anyone wants to ignore the defaults and run webgl in headless mode, you can just use the args instead of the options. These are just the args passed in the code without --disable-gpu. Use at your own risk though, since @aslushnikov says Emulation.setDefaultBackgroundColorOverride doesn't work well. @aslushnikov, do you have a source for this or did you just test it out yourself?

  const browser = await puppeteer.launch({
    headless: false,
    args: [
      '--headless',
      '--hide-scrollbars',
      '--mute-audio'
    ]
  });

@aslushnikov
Copy link
Contributor

@aslushnikov, do you have a source for this or did you just test it out yourself?

@dosentmatter some puppeteer screenshot tests were failing; looks like it was fixed since than so we can drop the --disable-gpu flag on linux and osx.

PR is out for a review.

@gkjohnson
Copy link

@aslushnikov

Can the flag be removed for windows now, too? From the original chromium issue #737678:

This flag is no longer necessary on Linux or macOS. It will become unnecessary on Windows as soon as bug 729961 is fixed.

It looks like that other issue #729961 is now fixed, as well.

aslushnikov added a commit to aslushnikov/puppeteer that referenced this issue Jun 4, 2019
It looks like https://crbug.com/737678 and https://crbug.com/729961
are fixed - so we shouldn't need the `--disable-gpu` flag on windows
headless.

Reference puppeteer#1260
@aslushnikov
Copy link
Contributor

@gkjohnson I wonder! Let's try dropping it #4523

@jasonmayes
Copy link

Also in need of as solution here - trying to run Web ML models on the server to automate a testing process that need GPU to execute in timely fashion using the new headless Chrome as shown here: https://developer.chrome.com/articles/new-headless/

However GPU is software only and not using the actual NVIDIA GPU attached to my Linux instance. Any fix for this would help all of us folk working in the Web ML space (Machine Learning in JavaScript)

@StrandedKitty
Copy link

@jasonmayes Any luck with this?

@jasonmayes
Copy link

@StrandedKitty
Copy link

@jasonmayes Thanks a lot! I've already found it myself and it works great on RTX 4090. This is basically the only solution that worked for me, at least on the kind of machines I'm using.

@george-activetheory
Copy link

Has anyone had any luck with this in a github action? I don't need hardware acceleration, software is fine, but i can't even get that far. I tried all the flags @jasonmayes suggested, as well as this set:

'--enable-gpu',
'--no-sandbox',
'--use-gl=angle',
'--use-angle=gl-egl',
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
'--disable-web-security',
'--disable-features=IsolateOrigins',
'--disable-site-isolation-trials'

@jasonmayes
Copy link

Not familiar with github actions but for me there was a driver issue too on linux that needed resolving before I could use those flags successfully. See first lines of my script. Does action allow you to use those drivers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants