Playwright: “Failed to launch Browsers” — how to solve?
Are you facing issues with launching Playwright’s browsers locally or in your CI? Do you get the below error? If so, you’re at the right spot!
“Error: Failed to launch chromium because executable doesn’t exist”
This post explains how to solve the above issue in the CI. We use Playwright with the CodeceptJS framework, and often saw the above error with Playwright executions in our Jenkins CI and made our builds very flaky 🤯
After googling more about the issue, I came across the Existing Issue on the Playwright and noticed that there are many other folks facing a similar issue.
🔺 Playwright Issue: https://github.com/microsoft/playwright/issues/4033
🚫 The issue was closed but unfortunately, there aren’t any solutions that worked for us.
⚠️ First, let’s take a look Why this happens?
“Each version of Playwright needs specific versions of browser binaries to operate. By default, and if lucky, Playwright downloads Chromium, WebKit, and Firefox browsers into the OS-specific cache folders — But We have seen this failing intermittently in our CI System and makes our CI flaky”
🌈 Solution
After trying a lot of options, I came across the Playwright’s flag that overrides the Playwright’s default Behaviors with Downloading and Launching browsers. I tried and worked really well.
Our CI stabilized, finally! 🎯
“🎯 Download the Playwright version-specific Browsers and supply in your CI. And, CI will always have the browsers to launch”
Let’s see how to achieve this ⬇
- Download version-specific Playwright Browsers
- Have Playwright launch browses from the downloaded location
- (optional) Ask Playwright not to Download browsers by default, improves the package installation speed
Step 1. Download version-specific Playwright Browsers
Override the Playwright’s Default behavior of “downloading browsers” through the Environment variable PLAYWRIGHT_BROWSERS_PATH.
The above step will download the browsers to location “/usr/lib/playwright”. Well, we dockerize the downloaded browsers for the CI and supply in our Jenkins.
Step 2. Have Playwright launch browses from the downloaded location
Set the Browses path through PLAYWRIGHT_BROWSERS_PATH while running your tests
The above step will launch Chromium from the path “/usr/lib/playwright”, and guess what — It always finds the browsers to launch
Step 3. (recommended) Ask Playwright not to Download browsers by default
I recommend skipping the default Browser downloads since you already have them available. This improves the speed of the installation and CI.
Set the below environment variable before running
yarn install
to skip the default downloads,
Thanks for reading, I hope you discovered something new and useful. Stay curious, and happy coding!