Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: fallback to Google mirror (#38573)

Simon Knott3b5fe8705d1d
diff --git a/packages/playwright-core/src/server/registry/index.ts b/packages/playwright-core/src/server/registry/index.ts
index 1c4777a19b..2bd817776a 100644
--- a/packages/playwright-core/src/server/registry/index.ts
+++ b/packages/playwright-core/src/server/registry/index.ts
@@ -125,69 +125,82 @@ const EXECUTABLE_PATHS = {
},
};
-type DownloadPaths = Record<HostPlatform, string | undefined>;
+type DownloadPathFunction = (params: BrowsersJSONDescriptor) => { path: string, mirrors: string[] };
+
+function cftUrl(suffix: string): DownloadPathFunction {
+ return ({ browserVersion }) => {
+ return {
+ path: `${browserVersion}/${suffix}`,
+ mirrors: [
+ 'https://cdn.playwright.dev/chrome-for-testing-public',
+ ],
+ };
+ };
+}
+
+type DownloadPaths = Record<HostPlatform, string | DownloadPathFunction | undefined>;
const DOWNLOAD_PATHS: Record<BrowserName | InternalTool, DownloadPaths> = {
'chromium': {
'<unknown>': undefined,
'ubuntu18.04-x64': undefined,
- 'ubuntu20.04-x64': 'builds/chromium/%s/chromium-linux.zip',
- 'ubuntu22.04-x64': 'builds/chromium/%s/chromium-linux.zip',
- 'ubuntu24.04-x64': 'builds/chromium/%s/chromium-linux.zip',
+ 'ubuntu20.04-x64': cftUrl('linux64/chrome-linux64.zip'),
+ 'ubuntu22.04-x64': cftUrl('linux64/chrome-linux64.zip'),
+ 'ubuntu24.04-x64': cftUrl('linux64/chrome-linux64.zip'),
'ubuntu18.04-arm64': undefined,
'ubuntu20.04-arm64': 'builds/chromium/%s/chromium-linux-arm64.zip',
'ubuntu22.04-arm64': 'builds/chromium/%s/chromium-linux-arm64.zip',
'ubuntu24.04-arm64': 'builds/chromium/%s/chromium-linux-arm64.zip',
- 'debian11-x64': 'builds/chromium/%s/chromium-linux.zip',
+ 'debian11-x64': cftUrl('linux64/chrome-linux64.zip'),
'debian11-arm64': 'builds/chromium/%s/chromium-linux-arm64.zip',
- 'debian12-x64': 'builds/chromium/%s/chromium-linux.zip',
+ 'debian12-x64': cftUrl('linux64/chrome-linux64.zip'),
'debian12-arm64': 'builds/chromium/%s/chromium-linux-arm64.zip',
- 'debian13-x64': 'builds/chromium/%s/chromium-linux.zip',
+ 'debian13-x64': cftUrl('linux64/chrome-linux64.zip'),
'debian13-arm64': 'builds/chromium/%s/chromium-linux-arm64.zip',
- 'mac10.13': 'builds/chromium/%s/chromium-mac.zip',
- 'mac10.14': 'builds/chromium/%s/chromium-mac.zip',
- 'mac10.15': 'builds/chromium/%s/chromium-mac.zip',
- 'mac11': 'builds/chromium/%s/chromium-mac.zip',
- 'mac11-arm64': 'builds/chromium/%s/chromium-mac-arm64.zip',
- 'mac12': 'builds/chromium/%s/chromium-mac.zip',
- 'mac12-arm64': 'builds/chromium/%s/chromium-mac-arm64.zip',
- 'mac13': 'builds/chromium/%s/chromium-mac.zip',
- 'mac13-arm64': 'builds/chromium/%s/chromium-mac-arm64.zip',
- 'mac14': 'builds/chromium/%s/chromium-mac.zip',
- 'mac14-arm64': 'builds/chromium/%s/chromium-mac-arm64.zip',
- 'mac15': 'builds/chromium/%s/chromium-mac.zip',
- 'mac15-arm64': 'builds/chromium/%s/chromium-mac-arm64.zip',
- 'win64': 'builds/chromium/%s/chromium-win64.zip',
+ 'mac10.13': cftUrl('mac-x64/chrome-mac-x64.zip'),
+ 'mac10.14': cftUrl('mac-x64/chrome-mac-x64.zip'),
+ 'mac10.15': cftUrl('mac-x64/chrome-mac-x64.zip'),
+ 'mac11': cftUrl('mac-x64/chrome-mac-x64.zip'),
+ 'mac11-arm64': cftUrl('mac-arm64/chrome-mac-arm64.zip'),
+ 'mac12': cftUrl('mac-x64/chrome-mac-x64.zip'),
+ 'mac12-arm64': cftUrl('mac-arm64/chrome-mac-arm64.zip'),
+ 'mac13': cftUrl('mac-x64/chrome-mac-x64.zip'),
+ 'mac13-arm64': cftUrl('mac-arm64/chrome-mac-arm64.zip'),
+ 'mac14': cftUrl('mac-x64/chrome-mac-x64.zip'),
+ 'mac14-arm64': cftUrl('mac-arm64/chrome-mac-arm64.zip'),
+ 'mac15': cftUrl('mac-x64/chrome-mac-x64.zip'),
+ 'mac15-arm64': cftUrl('mac-arm64/chrome-mac-arm64.zip'),
+ 'win64': cftUrl('win64/chrome-win64.zip'),
},
'chromium-headless-shell': {
'<unknown>': undefined,
'ubuntu18.04-x64': undefined,
- 'ubuntu20.04-x64': 'builds/chromium/%s/chromium-headless-shell-linux.zip',
- 'ubuntu22.04-x64': 'builds/chromium/%s/chromium-headless-shell-linux.zip',
- 'ubuntu24.04-x64': 'builds/chromium/%s/chromium-headless-shell-linux.zip',
+ 'ubuntu20.04-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
+ 'ubuntu22.04-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
+ 'ubuntu24.04-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
'ubuntu18.04-arm64': undefined,
'ubuntu20.04-arm64': 'builds/chromium/%s/chromium-headless-shell-linux-arm64.zip',
'ubuntu22.04-arm64': 'builds/chromium/%s/chromium-headless-shell-linux-arm64.zip',
'ubuntu24.04-arm64': 'builds/chromium/%s/chromium-headless-shell-linux-arm64.zip',
- 'debian11-x64': 'builds/chromium/%s/chromium-headless-shell-linux.zip',
+ 'debian11-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
'debian11-arm64': 'builds/chromium/%s/chromium-headless-shell-linux-arm64.zip',
- 'debian12-x64': 'builds/chromium/%s/chromium-headless-shell-linux.zip',
+ 'debian12-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
'debian12-arm64': 'builds/chromium/%s/chromium-headless-shell-linux-arm64.zip',
- 'debian13-x64': 'builds/chromium/%s/chromium-headless-shell-linux.zip',
+ 'debian13-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
'debian13-arm64': 'builds/chromium/%s/chromium-headless-shell-linux-arm64.zip',
'mac10.13': undefined,
'mac10.14': undefined,
'mac10.15': undefined,
- 'mac11': 'builds/chromium/%s/chromium-headless-shell-mac.zip',
- 'mac11-arm64': 'builds/chromium/%s/chromium-headless-shell-mac-arm64.zip',
- 'mac12': 'builds/chromium/%s/chromium-headless-shell-mac.zip',
- 'mac12-arm64': 'builds/chromium/%s/chromium-headless-shell-mac-arm64.zip',
- 'mac13': 'builds/chromium/%s/chromium-headless-shell-mac.zip',
- 'mac13-arm64': 'builds/chromium/%s/chromium-headless-shell-mac-arm64.zip',
- 'mac14': 'builds/chromium/%s/chromium-headless-shell-mac.zip',
- 'mac14-arm64': 'builds/chromium/%s/chromium-headless-shell-mac-arm64.zip',
- 'mac15': 'builds/chromium/%s/chromium-headless-shell-mac.zip',
- 'mac15-arm64': 'builds/chromium/%s/chromium-headless-shell-mac-arm64.zip',
- 'win64': 'builds/chromium/%s/chromium-headless-shell-win64.zip',
+ 'mac11': cftUrl('mac-x64/chrome-headless-shell-mac-x64.zip'),
+ 'mac11-arm64': cftUrl('mac-arm64/chrome-headless-shell-mac-arm64.zip'),
+ 'mac12': cftUrl('mac-x64/chrome-headless-shell-mac-x64.zip'),
+ 'mac12-arm64': cftUrl('mac-arm64/chrome-headless-shell-mac-arm64.zip'),
+ 'mac13': cftUrl('mac-x64/chrome-headless-shell-mac-x64.zip'),
+ 'mac13-arm64': cftUrl('mac-arm64/chrome-headless-shell-mac-arm64.zip'),
+ 'mac14': cftUrl('mac-x64/chrome-headless-shell-mac-x64.zip'),
+ 'mac14-arm64': cftUrl('mac-arm64/chrome-headless-shell-mac-arm64.zip'),
+ 'mac15': cftUrl('mac-x64/chrome-headless-shell-mac-x64.zip'),
+ 'mac15-arm64': cftUrl('mac-arm64/chrome-headless-shell-mac-arm64.zip'),
+ 'win64': cftUrl('win64/chrome-headless-shell-win64.zip'),
},
'chromium-tip-of-tree': {
'<unknown>': undefined,
@@ -1216,12 +1229,20 @@ export class Registry {
private _downloadURLs(descriptor: BrowsersJSONDescriptor): string[] {
const paths = (DOWNLOAD_PATHS as any)[descriptor.name];
- const downloadPathTemplate: string|undefined = paths[hostPlatform] || paths['<unknown>'];
+ const downloadPathTemplate: string|DownloadPathFunction|undefined = paths[hostPlatform] || paths['<unknown>'];
if (!downloadPathTemplate)
return [];
- const downloadPath = util.format(downloadPathTemplate, descriptor.revision);
+ let downloadPath: string;
+ let mirrors: string[];
+ if (typeof downloadPathTemplate === 'function') {
+ const result = downloadPathTemplate(descriptor);
+ downloadPath = result.path;
+ mirrors = result.mirrors;
+ } else {
+ downloadPath = util.format(downloadPathTemplate, descriptor.revision);
+ mirrors = PLAYWRIGHT_CDN_MIRRORS;
+ }
- let downloadURLs = PLAYWRIGHT_CDN_MIRRORS.map(mirror => `${mirror}/${downloadPath}`) ;
let downloadHostEnv;
if (descriptor.name.startsWith('chromium'))
downloadHostEnv = 'PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST';
@@ -1232,8 +1253,9 @@ export class Registry {
const customHostOverride = (downloadHostEnv && getFromENV(downloadHostEnv)) || getFromENV('PLAYWRIGHT_DOWNLOAD_HOST');
if (customHostOverride)
- downloadURLs = [`${customHostOverride}/${downloadPath}`];
- return downloadURLs;
+ mirrors = [customHostOverride];
+
+ return mirrors.map(mirror => `${mirror}/${downloadPath}`);
}
private async _downloadExecutable(descriptor: BrowsersJSONDescriptor, executablePath?: string) {
diff --git a/tests/installation/playwright-cdn.spec.ts b/tests/installation/playwright-cdn.spec.ts
index ac03a4b92e..c7a9321711 100644
--- a/tests/installation/playwright-cdn.spec.ts
+++ b/tests/installation/playwright-cdn.spec.ts
@@ -46,7 +46,7 @@ for (const cdn of CDNS) {
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit', ...extraInstalledSoftware]);
await checkInstalledSoftwareOnDisk((['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit', ...extraInstalledSoftware]));
const dls = parsedDownloads(result);
- for (const software of ['chromium', 'ffmpeg', 'firefox', 'webkit'])
+ for (const software of ['ffmpeg', 'firefox', 'webkit'])
expect(dls).toContainEqual({ status: 200, name: software, url: expect.stringContaining(cdn) });
await exec('node sanity.js playwright chromium firefox webkit');
await exec('node esm-playwright.mjs');
diff --git a/tests/installation/playwright-cli-install-should-work.spec.ts b/tests/installation/playwright-cli-install-should-work.spec.ts
index 2667564b93..48f7dabc78 100755
--- a/tests/installation/playwright-cli-install-should-work.spec.ts
+++ b/tests/installation/playwright-cli-install-should-work.spec.ts
@@ -85,7 +85,11 @@ test('install command should work with mirror that uses chunked encoding', async
await exec('npm i playwright');
const server = http.createServer(async (req, res) => {
try {
- const upstream = await fetch('https://cdn.playwright.dev/dbazure/download/playwright' + req.url);
+ const upstream = await fetch(
+ req.url.startsWith('/builds/')
+ ? 'https://cdn.playwright.dev/dbazure/download/playwright' + req.url
+ : 'https://cdn.playwright.dev/chrome-for-testing-public' + req.url
+ );
const headers = new Headers(upstream.headers);
headers.delete('content-length');
res.writeHead(upstream.status, Object.fromEntries(headers));