改善
Kaizen  · Today I Learned by Ville Säävuori

Running Playwright in GitLab CI

Had some trouble getting Playwright to run properly on GitLab CI so decided to document my learnings here.

Playwright CI documentation was helpful for tracking and tackling the problems:

Use only one browser

By default Playwright will install Chromium, Firefox and Webkit. If you don’t need all of these, there are specific versions of the package as well. As far as I can tell the only difference between the full package is the number of included browser engines.

Force install browsers

To force broser install, run:

npx playwright-cli install

Running in Gitlab CI

After trying out multiple different things, I ended up switching the runner to use mcr.microsoft.com/playwright:bionic Docker image which is not optimal as I run several other scripts in the same pipeline and wanted to optimize the install into one simple and lightweight step. This extended the pipeline runtime by about two minutes, but it works now.

I did leave the install script in which still produces an error (that it doesn’t do locally):

$ npx playwright-cli install
(node:62) UnhandledPromiseRejectionWarning: Error: EACCES: permission denied, mkdir '/builds/uninen/personal-data/.npm/_npx/20/lib/node_modules/playwright-cli/node_modules/playwright/.local-browsers'

I might revisit this sometime in the future when things mature a bit (and my nerves get a bit longer). It works, that’s enough for me for now.

Running in Vercel

Creating the browser instance with --disable-dev-shm-usage flag and adding the PLAYWRIGHT_BROWSERS_PATH=0 environment variable is all you need for Vercel.