diff --git a/docs/browsers-api/browsers.installedbrowser.md b/docs/browsers-api/browsers.installedbrowser.md
index 48ad1a90fab..b8879c5a95b 100644
--- a/docs/browsers-api/browsers.installedbrowser.md
+++ b/docs/browsers-api/browsers.installedbrowser.md
@@ -23,3 +23,10 @@ The constructor for this class is marked as internal. Third-party code should no
| executablePath | readonly
| string | |
| path | readonly
| string | Path to the root of the installation folder. Use [computeExecutablePath()](./browsers.computeexecutablepath.md) to get the path to the executable binary. |
| platform | | [BrowserPlatform](./browsers.browserplatform.md) | |
+
+## Methods
+
+| Method | Modifiers | Description |
+| ----------------------------------------------------------------------- | --------- | ----------- |
+| [readMetadata()](./browsers.installedbrowser.readmetadata.md) | | |
+| [writeMetadata(metadata)](./browsers.installedbrowser.writemetadata.md) | | |
diff --git a/docs/browsers-api/browsers.installedbrowser.readmetadata.md b/docs/browsers-api/browsers.installedbrowser.readmetadata.md
new file mode 100644
index 00000000000..aa1e4d8248c
--- /dev/null
+++ b/docs/browsers-api/browsers.installedbrowser.readmetadata.md
@@ -0,0 +1,17 @@
+---
+sidebar_label: InstalledBrowser.readMetadata
+---
+
+# InstalledBrowser.readMetadata() method
+
+#### Signature:
+
+```typescript
+class InstalledBrowser {
+ readMetadata(): Metadata;
+}
+```
+
+**Returns:**
+
+Metadata
diff --git a/docs/browsers-api/browsers.installedbrowser.writemetadata.md b/docs/browsers-api/browsers.installedbrowser.writemetadata.md
new file mode 100644
index 00000000000..4c0ae5d0c88
--- /dev/null
+++ b/docs/browsers-api/browsers.installedbrowser.writemetadata.md
@@ -0,0 +1,23 @@
+---
+sidebar_label: InstalledBrowser.writeMetadata
+---
+
+# InstalledBrowser.writeMetadata() method
+
+#### Signature:
+
+```typescript
+class InstalledBrowser {
+ writeMetadata(metadata: Metadata): void;
+}
+```
+
+## Parameters
+
+| Parameter | Type | Description |
+| --------- | -------- | ----------- |
+| metadata | Metadata | |
+
+**Returns:**
+
+void
diff --git a/docs/browsers-api/browsers.installoptions.md b/docs/browsers-api/browsers.installoptions.md
index 2e90d814db4..23278c6f09b 100644
--- a/docs/browsers-api/browsers.installoptions.md
+++ b/docs/browsers-api/browsers.installoptions.md
@@ -12,12 +12,13 @@ export interface InstallOptions
## Properties
-| Property | Modifiers | Type | Description | Default |
-| ------------------------ | --------------------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| baseUrl | optional
| string | Determines the host that will be used for downloading. |
Either
- https://storage.googleapis.com/chrome-for-testing-public or - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central
| -| browser | | [Browser](./browsers.browser.md) | Determines which browser to install. | | -| buildId | | string | Determines which buildId to download. BuildId should uniquely identify binaries and they are used for caching. | | -| cacheDir | | string | Determines the path to download browsers to. | | -| downloadProgressCallback |optional
| (downloadedBytes: number, totalBytes: number) => void | Provides information about the progress of the download. | |
-| platform | optional
| [BrowserPlatform](./browsers.browserplatform.md) | Determines which platform the browser will be suited for. | **Auto-detected.** |
-| unpack | optional
| boolean | Whether to unpack and install browser archives. | true
|
+| Property | Modifiers | Type | Description | Default |
+| ------------------------ | --------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| baseUrl | optional
| string | Determines the host that will be used for downloading. | Either
- https://storage.googleapis.com/chrome-for-testing-public or - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central
| +| browser | | [Browser](./browsers.browser.md) | Determines which browser to install. | | +| buildId | | string | Determines which buildId to download. BuildId should uniquely identify binaries and they are used for caching. | | +| buildIdAlias |optional
| string | An alias for the provided buildId
. It will be used to maintain local metadata to support aliases in the launch
command. | |
+| cacheDir | | string | Determines the path to download browsers to. | |
+| downloadProgressCallback | optional
| (downloadedBytes: number, totalBytes: number) => void | Provides information about the progress of the download. | |
+| platform | optional
| [BrowserPlatform](./browsers.browserplatform.md) | Determines which platform the browser will be suited for. | **Auto-detected.** |
+| unpack | optional
| boolean | Whether to unpack and install browser archives. | true
|
diff --git a/packages/browsers/src/CLI.ts b/packages/browsers/src/CLI.ts
index 255f5545b48..063540d97ce 100644
--- a/packages/browsers/src/CLI.ts
+++ b/packages/browsers/src/CLI.ts
@@ -238,6 +238,7 @@ export class CLI {
}
args.browser.buildId = pinnedVersion;
}
+ const originalBuildId = args.browser.buildId;
args.browser.buildId = await resolveBuildId(
args.browser.name,
args.platform,
@@ -253,6 +254,10 @@ export class CLI {
args.browser.buildId
),
baseUrl: args.baseUrl,
+ buildIdAlias:
+ originalBuildId !== args.browser.buildId
+ ? originalBuildId
+ : undefined,
});
console.log(
`${args.browser.name}@${
diff --git a/packages/browsers/src/Cache.ts b/packages/browsers/src/Cache.ts
index 13b465835a6..e6b574d9ddd 100644
--- a/packages/browsers/src/Cache.ts
+++ b/packages/browsers/src/Cache.ts
@@ -8,13 +8,18 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
+import debug from 'debug';
+
import {
Browser,
type BrowserPlatform,
executablePathByBrowser,
+ getVersionComparator,
} from './browser-data/browser-data.js';
import {detectBrowserPlatform} from './detectPlatform.js';
+const debugCache = debug('puppeteer:browsers:cache');
+
/**
* @public
*/
@@ -57,6 +62,14 @@ export class InstalledBrowser {
this.buildId
);
}
+
+ readMetadata(): Metadata {
+ return this.#cache.readMetadata(this.browser);
+ }
+
+ writeMetadata(metadata: Metadata): void {
+ this.#cache.writeMetadata(this.browser, metadata);
+ }
}
/**
@@ -80,6 +93,11 @@ export interface ComputeExecutablePathOptions {
buildId: string;
}
+export interface Metadata {
+ // Maps an alias (canary/latest/dev/etc.) to a buildId.
+ aliases: Record