Playwright "error while loading shared libraries: libnss3.so" in CI
The Chromium binary exists and starts, but ld.so cannot resolve libnss3.so because the package providing it (libnss3) is not installed. This is the single most common missing library on minimal Debian/Ubuntu images.
What this error means
A launch fails with "browserType.launch: ... error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory", often the only missing library on an otherwise working image.
browserType.launch: Target page, context or browser has been closed
Browser logs:
<launching> .../headless_shell ... error while loading shared libraries:
libnss3.so: cannot open shared object file: No such file or directoryDiagnose it: browser, server, or timing?
End-to-end failures in CI are dominated by three causes that have nothing to do with the test: the browser binary is missing, the application under test is not listening yet, or the test raced the page. Establish which before reading the assertion.
# 1. are the browsers actually installed in THIS job?
npx playwright install --with-deps chromium
npx playwright --version
# 2. is the app up before the tests start?
npx wait-on http://localhost:3000 --timeout 60000
# 3. capture evidence for the failure you cannot reproduce
npx playwright test --trace on --video retain-on-failureCommon causes
libnss3 not installed in the container
Chromium dynamically links Network Security Services; a minimal image omits libnss3, so the loader cannot start the browser.
Only some Playwright dependencies were installed
A hand-picked apt list missed libnss3, whereas playwright install-deps would have included it.
How to fix it
Let Playwright install the full dependency set
Run install-deps (or install --with-deps) so every required library, including libnss3, is present.
npx playwright install-deps chromiumInstall the package directly if you manage apt yourself
When you control the Dockerfile, add libnss3 explicitly alongside the other browser libraries.
apt-get update && apt-get install -y \
libnss3 libatk-bridge2.0-0 libgbm1 libasound2Make the browser cache safe
- Key the browser cache to the exact test-runner version. A cache restored from a different version gives you a binary that does not match the client and fails in a way that reads like a missing install.
- Install browsers after dependencies, not before; a dependency install can replace the package that owns the browser path.
- Prefer the vendor container image when the runner allows it. It removes the whole class of missing-system-library failures.
How to prevent it
- Prefer
playwright install-depsover a manual apt allowlist. - Build a custom image once with all browser libraries baked in.
- Test the image by launching a browser in a smoke step before the full suite.