playwright: [BUG] The official Docker image doesn't work with non root user

Context:

  • Playwright Version: [what Playwright version do you use?] 1.0.2
  • Operating System: [e.g. Windows, Linux or Mac] Linux Debian 10
  • Node version: [e.g. 10.12, 10.14] 12
  • Browser: [e.g. All, Chromium, Firefox, WebKit] All
  • Extra: [any specific details about your environment] Docker I am running playwright in Docker using the exact docker image from your github repo Error
VError: a BeforeAll hook errored, process exiting: features/support/playwright.js:14: Failed to launch browser: Error: spawn /home/pwuser/.cache/ms-playwright/firefox-1089/firefox/firefox ENOENT

I think the problem comes from installing The browsers to /root folder: /root/.cache/ms-playwright/chromium-764964 and the user not being able to access them when running playwright.

> node install.js
chromium v764964 downloaded to /root/.cache/ms-playwright/chromium-764964

firefox v1089 downloaded to /root/.cache/ms-playwright/firefox-1089

webkit v1219 downloaded to /root/.cache/ms-playwright/webkit-1219

Code Snippet

  global.browser = await pw.chromium.launch({ headless: process.env.HEADLESS !== "false" });

Describe the bug

Note that the same happens with chrome

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 22 (11 by maintainers)

Most upvoted comments

@haikyuu is there a reason you want to copy everything and install under root rather than non-privileged user the tests are running under? Basically rearranging your docker file like this:

USER pwuser

COPY --chown=pwuser:pwuser . /home/pwuser/project
WORKDIR /home/pwuser/project/e2e
RUN npm install

RUN npm run e2e

This way the browsers should go into pwuser home dir and the user should have permissions to access everything installed this way.

@tajo as @arjun27 pointed out you can build missing libjpeg from source, something like this should work.

This works. You guys are great. Thanks!

@tajo as @arjun27 pointed out you can build missing libjpeg from source, something like this should work:

FROM node:12-buster
....
# Build libjpeg from source
RUN cd /tmp && wget http://www.ijg.org/files/jpegsrc.v8d.tar.gz && tar zxvf jpegsrc.v8d.tar.gz && cd jpeg-8d && ./configure && make && make install

# Run everything after as non-privileged user.
USER node

# Add manually built libraries to the search path
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
...

This is not exactly libjpeg-turbo8 we are using but it should fix the missing dependency issue.

Sure, here is the exact Dockerfile

FROM node:12-buster
# Copied from :https://github.com/microsoft/playwright/blob/v1.0.2/docs/docker/Dockerfile.bionic

# FROM ubuntu:bionic
# COPY --from=0 /schoolibri/ /schoolibri

RUN apt-get update
# 2. Install WebKit dependencies
RUN apt-get install -y libwoff1 \
                       libopus0 \
                       libwebp6 \
                       libwebpdemux2 \
                       libenchant1c2a \
                       libgudev-1.0-0 \
                       libsecret-1-0 \
                       libhyphen0 \
                       libgdk-pixbuf2.0-0 \
                       libegl1 \
                       libnotify4 \
                       libxslt1.1 \
                       libevent-2.1-6 \
                       libgles2 \
                       libvpx5

# 3. Install Chromium dependencies

RUN apt-get install -y libnss3 \
                       libxss1 \
                       libasound2

# 4. Install Firefox dependencies

RUN apt-get install -y libdbus-glib-1-2 \
                       libxt6

# 5. Install ffmpeg to bring in audio and video codecs necessary for playing videos in Firefox.

RUN apt-get install -y ffmpeg

# 6. Add user so we don't need --no-sandbox in Chromium
RUN groupadd -r pwuser && useradd -r -g pwuser -G audio,video pwuser \
    && mkdir -p /home/pwuser/Downloads \
    && chown -R pwuser:pwuser /home/pwuser


# 7. (Optional) Install XVFB if there's a need to run browsers in headful mode
RUN apt-get install -y xvfb

# Run everything after as non-privileged user.
USER node
RUN mkdir /home/node/repo
WORKDIR /home/node/repo
RUN npm init --yes
RUN npm install playwright 

I don’t know what’s the problem. But i suspect it’s about the base image, since you’re using bionic and i’m using buster.

I would happily switch, but there is no bionic official image for node. And manually installing node in popped up a lot of EACCESS issues and was incompatible with our setup.

Here is the command to use to run the docker container docker run --rm -it <id> bash -il

Here is the last lines of the logs

tep 12/13 : RUN npm init --yes
 ---> Running in cda43e5ef8eb
Wrote to /home/node/repo/package.json:

{
  "name": "repo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


Removing intermediate container cda43e5ef8eb
 ---> b60453270f3a
Step 13/13 : RUN npm install playwright
 ---> Running in 4dd65bbc6735

> playwright@1.0.2 install /home/node/repo/node_modules/playwright
> node install.js


chromium v764964 downloaded to /home/node/.cache/ms-playwright/chromium-764964

firefox v1089 downloaded to /home/node/.cache/ms-playwright/firefox-1089

webkit v1219 downloaded to /home/node/.cache/ms-playwright/webkit-1219
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN repo@1.0.0 No description
npm WARN repo@1.0.0 No repository field.

+ playwright@1.0.2
added 38 packages from 82 contributors and audited 38 packages in 70.54s

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

 Removing intermediate container 4dd65bbc6735
 ---> fcf7f12dcdf9
Successfully built fcf7f12dcdf9
admin@ip-172-16-1-171:~/mono$ docker run --rm -it fcf7f12dcdf9 bash -il
node@860b28f649ab:~/repo$ ls
node_modules  package-lock.json  package.json
node@860b28f649ab:~/repo$ node
Welcome to Node.js v12.18.0.
Type ".help" for more information.
> require("playwright").chromium.launch().then(console.log)
Promise { <pending> }
> (node:11) UnhandledPromiseRejectionWarning: Error: Protocol error (Target.setAutoAttach): Target closed.
    at /home/node/repo/node_modules/playwright-core/lib/chromium/crConnection.js:130:63
    at new Promise (<anonymous>)
    at CRSession.send (/home/node/repo/node_modules/playwright-core/lib/chromium/crConnection.js:129:16)
    at CRSession.<anonymous> (/home/node/repo/node_modules/playwright-core/lib/helper.js:64:31)
    at Function.connect (/home/node/repo/node_modules/playwright-core/lib/chromium/crBrowser.js:63:27)
    at Chromium.launch (/home/node/repo/node_modules/playwright-core/lib/server/chromium.js:41:53)
(node:11) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:11) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.