playwright
                                
                                 playwright copied to clipboard
                                
                                    playwright copied to clipboard
                            
                            
                            
                        [BUG] can't get webgl hardware acceleration working using official docker image
Context:
- Playwright Version: 1.27.1
- Operating System: Linux RH8
- Node.js version: 16.14.2 (on hosting machine)
- Browser: Chromium
- Extra: Docker version 20.10.21
- nvidia Quadro T1000
Describe the bug
Hi,
T trying to run playwright tests using webgl hardware acceleration inside the official Microsoft docker image. Here is the way I tried to make it work and I currently out of new idea to make it work.
1/ Using my hosting machine (see hereafter description), and WITHOUT docker, I created a classic project using the npx playwright command scafolding tool. I created a basic test that assert the chromium url chrome://gpu to check the two tags "WebGL" and "WebGL2".
Using this setup, I succeed in having the correct setup.

2/ Using the same scafolded project, i tried to run the same test inside the latest docker official image, which should be : mcr.microsoft.com/playwright:v1.27.0-focal. GPU and associated libraries seems correctly configured, as far as I known. I run the docker image using --gpus all. I can call nvidia-smi inside the docker.
First time I ran the test, I get the test failed. The two flags are setup to "Software only, hardware acceleration unavailable" (see screenshot). Which is not what we want because our UI massively use WebGL (threejs app) and the test will be definitively slow.

So I googled I find additional chrome parameters to be injected via the playwright.config.js file. I tried : --use-gl=egl
And this time the flags are now "Unavailable".

I finally tried to also export the display of the docker image running to have direct access the chrome UI but I cannot get the hardware acceleration working fine.
Do you folks have any idea to make it working ?
Commands used:
npx playwright test --project=chromium (for both inside docker and on the hosting machine)
docker run --rm -e DISPLAY=${DISPLAY} -v /tmp/.X11-unix:/tmp/.X11-unix --gpus all -it -v /home/user/Documents/test-playwright:/tmp/denis mcr.microsoft.com/playwright:latest
In playwright.config.js launchOptions: { args: ["--use-gl=egl"] }
+1
Hello Tks for the pull up ! Any idea to solve this issue ? Tks
Hello there! Same issue, looking forward to any workarounds/fixes.
Have you tried --use-gl=angle? Works here in the official docker image with mapbox GL.
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
  projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
        launchOptions: { args: ['--use-gl=angle']  }
      }
    }
  ]
});
Have you tried
--use-gl=angle? Works here in the official docker image with mapbox GL.{ projects: [ { name: 'chromium', use: { ...devices['Desktop Chrome'], launchOptions: { args: ['--use-gl=angle'] } } } ] }
I have tried couple of options, this one as well.
Didn't work for me:

With image: mcr.microsoft.com/playwright:v1.30.0-focal
Hello Same issue here. Confirmed does not fix the problem.
+1
+1
I am experiencing the same issues. Are there any workarounds to get GPU running?
same
Hi all Could it be possible to have support on this issue ? We plan having a lot of tests using webgl soon and we do not know how to fix this problem... Please .. Tks again ! Denis
sadly, I faced it but that bug is in Firefox browwser, not Chromium. do you know any ideal to fixed this problem ?
@quan-nm-nexlesoft Firefox does not support WebGL in headless mode. Make sure that you run in headed mode, and you will need a virtual framebuffer for that (xvfb). Prepend your test run command with xvfb-run, e.g like this: xvfb-run npx playwright test ... or whatever.
@denisbrondy Maybe also check in Chromium whether headed vs headless mode makes a difference.
We've had HWA working in docker with playwright + headless chrome by building a custom image from the base nvcr.io/nvidia/cudagl:11.4.2-runtime-ubuntu20.04.
Found this issue while investigating as our setup stopped working with chromium after playwright 1.31.
It would be much nicer to have HWA support in the blessed microsoft playwright images
@kmannislands Did you make this image publicly available? It'd be nice if you could.
any updates?
This combination worked for me
const browser = await chromium.launch({
        headless: true,
        args: [
                '--use-gl=egl',
                '--ignore-gpu-blocklist',
                '--use-gl=angle',
        ],
    }
along with using xvfb to run it
xvfb-run node src/index.js
Logged settings
[
 'Canvas: Hardware accelerated\n' +
   'Canvas out-of-process rasterization: Disabled\n' +
   'Direct Rendering Display Compositor: Disabled\n' +
   'Compositing: Hardware accelerated\n' +
   'Multiple Raster Threads: Enabled\n' +
   'OpenGL: Enabled\n' +
   'Rasterization: Hardware accelerated\n' +
   'Raw Draw: Disabled\n' +
   'Video Decode: Hardware accelerated\n' +
   'Video Encode: Software only. Hardware acceleration disabled\n' +
   'Vulkan: Disabled\n' +
   'WebGL: Hardware accelerated\n' +
   'WebGL2: Hardware accelerated\n' +
   'WebGPU: Disabled'
]
I think I'm facing a similar issue, however what's different in my case is I have two different machines with identical setups (same packages etc) building the same dockerfile. When I test the resulting images one will have hardware acceleration enabled and the other won't, it's as if there's some contextual difference when building that I can't find.
This combination worked for me
const browser = await chromium.launch({ headless: true, args: [ '--use-gl=egl', '--ignore-gpu-blocklist', '--use-gl=angle', ], }along with using
xvfbto run it
xvfb-run node src/index.js
Thanks for sharing @ipatka. I can confirm this also worked for me.
@ipatka @StebanDev Could you please share more details, if possible? Perhaps snippets of your dockerfile?
We can't get passed xvfb-run. It hangs the docker container, regardless of what args or options passed.
@ipatka @StebanDev Could you please share more details, if possible? Perhaps snippets of your dockerfile?
We can't get passed
xvfb-run. It hangs the docker container, regardless of what args or options passed.
@aidinabedi Doesn't work for you locally or on the CI?
In my case it was working fine on github actions but to make it work locally I needed to add the --init option to the docker run command. https://docs.docker.com/engine/reference/commandline/container_run/#init
Hope it helps!
Thank you @StebanDev! I was indeed running locally. Using --init resolved xvfb-run hanging.