chore: do not delete unused browsers when PLAYWRIGHT_SKIP_BROWSER_GC is specified (#5827)
This commit is contained in:
parent
226bee01f0
commit
95affe9387
|
|
@ -285,3 +285,11 @@ Playwright downloads Chromium, Firefox and WebKit browsers by default. To instal
|
||||||
$ pip install playwright
|
$ pip install playwright
|
||||||
$ playwright install firefox
|
$ 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.
|
||||||
|
|
|
||||||
|
|
@ -95,14 +95,16 @@ async function validateCache(linksDir: string, browserNames: BrowserName[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Delete all unused browsers.
|
// 2. Delete all unused browsers.
|
||||||
let downloadedBrowsers = (await fsReaddirAsync(registryDirectory)).map(file => path.join(registryDirectory, file));
|
if (!getAsBooleanFromENV('PLAYWRIGHT_SKIP_BROWSER_GC')) {
|
||||||
downloadedBrowsers = downloadedBrowsers.filter(file => isBrowserDirectory(file));
|
let downloadedBrowsers = (await fsReaddirAsync(registryDirectory)).map(file => path.join(registryDirectory, file));
|
||||||
const directories = new Set<string>(downloadedBrowsers);
|
downloadedBrowsers = downloadedBrowsers.filter(file => isBrowserDirectory(file));
|
||||||
for (const browserDirectory of usedBrowserPaths)
|
const directories = new Set<string>(downloadedBrowsers);
|
||||||
directories.delete(browserDirectory);
|
for (const browserDirectory of usedBrowserPaths)
|
||||||
for (const directory of directories) {
|
directories.delete(browserDirectory);
|
||||||
browserFetcher.logPolitely('Removing unused browser at ' + directory);
|
for (const directory of directories) {
|
||||||
await removeFolderAsync(directory).catch(e => {});
|
browserFetcher.logPolitely('Removing unused browser at ' + directory);
|
||||||
|
await removeFolderAsync(directory).catch(e => {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Install missing browsers for this package.
|
// 3. Install missing browsers for this package.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue