How to Set Playwright Browsers Path
In this article
Setting a custom browsers path for Playwright lets you control where Playwright downloads and looks for browser binaries. This is useful for CI environments, shared caches, or systems with restricted storage. You can set the path via an environment variable or in the Playwright config file. Here’s how to do it step by step.
What You'll Need
- A Node.js project with Playwright installed (npm install @playwright/test or npm install playwright).
- Basic familiarity with your terminal and project files.
- For the config method: a
playwright.config.jsorplaywright.config.tsfile (created automatically withnpm init playwright).
Step-by-Step
- Decide which method to use. You have two main options: set the
PLAYWRIGHT_BROWSERS_PATHenvironment variable, or set thelaunchOptions.executablePathin the config. The environment variable affects all Playwright operations (install, run), while the config method only affects test runs. - Method 1: Set the environment variable (recommended for most cases). Before running any Playwright command, set the variable in your terminal. For example, on Linux/macOS:
export PLAYWRIGHT_BROWSERS_PATH=/path/to/your/browsers. On Windows (Command Prompt):set PLAYWRIGHT_BROWSERS_PATH=C:\path\to\browsers. On PowerShell:$env:PLAYWRIGHT_BROWSERS_PATH="C:\path\to\browsers". - Persist the variable (optional). To make it permanent, add the export line to your shell profile (e.g.,
.bashrc,.zshrc) or set it as a system environment variable on Windows. - Install browsers to the custom path. After setting the variable, run
npx playwright install. Playwright will download the browsers into the specified directory. If the directory doesn’t exist, it will be created. - Method 2: Set the path in the config file. Open your
playwright.config.js(or .ts). In theuseblock, add alaunchOptionsobject with anexecutablePathpointing to the browser binary. For example:use: { launchOptions: { executablePath: '/path/to/chrome' } }. This overrides the default browser path for tests. - For projects with multiple browsers, use per-project configuration. If you need different paths for different browsers, define projects in the config, each with its own
use.launchOptions.executablePath. - Verify the path is set. Run a simple test:
npx playwright test. If the path is correct, tests will run. You can also check the path by runningnpx playwright install --dry-run(if supported) or by looking at the Playwright output during installation.
Common Mistakes
- Setting the variable after installing browsers. If you install browsers first and then set the variable, Playwright will still look in the default location. Always set the variable before running
npx playwright install. - Using relative paths. Relative paths can cause confusion. Use absolute paths to avoid issues.
- Forgetting to reinstall browsers after changing the path. If you change the path, you must re-run
npx playwright installto download browsers to the new location. - Mixing up the environment variable name. It’s
PLAYWRIGHT_BROWSERS_PATH, notPLAYWRIGHT_BROWSER_PATH(singular). - Setting the path in the config but not using it for installation. The config file path only affects test execution, not the download location. You still need the environment variable or a manual download for installation.
Tips
- Use a shared cache in CI. Set
PLAYWRIGHT_BROWSERS_PATHto a directory that persists between runs (e.g.,~/.cache/ms-playwrighton Linux). This speeds up CI. - Check the default path. On Linux, the default is
~/.cache/ms-playwright. On Windows, it’s%USERPROFILE%\AppData\Local\ms-playwright. Knowing this helps you identify if your custom path is being used. - Use a
.envfile for local development. If you use dotenv, you can set the variable in a.envfile and load it in your test setup. - For Docker, set the variable in the Dockerfile. Use
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwrightto keep browsers inside the container. - If you only need one browser, you can specify it during install. For example,
npx playwright install chromiumto save time and space.
Troubleshooting
- Tests fail with "Executable doesn't exist" error. This means the browser binary is not in the expected path. Check that you ran
npx playwright installafter setting the variable, and verify the path is correct. - Browsers still download to the default location. The environment variable might not be set in the current shell. Re-export it or use the full command:
PLAYWRIGHT_BROWSERS_PATH=/path npx playwright install. - Permission denied when accessing the path. Ensure the directory is writable. On Linux, you may need to change ownership or use
sudo(though it’s better to use a user-writable directory). - Config file path is ignored. Make sure you’re editing the correct config file and that it’s being loaded. Check the file name and location (usually in the project root). Also, ensure you’re using the
launchOptionsinsideuse, not at the top level. - Path contains spaces. If your path has spaces, wrap it in quotes when setting the environment variable, and in the config use the full string with proper escaping.
- After changing the path, old browsers are still used. Playwright caches the path in some cases. Clear the cache or restart your terminal/IDE.
Frequently Asked Questions
Can I set different paths for different browsers?
Yes, you can set the environment variable to a common directory, and Playwright will create subdirectories for each browser. Alternatively, use the config file with per-project executablePath to point to specific binaries.
Does the environment variable affect the Playwright test runner?
Yes, it affects any Playwright command that launches browsers, including tests. The runner reads the variable at runtime.
What is the default path for Playwright browsers?
On Linux and macOS, it’s ~/.cache/ms-playwright. On Windows, it’s %USERPROFILE%\AppData\Local\ms-playwright.
Can I use a relative path in the config file?
Yes, but it’s resolved relative to the current working directory. For reliability, use an absolute path or a path built with path.resolve().
Do I need to reinstall browsers after changing the path?
Yes, because the browsers are not moved automatically. You must run npx playwright install again to download them to the new location.
Is it possible to use system-installed browsers instead of Playwright's?
Yes, you can set executablePath to the system browser path (e.g., /usr/bin/google-chrome). However, Playwright may not work perfectly with all system browsers due to version differences.