microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
63.8k stars 3.45k forks source link

[Feature]: Enable GPU Hardware Acceleration by default on the Headless mode. #11627

Open rkunwar opened 2 years ago

rkunwar commented 2 years ago

We currently are writing a browser tests for our application that involves a heavy use of WebGL for rendering graphics. Running tests on '--headed' mode is all running fine, however when we want to run the tests on CI pipelines or even locally in '--headless' mode, we have issues with tests taking super long time to render graphics and leads to the test failure several times.

For now we have found a workaround that enables to use Hardware Acceleration on '--headless' mode by enabling this flag on MAC OSX. await chromium.launch( {args: [ // This works in MAC '--use-gl=egl', '--use-gl=egl' ]},)

We are still facing the issue when it comes to the use in Windows as above browser launch arguments does not seem to work on Windows System.

This is very important for us to be able to run the tests on CI Pipeline as currently we are having to manually trigger the test on '--headed' mode on Windows systems.

I feel this will be useful for anyone running tests that involves the use of WebGL and heavy graphics. Other parts of application that do not use the WebGL is running fine on '--headless' mode.

I have attached the screenshots with the sample how long the difference is in running the tests.

Screen Shot 2022-01-26 at 8 19 51 am Screen Shot 2022-01-26 at 8 19 44 am
Krahegwen commented 2 years ago

It would be great to know how to run the hardware acceleration in windows and in linux in headless mode

dazfuller commented 2 years ago

This would be great to know as I'm doing the same thing and trying to run the tests in DevOps pipelines running on Ubuntu

JCMais commented 2 years ago

Was anyone able to run with hardware acceleration enabled while in headless mode on Linux?

ngustavo commented 1 year ago

For those having issues with this on Windows, it worked for me using:

{
  channel: "chrome",
  args: [
    "--use-angle=vulkan",
  ],
}

If that won't work, maybe tinker with these:

[
  // "--enable-features=Vulkan,UseSkiaRenderer",
  // "--use-vulkan=swiftshader",
  // "--use-gl=swiftshader",
  // "--ignore-gpu-blacklist",
  // "--enable-unsafe-webgpu",
  // "--disable-vulkan-fallback-to-gl-for-testing",
],
nicholasks commented 1 year ago

I'm on Ubuntu 22.04, I've tried different args but --enable-gpu was the only one that allowed me to run WebGL in headless mode.

launchOptions: {
    // Force hardware acceleration
    args: ["--enable-gpu"],
}

https://peter.sh/experiments/chromium-command-line-switches/#enable-gpu

nikolas-garza-1 commented 6 months ago

This configuration is working for me. Ubuntu 20.04

    launchOptions: {
      args: [
        '--ignore-gpu-blocklist',
        '--use-gl=angle',
        '--use-angle=gl-egl',
      ],
    },