Playwright Install Browsers

Playwright Install Browsers

Browsers are essential for playwright testing. Each version of the playwright needs specific browser versions to operate. Depending on the language, the playwright will either download these browsers at package install time without a problem, or playwright CLI is needed to install these browsers.

With every playwright release, it will operate at best with the latest browser version, which means every time we update the playwright, we might need to re-run the install command.

Chromium:

  • For chromium-based browsers, playwright, by default, uses open source chromium builds.
  • When the world was using the chrome version, N playwright was always one step ahead and was using the N+1 release for both chrome and edge.

Firefox:

  • Playwright matches with the current firefox stable build.

Webkit:

  • It matched the recent WebKit trunk build before using apple safari and other WebKit-based browsers.

Opt To Stock:

The playwright can download and see the recent chromium build, but if we want a more stock-like an experience like chrome, we can opt for it.

const config = {
  use: {
    channel: 'chrome',
  },
};

module.exports = config;

Installing Browsers:

  • Playwright downloads chromium, firefox, and WebKit browsers into OS-specific cache folders.

%USERPROFILE%\AppData\Local\ms-playwright on Windows
~/Library/Caches/ms-playwright on MacOS
~/.cache/ms-playwright on Linux

  • Each browser will take up to 100MB of disk space when installed.
  • Using the environment variable, we can change the path for installing browsers to the default behavior.

Using Powershell:

$env:PLAYWRIGHT_BROWSERS_PATH="$env:USERPROFILE\pw-browsers"
npx playwright install

Install Behind Firewall Or Proxy:

  • Playwright sometimes downloads browsers from Microsoft CDN.
  • There can be complaints that the internal proxy blocks direct access to public resources.
  • Playwright, at this time, can be tweaked to download browsers via proxy server.
# For Playwright Test
$env:HTTPS_PROXY="https://192.0.2.1"
npx playwright install

# For Playwright Library
$env:HTTPS_PROXY="https://192.0.2.1"
npm install playwright

Install From Artifact Repository:

  • The playwright can also be tweaked to download from a custom location using the PLAYWRIGHT_DOWNLOAD_HOST env variable.
# For Playwright Test
$env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1"
npx playwright install

# For Playwright Library
$env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1"
npm install playwright

We can also use per download hosts using:

  1. PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST
  2. PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST 
  3. PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST 
Tags
Standard (Image)