Skip to main content

Fix Playwright Chromium Wayland Launch Errors on Linux X11

The Issue

If you are running Playwright tests on Linux under X11 you may experience issues where Chromium based browsers incorrectly start using the Wayland Ozone backend.

For example when running:

npx playwright codegen

Error:

[pid=520][err] [520:ERROR:ui/ozone/platform/wayland/host/wayland_connection.cc:202] Failed to connect to Wayland display: No such file or directory (2)
 
[pid=520][err] [520:ERROR:ui/ozone/platform/wayland/ozone_platform_wayland.cc:281] Failed to initialize Wayland platform
 
[pid=520][err] [520:ERROR:ui/aura/env.cc:246] The platform failed to initialize.  Exiting.

Workaround for Playwright Test

For test runs add a new project that forces the browser to use the X11 Ozone platform.

Example playwright.config.ts entry:

import { defineConfig, devices } from '@playwright/test';
 
export default defineConfig({
  projects: [
    {
      name: 'chromium-x11',
      use: {
        ...devices['Desktop Chrome'],
        launchOptions: {
          args: ['--ozone-platform=x11'],
        },
      },
    },
  ],
});

You can run tests using this project with npx playwright test --project=chromium-x11.

Workaround for Codegen

Codegen does not use the project settings set above. Instead we need to use environment variables to start Chromium using the X11 Ozone platform.

env -u WAYLAND_DISPLAY \
    -u ELECTRON_OZONE_PLATFORM_HINT \
    XDG_SESSION_TYPE=x11 \
    npx playwright codegen https://www.awilliams.me

Distro Level Browser Config

These workarounds are for Playwright bundled browsers. If you are having issues when launching the browser normally you can set the X11 Ozone Platform setting --ozone-platform=x11 in the configuration file for your browser under ~/.config.