playwright: [BUG] Running Nightly as root in a regular user's session is not supported.

Running playwright automation in Github CI using docker image fails for Firefox

Github Actions Workflow looks as follow:

jobs:
  test_e2e:
    runs-on: self-hosted
    container:
      image: mcr.microsoft.com/playwright
      options: '--ipc=host --entrypoint /bin/bash'
    steps:
      - uses: actions/checkout@v2
      - run: npm ci --no-optional --no-audit --prefer-offline --progress=false
      - run: npm run ci:e2e

Output is:

 npm run ci:e2e
  shell: sh -e {0}

> @clap/clap-frontend@0.1.0 ci:e2e /__w/clap-ui/clap-ui
> jest -c jest-e2e.config.js

Protocol error (Browser.enable): Browser closed.
==================== Browser output: ====================
<launching> /ms-playwright/firefox-1250/firefox/firefox -no-remote -headless -profile /tmp/playwright_firefoxdev_profile-8PNwPz -juggler-pipe -silent
<launched> pid=629
[pid=629][err] Running Nightly as root in a regular user's session is not supported.  ($HOME is /github/home which is owned by pwuser.)Error
    at /__w/clap-ui/clap-ui/node_modules/playwright/lib/server/firefox/ffConnection.js:55:63
    at new Promise (<anonymous>)
    at FFConnection.send (/__w/clap-ui/clap-ui/node_modules/playwright/lib/server/firefox/ffConnection.js:54:16)
    at Function.connect (/__w/clap-ui/clap-ui/node_modules/playwright/lib/server/firefox/ffBrowser.js:65:24)
    at Firefox._connectToTransport (/__w/clap-ui/clap-ui/node_modules/playwright/lib/server/firefox/firefox.js:65:38)
    at Firefox._innerLaunch (/__w/clap-ui/clap-ui/node_modules/playwright/lib/server/browserType.js:133:36)
    at async ProgressController.run (/__w/clap-ui/clap-ui/node_modules/playwright/lib/server/progress.js:76:28)
    at async Firefox.launch (/__w/clap-ui/clap-ui/node_modules/playwright/lib/server/browserType.js:78:25)
    at async BrowserServerLauncherImpl.launchServer (/__w/clap-ui/clap-ui/node_modules/playwright/lib/browserServerImpl.js:35:25)
    at async PlaywrightRunner.launchServer (/__w/clap-ui/clap-ui/node_modules/jest-playwright-preset/lib/PlaywrightRunner.js:68:44)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @clap/clap-frontend@0.1.0 ci:e2e: `jest -c jest-e2e.config.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @clap/clap-frontend@0.1.0 ci:e2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /github/home/.npm/_logs/2021-05-11T12_50_21_530Z-debug.log
Error: Process completed with exit code 1.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 15 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@aslushnikov for help with docker.

The code in firefox is in toolkit/xre/nsAppRunner.cpp, and it checks if the directories $HOME, $XDG_RUNTIME_DIR and $XAUTHORITY are owned by the current user. Could you try running with HOME=/root npm run ci:e2e?

Update on this for future viewers…

Instead of running the tests with HOME=/root npx playwright inside the container, you can just set the --user from the jobs.<job_id>.container.options as shown in the docs here, also shown below.

name: Playwright Tests
on:
  push:
    branches: [ main, master ]
  pull_request:
    branches: [ main, master ]
jobs:
  playwright:
    name: 'Playwright Tests'
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/playwright:v1.51.1-noble
      options: --user 1001 # <----- add this to change user from `root` to `pwuser` (aka `1001`)
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: lts/*
      - name: Install dependencies
        run: npm ci
      - name: Run your tests
        run: npx playwright test

Update on this for future viewers…

Instead of running the tests with HOME=/root npx playwright inside the container, you can just set the --user from the jobs.<job_id>.container.options as shown in the docs here, also shown below.

name: Playwright Tests on: push: branches: [ main, master ] pull_request: branches: [ main, master ] jobs: playwright: name: ‘Playwright Tests’ runs-on: ubuntu-latest container: image: mcr.microsoft.com/playwright:v1.51.1-noble options: --user 1001 # <----- add this to change user from root to pwuser (aka 1001) steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: lts/* - name: Install dependencies run: npm ci - name: Run your tests run: npx playwright test

In our CI we got the following error after adding the user param:

Installing dependencies...
Switching to root user to install dependencies...
Password: su: Authentication failure

@aslushnikov Yeah, that does get round the problem:

Following https://github.com/microsoft/playwright/issues/23388#issuecomment-1571823562, using env HOME=/root npx playwright [...] worked (https://github.com/PREreview/prereview.org/commit/5e2bf8142f957da411524f367dc55b983189fcd8). (Using env is needed as the contents of the step.with.args is equivalent to a Dockerfile CMD.)

@thewilkybarkid could you help me reproducing it at the https://github.com/mxschmitt/firefox-github-actions-container repository? (feel free to create a PR there with what I did wrong)

Reopening since this is still relevant and affects the default configuration.

Repro: https://github.com/mxschmitt/firefox-github-actions-container Upstream bug which implemented it: https://bugzilla.mozilla.org/show_bug.cgi?id=1323302


Actually while looking at it again, it seems working fine: https://github.com/mxschmitt/firefox-github-actions-container

Waiting for new customer reports.

Update: I raised an issue on GitHub side, since it seems not fixable on our side except using HOME=/root as a workaround as Joel has recommended.