diff --git a/docs/api.md b/docs/api.md index 54a4305028..cb9e0905b0 100644 --- a/docs/api.md +++ b/docs/api.md @@ -4148,6 +4148,7 @@ If Playwright doesn't find them in the environment, a lowercased variant of thes - `PLAYWRIGHT_DOWNLOAD_HOST` - overwrite URL prefix that is used to download browsers. Note: this includes protocol and might even include path prefix. By default, Playwright uses `https://storage.googleapis.com` to download Chromium and `https://playwright.azureedge.net` to download Webkit & Firefox. - `PLAYWRIGHT_BROWSERS_PATH` - specify a shared folder that playwright will use to download browsers and to look for browsers when launching browser instances. +- `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` - set to non-empty value to skip browser downloads altogether. ```sh # Install browsers to the shared location. diff --git a/download-browser.js b/download-browser.js index 53eabe29b3..468ca71bc3 100644 --- a/download-browser.js +++ b/download-browser.js @@ -37,6 +37,7 @@ function downloadOptionsFromENV(packagePath, browserName) { path.join(packagePath, '.local-browsers', browserName); return { downloadPath, + skipBrowserDownload: getFromENV('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD'), progressBarBrowserName: `${browserName} for playwright v${packageJSON.version}`, revision: packageJSON.playwright[`${browserName}_revision`], browser: browserName, @@ -46,6 +47,10 @@ function downloadOptionsFromENV(packagePath, browserName) { } async function downloadBrowserWithProgressBar(options) { + if (options.skipBrowserDownload) { + logPolitely('Skipping browsers download because `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` env variable is set'); + return; + } let progressBar = null; let lastDownloadedBytes = 0; function progress(downloadedBytes, totalBytes) { diff --git a/test/installation-tests/installation-tests.sh b/test/installation-tests/installation-tests.sh index 2c31377fac..9a7ef6904b 100755 --- a/test/installation-tests/installation-tests.sh +++ b/test/installation-tests/installation-tests.sh @@ -30,6 +30,7 @@ SANITY_JS="$(pwd -P)/../sanity.js" TEST_ROOT="$(pwd -P)" function run_tests { + test_skip_browser_download test_playwright_global_installation_subsequent_installs test_playwright_should_work test_playwright_chromium_should_work @@ -74,6 +75,22 @@ function test_playwright_global_installation_subsequent_installs { PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node --unhandled-rejections=strict node_modules/playwright/install.js } +function test_skip_browser_download { + initialize_test "${FUNCNAME[0]}" + + npm install ${PLAYWRIGHT_CORE_TGZ} + OUTPUT=$(PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_TGZ}) + if [[ "${OUTPUT}" != *"Skipping browsers download because"* ]]; then + echo "missing log message that browsers download is skipped" + exit 1 + fi + + if [[ -d ./node_modules/playwright/.local-browsers ]]; then + echo "local browsers folder should be empty" + exit 1 + fi +} + function test_playwright_should_work { initialize_test "${FUNCNAME[0]}"