puppeteer: Cannot enable GPU acceleration
Steps to reproduce
Tell us about your environment:
- Puppeteer version: 1.9.0
- Platform / OS version: Linux version 4.15.0-39-generic (buildd@lgw01-amd64-054) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3))
- Node.js version: v10.10.0
What steps will reproduce the problem?
- Run code given below that opens
chrome://gpu
page + takes screenshot
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ args: ['--headless'] });
const page = await browser.newPage();
await page
.goto('chrome://gpu', { waitUntil: 'networkidle0', timeout: 20 * 60 * 1000 })
.catch(e => console.log(e));
await page.screenshot({
path: 'gpu_stats.png'
});
await browser.close();
})();
- View resulting
gpu_stats.png
screenshot
What is the expected result?
Same result as in Chrome browser, in my case:
What happens instead?
This is the resulting screenshot:
I’m mainly concerned with the WebGL: Software only, hardware acceleration unavailable
vs. WebGL: Hardware accelerated but at reduced performance
, as I would like GPU acceleration for OpenGL rendering.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (1 by maintainers)
–use-gl=desktop didn’t work for me. This did.
I can verify that the following gives the same output from
chrome://gpu
:However it is clear from the rendering that the hardware acceleration is not working. From some testing, it still is 100x faster to run the same in a non-headless instance of Chrome.
@giokara Chrome headless currently relies on software WebGL by default. You can override this using the
--use-gl=desktop
flag; for example, the following works for me:More on the
--use-gl
flag could be found in Chromium sources: https://cs.chromium.org/chromium/src/ui/gl/gl_switches.cc?type=cs&q=kUseGL&sq=package:chromium&g=0&l=69Hope this helps.
@bilalmughal wondering if you could tell us how you made this work? we are still struggling with this.
UPDATE: found this Thank you!: https://mirzabilal.com/how-to-enable-hardware-acceleration-on-chrome-chromium-puppeteer-on-aws-in-headless-mode
Got it working though had to make quite a lot of changes including a driver issue etc.
Full write up can be found in this repo that has example code to automate too incase this is useful to folk:
https://github.com/jasonmayes/headless-chrome-nvidia-t4-gpu-support/tree/main
EDIT: Now updated this repo to work with both WebGL and WebGPU!
Thank you @snnn and @sanschaise for posting the link as well, I am glad it helped you and I am hopeful it will help others like me and you 🙏
Great article!
I was able to make it work on AWS Nvidia featuring GPU instance.
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 when running via puppeteer 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) See this screenshot from headless chrome://gpu
We essentially need WebGL / WebGL2 and WebGPU to be hardware supported (WebGPU Is now in Chrome stable as of 114 and new headless Chrome is Chrome itself now vs a separate thing in the past
Hardware acceleration in headless mode (with
--use-gl=egl
) stopped working for me from v19.8.0 (works on v19.7.5).Using Debian testing with Mesa 22.3.6 on Windows 11 WSL2.