User Agents

Web browsers and everyday web tech, explained

Install Playwright Packages, Browsers & CI Setup

· 5 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through manually installing Playwright packages, downloading its browser binaries, and configuring it for continuous integration (CI) environments. You'll learn the exact commands and configuration steps needed to get Playwright running locally and in a CI pipeline, without relying on automatic setup scripts.

What You'll Need

  • Node.js (version 18 or later) and npm installed on your machine.
  • A code editor or terminal access.
  • For CI: a GitHub, GitLab, or other CI platform account with a project you can modify.
  • Basic familiarity with command-line tools and YAML configuration files.

Step-by-Step

  1. Initialize your project (if not already done). Open a terminal in your project directory and run npm init -y to create a package.json file. This is where Playwright dependencies will be recorded.
  2. Install the Playwright library. Run npm install @playwright/test (for the test runner) or npm install playwright (for the library only). The @playwright/test package includes the test runner and is recommended for most projects.
  3. Install browser binaries manually. Normally, Playwright downloads browsers during installation. To do it manually, run npx playwright install to download all supported browsers (Chromium, Firefox, WebKit). To install a specific browser, use npx playwright install chromium (or firefox, webkit).
  4. Install system dependencies (Linux only). If you're on Linux, you may need additional system packages for browsers to run. Run npx playwright install-deps to install them automatically (requires sudo). Alternatively, consult the Playwright documentation for a manual list.
  5. Verify installation. Create a simple test file (e.g., test.spec.js) with a basic test that opens a page and checks a title. Run npx playwright test to confirm everything works. If you're not using the test runner, you can run a Node script that launches a browser and navigates to a URL.
  6. Configure CI environment variables (optional but recommended). Set PLAYWRIGHT_BROWSERS_PATH=0 to force Playwright to install browsers into the default cache location, which is often required in CI. Alternatively, set it to a custom path if you need to control where browsers are stored.
  7. Create a CI pipeline configuration. For GitHub Actions, create a .github/workflows/playwright.yml file. For GitLab CI, create a .gitlab-ci.yml file. The configuration should include steps to: checkout the code, set up Node.js, install dependencies (npm ci), install Playwright browsers (npx playwright install --with-deps), and run tests (npx playwright test).
  8. Cache Playwright browsers in CI (to speed up runs). In your CI configuration, add a caching step for the Playwright browser cache. For GitHub Actions, use the actions/cache action with a path like ~/.cache/ms-playwright. This avoids re-downloading browsers on every run.
  9. Run your CI pipeline. Commit your changes and push to your repository. The CI pipeline should trigger. Monitor the logs to ensure browsers install correctly and tests pass.

Common Mistakes

  • Forgetting to install browsers. Installing the npm package alone does not download browsers. You must run npx playwright install.
  • Using npm install instead of npm ci in CI. npm ci is faster and more reliable for CI environments because it installs exact versions from the lockfile.
  • Not setting PLAYWRIGHT_BROWSERS_PATH in CI. Some CI environments have restricted permissions, and without this variable, browsers may not install correctly.
  • Ignoring system dependencies on Linux. If you skip install-deps, browsers may crash with missing library errors.
  • Running tests from the wrong directory. Ensure your CI configuration runs tests from the project root where playwright.config.js is located.

Tips

  • Use a specific Playwright version. Pin your Playwright version in package.json to avoid unexpected changes when browsers are updated.
  • Run npx playwright install --with-deps in CI. This installs both browsers and system dependencies in one command, simplifying your pipeline.
  • Set a timeout for browser installation in CI. If your CI has a default timeout, increase it to accommodate browser downloads (they can take several minutes).
  • Use the Playwright Docker image for CI. If your CI supports Docker, using mcr.microsoft.com/playwright as the base image pre-installs browsers and dependencies, saving time.
  • Keep your test configuration separate. Use playwright.config.js to define test directories, browsers, and retries, so your CI file stays clean.

Troubleshooting

  • Browser fails to launch with missing libraries. Run npx playwright install-deps on your local machine or in CI. If you're on a custom Linux distribution, manually install the required packages from the Playwright docs.
  • Tests fail due to timeout when launching browser. This often happens when browsers are not fully downloaded. Delete the cache folder (~/.cache/ms-playwright) and re-run npx playwright install.
  • CI says “browser executable doesn’t exist”. Ensure you ran npx playwright install in the CI step before running tests. Also verify the PLAYWRIGHT_BROWSERS_PATH is set correctly if you customized it.
  • Permission errors when installing browsers in CI. Set PLAYWRIGHT_BROWSERS_PATH=0 to use the default cache, or specify a writable directory like /tmp/playwright.
  • npm install fails with EACCES. This is a file permission issue. Avoid using sudo with npm; instead, fix the directory ownership or use a node version manager.

Frequently Asked Questions

Do I need to install browsers for every project?

Yes, each project that uses Playwright needs its own browser installation, unless you set a shared PLAYWRIGHT_BROWSERS_PATH to a common location.

What is the difference between playwright and @playwright/test?

The playwright package provides the core automation library. @playwright/test includes the library plus a test runner with assertions, fixtures, and parallel execution.

Can I install only Chromium to save disk space?

Yes, use npx playwright install chromium. You can also configure which browsers to use in your test configuration.

How do I update Playwright to a new version?

Run npm install @playwright/test@latest to update the package, then run npx playwright install to download any new browser versions.

Why does my CI pipeline take so long on the first run?

Because it downloads browsers and dependencies. Caching the Playwright browser cache and using npm ci will speed up subsequent runs.

Can I use Playwright without a test runner?

Yes, you can write plain Node.js scripts using the playwright library. However, the test runner provides better reporting and debugging tools.