Browser Installation and Caching
What You'll Learn
You'll learn how to significantly speed up your CI pipeline by caching Playwright browsers and dependencies so they don't need to be re-downloaded on every test run.
The Problem: Downloading Browsers Is Slow
Every time Playwright runs in CI, it needs Chromium, Firefox, and WebKit binaries installed. Without caching, these get downloaded fresh each time—adding 1-3 minutes per build. That's like re-downloading a video game every time you want to play it.
The Solution: Cache Playwright's Browser Directory
Playwright stores browsers in a specific directory (usually ~/.cache/ms-playwright on Linux). Your CI workflow can cache this directory between runs using the same cache key pattern you used for node_modules.
In GitHub Actions, add this to your workflow file:
- name: Get installed Playwright version
id: playwright-version
run: echo "PLAYWRIGHT_VERSION=$(npm list @playwright/test --depth=0 --json | jq -r '.dependencies["@playwright/test"].version')" >> $GITHUB_OUTPUT
- name: Cache Playwright browsers
uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright
key: playwright-browsers-${{ steps.playwright-version.outputs.PLAYWRIGHT_VERSION }}
- name: Install Playwright browsers
run: npx playwright install --with-deps
if: steps.cache-playwright.outputs.cache-hit != 'true'
The cache key includes the Playwright version, so browsers are re-downloaded only when you upgrade Playwright—exactly when they need updating.
Why This Matters
Without caching: 2-3 minutes downloading browsers every run.
With caching: ~5 seconds on cache hits.
Key Takeaway: Cache Playwright's browser directory using a version-specific key to avoid re-downloading hundreds of megabytes of browser binaries on every CI run, dramatically reducing build times.