---
id: "caching-playwright-in-github-actions"
title: "Caching Playwright Binaries in GitHub Actions"
description: "A GitHub Actions caching strategy for Playwright browser binaries
  that reduces repeated downloads and speeds up browser-based CI runs."
pubDate: "2022-09-22T00:00:00.000Z"
tags:
  - "code"
  - "GitHub"
  - "playwright"
  - "workflows"
syndicate: false
canonicalURL: "https://justin.poehnelt.com/posts/caching-playwright-in-github-actions/"
relativeURL: "/posts/caching-playwright-in-github-actions/"
markdownURL: "/posts/caching-playwright-in-github-actions.md"
---
I’ve always enjoyed using Playwright, but never want to wait for the binaries to download. I’ve tried a few different strategies to speed this up, but the one I’ve settled on is to cache the binaries in GitHub Actions.

The primary issue that I’ve had with caching the binaries is that while the binaries can easily be cached, the operating system dependencies must also be installed if not present. The key bits are in the following steps of my GitHub workflow.

```yaml
- uses: actions/cache@v3
  id: playwright-cache
  with:
    path: |
      ~/.cache/ms-playwright
    key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
- run: npm ci
- run: npx playwright install --with-deps
  if: steps.playwright-cache.outputs.cache-hit != 'true'
- run: npx playwright install-deps
  if: steps.playwright-cache.outputs.cache-hit == 'true'
```

And it works! 🎉

[![Output for the GitHub action with Playwright browser binaries cached](https://justin.poehnelt.com/images/playwright-caching.png)](https://justin.poehnelt.com/images/playwright-caching.png)

Output for the GitHub action with Playwright browser binaries cached

If you don’t do this properly, you might run into the following error.

> Host system is missing dependencies to run browsers.

[![Missing dependencies to run browsers](https://justin.poehnelt.com/images/playwright-missing-dependencies-to-run-browsers.png)](https://justin.poehnelt.com/images/playwright-missing-dependencies-to-run-browsers.png)

Missing dependencies to run browsers

Without any caching, the build took 1 minute and 43 seconds. With caching, but still installing the host dependencies, the time was 45 seconds, plus about 17 seconds for cache loading/saving, leading to a reduction of about 40 seconds for every build.

[![Build time without caching](https://justin.poehnelt.com/images/playwright-build-time-without-caching.png)](https://justin.poehnelt.com/images/playwright-build-time-without-caching.png)

Build time without caching


[Caching Playwright Binaries in GitHub Actions](https://justin.poehnelt.com/posts/caching-playwright-in-github-actions/) © 2022 by [Justin Poehnelt](https://justin.poehnelt.com/) is licensed under CC BY-SA 4.0