This guide explains how to handle Playwright’s browser downloads and verify their integrity across Windows, macOS, and Linux. You’ll learn where the browsers are stored, how to confirm they are correctly installed, and how to troubleshoot common issues that arise when downloads fail or become corrupted.
What You’ll Need
- Node.js (version 18 or later) installed on your system
- A terminal or command prompt with internet access
- Playwright installed via npm (or your preferred package manager)
- Administrator or user-level permissions to write to the cache directory
Step-by-Step
- Install Playwright and its browsers. In your project directory, run
npm init -yfollowed bynpm install @playwright/test. Then executenpx playwright install. This downloads the default browser set (Chromium, Firefox, WebKit) to a system-specific cache folder. - Identify the browser cache location for your OS. The cache paths are:
– Windows:%USERPROFILE%\AppData\Local\ms-playwright
– macOS:~/Library/Caches/ms-playwright
– Linux:~/.cache/ms-playwright
You can also runnpx playwright install --dry-runto see the exact paths without downloading. - Check that the expected folders exist. Navigate to the cache directory and list its contents. You should see folders named like
chromium-XXXX,firefox-XXXX, andwebkit-XXXX, where XXXX is a revision number. If any are missing, the download was incomplete. - Verify the integrity of each browser. Run
npx playwright install --verify. This command checks that each browser’s executable is present and that the expected files are in place. It does not re-download unless something is broken. - Test a simple launch to confirm functionality. Create a minimal script (e.g.,
test.js) with the following content:
const { chromium } = require('playwright');
(async () => { const browser = await chromium.launch(); const page = await browser.newPage(); await page.goto('https://example.com'); console.log('Title:', await page.title()); await browser.close(); })();
Run it withnode test.js. If it prints the page title, the download is functional. - If using CI or Docker, ensure dependencies are installed. On Linux, run
npx playwright install-depsto install system libraries required by the browsers. This is often the cause of launch failures even when the download itself appears correct. - Set a custom cache directory if needed. You can override the default location by setting the
PLAYWRIGHT_BROWSERS_PATHenvironment variable to a path of your choice. This is useful in CI environments where the home directory is ephemeral.
Common Mistakes
- Running install without network access: The download requires a stable internet connection. A proxy or firewall may block it; use
HTTPS_PROXYenvironment variables if necessary. - Mixing versions: If you update Playwright without re-running
npx playwright install, the browsers may not match the library version. Always install after upgrading. - Ignoring Linux dependencies: On Linux, even if the browser files are present, missing system libraries (like libnss3 or libatk) will cause launch errors. Run
install-depsto fix this. - Assuming the cache is in the project folder: The browsers are stored globally in the user cache, not in
node_modules. Don’t look for them there. - Forgetting to reinstall after clearing cache: If you delete the cache manually, you must run
npx playwright installagain.
Tips
- Use
npx playwright install --with-depson Linux to install browsers and system dependencies in one step. - In CI, cache the
ms-playwrightfolder to speed up builds. For GitHub Actions, use theactions/cacheaction with the appropriate path for your OS. - If you only need one browser, install it individually, e.g.,
npx playwright install chromiumto save disk space. - Check the Playwright version with
npx playwright --versionand compare it with the browsers’ revision numbers in the cache to ensure they match. - Set
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1during npm install if you plan to manage browsers separately (e.g., in a Docker image).
Troubleshooting
If the download fails or browsers don’t work, try these steps in order:
- Re-run the install with verbose output: Use
npx playwright install --debugto see detailed logs. This often reveals network timeouts or forbidden URLs. - Clear the cache and reinstall: Delete the
ms-playwrightfolder (or the specific browser folder) and runnpx playwright installagain. This fixes corrupted downloads. - Check disk space: Browsers take about 400 MB each. Ensure you have at least 1 GB free.
- Verify environment variables: If you have
PLAYWRIGHT_BROWSERS_PATHset, make sure it points to a writable location. Also check thatHOMEorUSERPROFILEis correct. - Test the browser executable directly: Navigate to the cache folder and run the executable (e.g.,
chrome-win/chrome.exeon Windows) to see if it launches standalone. If it doesn’t, the download is incomplete. - For Linux, run
lddon the executable: This shows missing shared libraries. Install them via your package manager or usenpx playwright install-deps. - If all else fails, reinstall Playwright: Uninstall with
npm uninstall @playwright/test, deletenode_modulesandpackage-lock.json, then reinstall and runnpx playwright install.
Frequently Asked Questions
Q: How do I know which browser version is installed?
Run npx playwright install --dry-run to see the expected revision numbers. Then check the folder names in the cache directory—they include the revision number.
Q: Can I use system-installed browsers instead of Playwright’s downloads?
Yes, you can use the channel option in launch, e.g., chromium.launch({ channel: 'chrome' }), but this is not recommended for CI because it’s less reproducible.
Q: Why does Playwright download browsers again after I update the library?
Each Playwright version pins specific browser revisions. Updating the library requires matching browser builds, so you must re-run npx playwright install.
Q: Is it safe to delete the cache folder?
Yes, but you’ll need to re-download the browsers next time you run tests. It’s a common first step in troubleshooting corrupted installations.
Q: How long does the download take?
It depends on your internet speed. Typically 1-3 minutes for all three browsers, but can be longer on slow connections. Use --only-shell to download a minimal browser for testing quickly.
Q: Can I install browsers for all platforms from one machine?
No, Playwright downloads the binaries for the current OS only. To test on other platforms, use CI services or virtual machines.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Campus Tech Innovation Hubs: What They Are
- Poco C51 Airtel Prepaid Locked Variant India?
- Jenkins vs GitHub Actions: Which CI/CD Fits Your Team?
- Turn Off Backup Encryption in iTunes?
- Shared VPS Hosting: Is It Better?
- Disk Defrag Pro: What It Does and Whether You Need It