Implementation:Puppeteer Puppeteer Cache Class
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Browser_Management, Cache_Management |
| Last Updated | 2026-02-11 23:00 GMT |
Overview
Concrete tool for managing the browser binary cache directory, provided by the @puppeteer/browsers package.
Description
The Cache class manages the filesystem cache of downloaded browser binaries. It provides methods to list installed browsers, compute executable paths, and manage cache metadata. The uninstall() function (separate from Cache) removes specific browser versions from the cache.
Usage
Create a Cache instance with the cache root directory, then use its methods to query and manage installed browsers.
Code Reference
Source Location
- Repository: puppeteer
- Cache class: packages/browsers/src/Cache.ts (lines 120-306)
- getInstalledBrowsers: lines 238-267
- computeExecutablePath: lines 269-305
- uninstall: packages/browsers/src/install.ts (lines 534-547)
Signature
class Cache {
constructor(rootDir: string);
getInstalledBrowsers(): InstalledBrowser[];
computeExecutablePath(options: {
browser: Browser;
buildId: string;
platform?: BrowserPlatform;
}): string;
}
async function uninstall(options: UninstallOptions): Promise<void>;
Import
import {Cache, uninstall} from '@puppeteer/browsers';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| rootDir | string | Yes (constructor) | Cache root directory path |
| options.browser | Browser | Yes (computeExecutablePath) | Browser type |
| options.buildId | string | Yes (computeExecutablePath) | Build identifier |
| options.platform | BrowserPlatform | No | Platform (auto-detected if omitted) |
Outputs
| Name | Type | Description |
|---|---|---|
| getInstalledBrowsers() | InstalledBrowser[] | Array of installed browser metadata objects |
| computeExecutablePath() | string | Absolute path to the browser executable |
| uninstall() | Promise<void> | Removes browser from cache |
Usage Examples
import {Cache, uninstall, Browser} from '@puppeteer/browsers';
const cache = new Cache('/home/user/.cache/puppeteer');
// List installed browsers
const installed = cache.getInstalledBrowsers();
for (const browser of installed) {
console.log(`${browser.browser} ${browser.buildId} at ${browser.executablePath}`);
}
// Get executable path
const chromePath = cache.computeExecutablePath({
browser: Browser.CHROME,
buildId: '131.0.6778.33',
});
// Uninstall a specific version
await uninstall({
cacheDir: '/home/user/.cache/puppeteer',
browser: Browser.CHROME,
buildId: '130.0.6723.58',
});
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment