chromedp: WebGL is not working using headless shell
What versions are you running?
$ go list -m github.com/chromedp/chromedp
v0.8.2
$ google-chrome-stable --version
Google Chrome 101.0.4951.64 (desktop, Arch Linux)
Chrome/102.0.5005.63 (headless shell)
$ go version
go version go1.18.2 linux/amd64
What did you do? Include clear steps.
docker run -p 9222:9222 --rm --name headless-shell chromedp/headless-shell
[0530/182008.253071:INFO:content_main_runner_impl.cc(1144)] Chrome is running in full browser mode.
DevTools listening on ws://0.0.0.0:9222/devtools/browser/5d1cb0e4-bcd0-4547-b976-f5bdedc86c31
[0530/182008.258946:WARNING:child_process_launcher_helper_posix.cc(83)] Ignoring invalid file snapshot_blob.bin
[0530/182008.260614:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0530/182008.260743:ERROR:gpu_init.cc(481)] Passthrough is not supported, GL is angle, ANGLE is swiftshader
[0530/182008.260808:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0530/182008.260865:ERROR:gpu_info_collector.cc(93)] gl::init::CreateGLContext failed
[0530/182008.260909:ERROR:gpu_info_collector.cc(348)] Could not create context for info collection.
[0530/182008.260963:ERROR:gpu_init.cc(86)] CollectGraphicsInfo failed.
[0530/182008.262619:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0530/182008.263289:WARNING:child_process_launcher_helper_posix.cc(83)] Ignoring invalid file snapshot_blob.bin
[0530/182008.269225:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0530/182008.269310:ERROR:gpu_init.cc(481)] Passthrough is not supported, GL is angle, ANGLE is swiftshader
[0530/182008.269383:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0530/182008.269428:ERROR:gpu_info_collector.cc(93)] gl::init::CreateGLContext failed
[0530/182008.269463:ERROR:gpu_info_collector.cc(348)] Could not create context for info collection.
[0530/182008.269540:ERROR:gpu_init.cc(86)] CollectGraphicsInfo failed.
[0530/182008.270843:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0530/182008.274135:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0530/182008.274225:ERROR:gpu_init.cc(481)] Passthrough is not supported, GL is angle, ANGLE is swiftshader
[0530/182008.274309:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0530/182008.274350:ERROR:gpu_info_collector.cc(93)] gl::init::CreateGLContext failed
[0530/182008.274381:ERROR:gpu_info_collector.cc(348)] Could not create context for info collection.
[0530/182008.274417:ERROR:gpu_init.cc(86)] CollectGraphicsInfo failed.
[0530/182008.275892:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0530/182008.278231:ERROR:gpu_init.cc(481)] Passthrough is not supported, GL is disabled, ANGLE is
I then have a Go code using chromedp that waits for an element to be visible, this element is visible once a canvas is successfully rendered with Three.js. I then render the webpage to a PDF file.
With chromedp’s headless shell running in Docker, it doesn’t work and hangs waiting for my element to become visible.
If I use my desktop browser launched with google-chrome-stable --headless --use-gl=swiftshader --remote-debugging-port=9222, it starts flawlessly and everything works. (--no-sandbox flag doesn’t change anything)
What did you expect to see?
No GL initialization error.
What did you see instead?
GL initialization errors. This is the root cause of my problem but I can provide a minimal working example if needed.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (11 by maintainers)
Commits related to this issue
- change legacy SwiftShader GL to SwANGLE Legacy SwiftShader GL is deprecated, and the shared libraries on which headless_shell depends have changed. The dependencies of headless_shell are found with ... — committed to ZekeLu/docker-headless-shell by ZekeLu 2 years ago
- add a test to make sure WebGL works in headless-shell For #1073 — committed to ZekeLu/chromedp by ZekeLu 2 years ago
- add a test to make sure WebGL works in headless-shell For #1073 — committed to ZekeLu/chromedp by ZekeLu 2 years ago
- add a test to make sure WebGL works in headless-shell For #1073 — committed to ZekeLu/chromedp by ZekeLu 2 years ago
- change legacy SwiftShader GL to SwANGLE Legacy SwiftShader GL is deprecated, and the shared libraries on which headless_shell depends have changed. The dependencies of headless_shell are found with ... — committed to chromedp/docker-headless-shell by ZekeLu 2 years ago
- add a test to make sure WebGL works in headless-shell For #1073 — committed to chromedp/chromedp by ZekeLu 2 years ago
Thank you for confirming!
--use-vulkan=native --use-angle=vulkanworks withchromedp/headless-shell:102.0.5005.115, but in a way that we don’t understand. The error messages do not look good.--use-vulkan=native --use-angle=vulkandoes not work withzeke/headless-shell:102.0.5005.115. But I think this is expected. Because hardware GPU is not supported yet according to https://bugs.chromium.org/p/chromium/issues/detail?id=765284.I think we can go with
--use-gl=angle --use-angle=swiftshaderfor now, and review the options after hardware GPU support is landed.Thanks for jumping in.
I worked on that issue for hours and came up with a minimal working example:
Using
docker run -p 9222:9222 chromedp/headless-shell, I get:And no WebGL canvas. So it’s definitely not working.
If I use
docker run -p 9222:9222 --rm --name headless-shell chromedp/headless-shell:101.0.4947.3, here is what I get upon starting:The PDF reports that WebGL is working:
But the canvas is blank and I don’t see the cube.
However I was finally able to render my Three.js canvas thanks to this Chromium issue: https://bugs.chromium.org/p/chromium/issues/detail?id=765284
With
docker run -p 9222:9222 chromedp/headless-shell --use-vulkan=native --use-angle=vulkan, I’m finally able to render the cube 🎉I still get initialization errors:
But everything is working as expected.
We might want to update the Dockerfile’s entrypoint or give recommandation on the README to get
chromedp/headless-shellWebGL rendering to work. At this point I still do not know if Chrome is really using Vulkan for WebGL rendering or falling back to a working default…Here are the rendered PDFs: webgl-unsupported.pdf webgl-supported-no-cube-101.0.4947.3.pdf vulkan-working.pdf