From 95affe93876d5dee275c667bdd43612dd24fcb24 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Tue, 16 Mar 2021 07:00:18 +0800 Subject: [PATCH] chore: do not delete unused browsers when PLAYWRIGHT_SKIP_BROWSER_GC is specified (#5827) --- docs/src/installation.md | 8 ++++++++ src/install/installer.ts | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/src/installation.md b/docs/src/installation.md index c438ccb97aa00..8724b6387637c 100644 --- a/docs/src/installation.md +++ b/docs/src/installation.md @@ -285,3 +285,11 @@ Playwright downloads Chromium, Firefox and WebKit browsers by default. To instal $ pip install playwright $ playwright install firefox ``` + +## Stale browser removal + +Playwright keeps track of the clients that use its browsers. When there are no more clients that require particular +version of the browser, that version is deleted from the system. That way you can safely use Playwright instances of +different versions and at the same time, you don't waste disk space for the browsers that are no longer in use. + +To opt-out from the unused browser removal, you can set the `PLAYWRIGHT_SKIP_BROWSER_GC=1` environment variable. diff --git a/src/install/installer.ts b/src/install/installer.ts index 1f3b5bc92419d..a0a86e414ea43 100644 --- a/src/install/installer.ts +++ b/src/install/installer.ts @@ -95,14 +95,16 @@ async function validateCache(linksDir: string, browserNames: BrowserName[]) { } // 2. Delete all unused browsers. - let downloadedBrowsers = (await fsReaddirAsync(registryDirectory)).map(file => path.join(registryDirectory, file)); - downloadedBrowsers = downloadedBrowsers.filter(file => isBrowserDirectory(file)); - const directories = new Set(downloadedBrowsers); - for (const browserDirectory of usedBrowserPaths) - directories.delete(browserDirectory); - for (const directory of directories) { - browserFetcher.logPolitely('Removing unused browser at ' + directory); - await removeFolderAsync(directory).catch(e => {}); + if (!getAsBooleanFromENV('PLAYWRIGHT_SKIP_BROWSER_GC')) { + let downloadedBrowsers = (await fsReaddirAsync(registryDirectory)).map(file => path.join(registryDirectory, file)); + downloadedBrowsers = downloadedBrowsers.filter(file => isBrowserDirectory(file)); + const directories = new Set(downloadedBrowsers); + for (const browserDirectory of usedBrowserPaths) + directories.delete(browserDirectory); + for (const directory of directories) { + browserFetcher.logPolitely('Removing unused browser at ' + directory); + await removeFolderAsync(directory).catch(e => {}); + } } // 3. Install missing browsers for this package.