Caching Playwright's Chromium dependency

I am trying to run some quick tests before the build, to stop it from deploying if site is broken.

I have Playwright in my npm dependencies, which is sufficient in GitHub Actions, but in Netlify build it asks that I install browser dependencies.

2:16:45 PM: > npx playwright install chromium && npm run server-test && npm run build
2:16:46 PM: Downloading Chromium 102.0.5005.40 (playwright build v1005)…
2:16:48 PM: |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 100% of 129.7 Mb
2:16:51 PM: Chromium 102.0.5005.40 (playwright build v1005) downloaded to /opt/buildhome/.cache/ms-playwright/chromium-1005

That works, however the download happens every time. There is some mixed information about .cache and from looking at image’s run-build-functions.sh it doesn’t seem to be cached at this time?

  1. Any recommendations how to handle it, does it need caching from Netlify perspective?
  2. Should I open this as an issue in image’s repository to suggest support?

I’ve tried third party netlify-plugin-cache, but it’s currently broken for me.

Site dnd.rarst.net

The problem is not with the plugin, but with Node version 18. Currently, we don’t recommend using Node > 16 for 2 reasons:

  1. AWS Lambda doesn’t support it yet, so it might create issues if you use Netlify Functions
  2. Our build system has some issues, especially with the plugin like the one you faced.

You can cache Playwright Chromium by installing netlify-plugin-playwright-cache from Netlify UI or as a dependency

  1. Install from Netlify UI
  2. Install as a dependency
npm install --save-dev netlify-plugin-playwright-cache
# Or
yarn add -D netlify-plugin-playwright-cache
# Or
pnpm add -D netlify-plugin-playwright-cache

Then update netlify.toml to include the plugin:

[[plugins]]
package = "netlify-plugin-playwright-cache"

If your builds are failing due to missing executables, Remember to Clear cache and retry deploy after adding the plugin.

GitHub: GitHub - nvh95/netlify-plugin-playwright-cache: 🤖 Persist the Playwright executable between Netlify builds