Skip to content

Commit 95affe9

Browse files
authored
chore: do not delete unused browsers when PLAYWRIGHT_SKIP_BROWSER_GC is specified (#5827)
1 parent 226bee0 commit 95affe9

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

docs/src/installation.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,11 @@ Playwright downloads Chromium, Firefox and WebKit browsers by default. To instal
285285
$ pip install playwright
286286
$ playwright install firefox
287287
```
288+
289+
## Stale browser removal
290+
291+
Playwright keeps track of the clients that use its browsers. When there are no more clients that require particular
292+
version of the browser, that version is deleted from the system. That way you can safely use Playwright instances of
293+
different versions and at the same time, you don't waste disk space for the browsers that are no longer in use.
294+
295+
To opt-out from the unused browser removal, you can set the `PLAYWRIGHT_SKIP_BROWSER_GC=1` environment variable.

src/install/installer.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,16 @@ async function validateCache(linksDir: string, browserNames: BrowserName[]) {
9595
}
9696

9797
// 2. Delete all unused browsers.
98-
let downloadedBrowsers = (await fsReaddirAsync(registryDirectory)).map(file => path.join(registryDirectory, file));
99-
downloadedBrowsers = downloadedBrowsers.filter(file => isBrowserDirectory(file));
100-
const directories = new Set<string>(downloadedBrowsers);
101-
for (const browserDirectory of usedBrowserPaths)
102-
directories.delete(browserDirectory);
103-
for (const directory of directories) {
104-
browserFetcher.logPolitely('Removing unused browser at ' + directory);
105-
await removeFolderAsync(directory).catch(e => {});
98+
if (!getAsBooleanFromENV('PLAYWRIGHT_SKIP_BROWSER_GC')) {
99+
let downloadedBrowsers = (await fsReaddirAsync(registryDirectory)).map(file => path.join(registryDirectory, file));
100+
downloadedBrowsers = downloadedBrowsers.filter(file => isBrowserDirectory(file));
101+
const directories = new Set<string>(downloadedBrowsers);
102+
for (const browserDirectory of usedBrowserPaths)
103+
directories.delete(browserDirectory);
104+
for (const directory of directories) {
105+
browserFetcher.logPolitely('Removing unused browser at ' + directory);
106+
await removeFolderAsync(directory).catch(e => {});
107+
}
106108
}
107109

108110
// 3. Install missing browsers for this package.

0 commit comments

Comments
 (0)