From 81a2a00382819697fc234829f6d0afedc22fee92 Mon Sep 17 00:00:00 2001 From: "microsoft-playwright-automation[bot]" <203992400+microsoft-playwright-automation[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 17:52:56 +0000 Subject: [PATCH 1/3] fix(docker): use latest stable Chrome for Testing and Node.js LTS Fixes: https://github.com/microsoft/playwright/issues/43664 --- docs/src/docker.md | 2 + tests/installation/docker.spec.ts | 74 ++++++++++++++++++++++++++ utils/build/update-playwright-node.mjs | 5 +- utils/docker/Dockerfile.jammy | 10 ++-- utils/docker/Dockerfile.noble | 10 ++-- utils/docker/Dockerfile.resolute | 10 ++-- utils/docker/build.sh | 8 ++- utils/docker/configure-browsers.mjs | 32 +++++++++++ utils/docker/latest-versions.mjs | 33 ++++++++++++ 9 files changed, 171 insertions(+), 13 deletions(-) create mode 100644 tests/installation/docker.spec.ts create mode 100644 utils/docker/configure-browsers.mjs create mode 100644 utils/docker/latest-versions.mjs diff --git a/docs/src/docker.md b/docs/src/docker.md index 608d074ecf37d..efa517597a9e8 100644 --- a/docs/src/docker.md +++ b/docs/src/docker.md @@ -7,6 +7,8 @@ title: "Docker" [Dockerfile.noble] can be used to run Playwright scripts in Docker environment. This image includes the [Playwright browsers](./browsers.md#install-browsers) and [browser system dependencies](./browsers.md#install-system-dependencies). The Playwright package/dependency is not included in the image and should be installed separately. +For Node.js images, each build selects the latest stable Chrome for Testing (including Chrome Headless Shell) and the latest Node.js LTS release. Firefox and WebKit remain at the versions bundled with the matching Playwright release. Published images do not update automatically. + ## Usage This Docker image is published to [Microsoft Artifact Registry]. diff --git a/tests/installation/docker.spec.ts b/tests/installation/docker.spec.ts new file mode 100644 index 0000000000000..a6aa56a69f5f4 --- /dev/null +++ b/tests/installation/docker.spec.ts @@ -0,0 +1,74 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import fs from 'fs'; +import path from 'path'; +import { pathToFileURL } from 'url'; +import { test, expect } from './npmTest'; + +test('Docker builds select stable Chrome for Testing and Node.js LTS', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43664' } }, async ({ exec, writeFiles, tmpWorkspace }) => { + test.skip(process.platform === 'win32', 'Docker images are built with bash'); + const dockerDir = path.resolve(__dirname, '../../utils/docker'); + await writeFiles({ + 'bin/docker': '#!/bin/sh\nprintf "%s\\n" "$@"\n', + 'fetch.mjs': ` + globalThis.fetch = async url => { + if (url === 'https://nodejs.org/dist/index.json') + return new Response(JSON.stringify([{ version: 'v25.0.0', lts: false }, { version: 'v24.9.0', lts: 'Krypton' }])); + if (url === 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json') + return new Response(JSON.stringify({ channels: { Stable: { version: '143.0.7499.4' }, Beta: { version: '144.0.7500.1' } } })); + throw new Error('Unexpected URL: ' + url); + }; + `, + }); + await fs.promises.chmod(path.join(tmpWorkspace, 'bin/docker'), 0o755); + const output = await exec(`bash "${path.join(dockerDir, 'build.sh')}" --amd64 noble playwright:test`, { + env: { + PATH: path.join(tmpWorkspace, 'bin') + path.delimiter + process.env.PATH, + NODE_OPTIONS: `--import=${pathToFileURL(path.join(tmpWorkspace, 'fetch.mjs'))}`, + }, + }); + expect(output).toContain('NODE_VERSION=24.9.0'); + expect(output).toContain('CHROMIUM_VERSION=143.0.7499.4'); + expect(output).toContain('--pull'); + + await exec('npm i playwright-core'); + const browsersFile = path.join(tmpWorkspace, 'node_modules/playwright-core/browsers.json'); + const original: { browsers: { name: string, revision: string, browserVersion?: string }[] } = JSON.parse(await fs.promises.readFile(browsersFile, 'utf8')); + await exec(`node "${path.join(dockerDir, 'configure-browsers.mjs')}" 143.0.7499.4`); + const configured = JSON.parse(await fs.promises.readFile(browsersFile, 'utf8')); + expect(configured).toEqual({ + ...original, + browsers: original.browsers.map(browser => ['chromium', 'chromium-headless-shell'].includes(browser.name) ? { ...browser, browserVersion: '143.0.7499.4' } : browser), + }); + const downloads = await exec('npx playwright-core install chromium --dry-run'); + expect(downloads).toContain('/builds/cft/143.0.7499.4/'); + for (const name of ['chromium', 'chromium-headless-shell']) { + const descriptor = original.browsers.find(browser => browser.name === name); + expect(downloads).toContain(`${name.replace(/-/g, '_')}-${descriptor.revision}`); + } + + await writeFiles({ 'fetch-error.mjs': 'globalThis.fetch = async () => new Response("", { status: 503 });' }); + const failure = await exec(`bash "${path.join(dockerDir, 'build.sh')}" --amd64 noble playwright:test`, { + env: { + PATH: path.join(tmpWorkspace, 'bin') + path.delimiter + process.env.PATH, + NODE_OPTIONS: `--import=${pathToFileURL(path.join(tmpWorkspace, 'fetch-error.mjs'))}`, + }, + expectToExitWithError: true, + }); + expect(failure).toContain('Failed to fetch'); + expect(failure).toContain('503'); +}); diff --git a/utils/build/update-playwright-node.mjs b/utils/build/update-playwright-node.mjs index f56dd38102a91..728ae49fbd49f 100644 --- a/utils/build/update-playwright-node.mjs +++ b/utils/build/update-playwright-node.mjs @@ -25,9 +25,8 @@ const dockerfilePaths = await getDockerfilePaths(dockerDirectory); const latestNodeJsLts = await getLatestNodeJsVersion(); for (const dockerfilePath of dockerfilePaths) { - const nodeMajorVersion = latestNodeJsLts.split('.')[0]; - if (refreshDockerfileVersionNumber(nodeMajorVersion, dockerfilePath)) - console.log(`Updated Dockerfile ${path.relative(process.cwd(), dockerfilePath)} to Node.js ${nodeMajorVersion}.x`); + if (refreshDockerfileVersionNumber(latestNodeJsLts, dockerfilePath)) + console.log(`Updated Dockerfile ${path.relative(process.cwd(), dockerfilePath)} to Node.js ${latestNodeJsLts}`); } async function getDockerfilePaths(directory) { diff --git a/utils/docker/Dockerfile.jammy b/utils/docker/Dockerfile.jammy index d36b5f1177d90..ec2b57d167bf8 100644 --- a/utils/docker/Dockerfile.jammy +++ b/utils/docker/Dockerfile.jammy @@ -4,7 +4,7 @@ FROM ${ACR_CACHE_PREFIX}ubuntu:jammy ARG DEBIAN_FRONTEND=noninteractive ARG TZ=America/Los_Angeles ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright:v%version%-jammy" -ARG NODE_VERSION=24 # autogenerated via ./update-playwright-node.mjs +ARG NODE_VERSION=24.22.1 # autogenerated via ./update-playwright-node.mjs ARG UBUNTU_MIRROR_PREFIX ENV LANG=C.UTF-8 @@ -19,9 +19,9 @@ RUN --mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \ apt-get install -y curl wget gpg ca-certificates && \ mkdir -p /etc/apt/keyrings && \ curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ - echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION%%.*}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ apt-get update && \ - apt-get install -y nodejs && \ + apt-get install -y "nodejs=${NODE_VERSION}-1nodesource1" && \ # Feature-parity with node.js base images. # zstd is used by actions/cache. apt-get install -y --no-install-recommends git openssh-client zstd && \ @@ -39,12 +39,16 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright # 1. Add tip-of-tree Playwright package to install its browsers. # The package should be built beforehand from tip-of-tree Playwright. COPY ./playwright-core.tar.gz /tmp/playwright-core.tar.gz +COPY ./configure-browsers.mjs /tmp/configure-browsers.mjs +ARG CHROMIUM_VERSION # 2. Set up playwright-core and install all system dependencies in one layer. RUN install -d -m 777 /ms-playwright /ms-playwright/.links && \ mkdir /ms-playwright-agent && \ cd /ms-playwright-agent && npm init -y && \ npm i /tmp/playwright-core.tar.gz && \ + node /tmp/configure-browsers.mjs "${CHROMIUM_VERSION}" && \ + rm /tmp/configure-browsers.mjs && \ npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \ npm exec --no -- playwright-core install-deps && \ # Workaround for https://github.com/microsoft/playwright/issues/27313 diff --git a/utils/docker/Dockerfile.noble b/utils/docker/Dockerfile.noble index 627e6fd366f81..46d53ae33c99f 100644 --- a/utils/docker/Dockerfile.noble +++ b/utils/docker/Dockerfile.noble @@ -4,7 +4,7 @@ FROM ${ACR_CACHE_PREFIX}ubuntu:noble ARG DEBIAN_FRONTEND=noninteractive ARG TZ=America/Los_Angeles ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright:v%version%-noble" -ARG NODE_VERSION=24 # autogenerated via ./update-playwright-node.mjs +ARG NODE_VERSION=24.22.1 # autogenerated via ./update-playwright-node.mjs ARG UBUNTU_MIRROR_PREFIX ENV LANG=C.UTF-8 @@ -19,9 +19,9 @@ RUN --mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \ apt-get install -y curl wget gpg ca-certificates && \ mkdir -p /etc/apt/keyrings && \ curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ - echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION%%.*}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ apt-get update && \ - apt-get install -y nodejs && \ + apt-get install -y "nodejs=${NODE_VERSION}-1nodesource1" && \ # Feature-parity with node.js base images. # zstd is used by actions/cache. apt-get install -y --no-install-recommends git openssh-client zstd && \ @@ -39,12 +39,16 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright # 1. Add tip-of-tree Playwright package to install its browsers. # The package should be built beforehand from tip-of-tree Playwright. COPY ./playwright-core.tar.gz /tmp/playwright-core.tar.gz +COPY ./configure-browsers.mjs /tmp/configure-browsers.mjs +ARG CHROMIUM_VERSION # 2. Set up playwright-core and install all system dependencies in one layer. RUN install -d -m 777 /ms-playwright /ms-playwright/.links && \ mkdir /ms-playwright-agent && \ cd /ms-playwright-agent && npm init -y && \ npm i /tmp/playwright-core.tar.gz && \ + node /tmp/configure-browsers.mjs "${CHROMIUM_VERSION}" && \ + rm /tmp/configure-browsers.mjs && \ npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \ npm exec --no -- playwright-core install-deps && \ rm -rf /var/lib/apt/lists/* diff --git a/utils/docker/Dockerfile.resolute b/utils/docker/Dockerfile.resolute index 30d4880a20ebe..4ecb770a2d334 100644 --- a/utils/docker/Dockerfile.resolute +++ b/utils/docker/Dockerfile.resolute @@ -4,7 +4,7 @@ FROM ${ACR_CACHE_PREFIX}ubuntu:resolute ARG DEBIAN_FRONTEND=noninteractive ARG TZ=America/Los_Angeles ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright:v%version%-resolute" -ARG NODE_VERSION=24 # autogenerated via ./update-playwright-node.mjs +ARG NODE_VERSION=24.22.1 # autogenerated via ./update-playwright-node.mjs ARG UBUNTU_MIRROR_PREFIX ENV LANG=C.UTF-8 @@ -20,9 +20,9 @@ RUN --mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \ apt-get install -y curl wget gpg ca-certificates && \ mkdir -p /etc/apt/keyrings && \ curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ - echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION%%.*}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ apt-get update && \ - apt-get install -y nodejs && \ + apt-get install -y "nodejs=${NODE_VERSION}-1nodesource1" && \ # Feature-parity with node.js base images. # zstd is used by actions/cache. apt-get install -y --no-install-recommends git openssh-client zstd && \ @@ -40,12 +40,16 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright # 1. Add tip-of-tree Playwright package to install its browsers. # The package should be built beforehand from tip-of-tree Playwright. COPY ./playwright-core.tar.gz /tmp/playwright-core.tar.gz +COPY ./configure-browsers.mjs /tmp/configure-browsers.mjs +ARG CHROMIUM_VERSION # 2. Set up playwright-core and install all system dependencies in one layer. RUN install -d -m 777 /ms-playwright /ms-playwright/.links && \ mkdir /ms-playwright-agent && \ cd /ms-playwright-agent && npm init -y && \ npm i /tmp/playwright-core.tar.gz && \ + node /tmp/configure-browsers.mjs "${CHROMIUM_VERSION}" && \ + rm /tmp/configure-browsers.mjs && \ npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \ npm exec --no -- playwright-core install-deps && \ rm -rf /var/lib/apt/lists/* diff --git a/utils/docker/build.sh b/utils/docker/build.sh index e0c90bab9d5d1..669646792c5d3 100755 --- a/utils/docker/build.sh +++ b/utils/docker/build.sh @@ -42,6 +42,10 @@ if [[ -n "${NPMRC_SECRET:-}" ]]; then SECRET_ARGS+=(--secret "id=npmrc,src=${NPMRC_SECRET}") fi +VERSIONS=$(node ./latest-versions.mjs) +read -r NODE_VERSION CHROMIUM_VERSION <<< "$VERSIONS" +echo "Building with Node.js ${NODE_VERSION} and Chrome for Testing ${CHROMIUM_VERSION}" + # Keep each arch image a plain single-platform manifest without the unknown/unknown platform entry. export BUILDX_NO_DEFAULT_ATTESTATIONS=1 @@ -53,9 +57,11 @@ export BUILDX_NO_DEFAULT_ATTESTATIONS=1 MAX_ATTEMPTS=3 for ((attempt = 1; attempt <= MAX_ATTEMPTS; attempt++)); do - if docker build --platform "${PLATFORM}" \ + if docker build --pull --platform "${PLATFORM}" \ --build-arg ACR_CACHE_PREFIX="${ACR_CACHE_PREFIX}" \ --build-arg UBUNTU_MIRROR_PREFIX="${UBUNTU_MIRROR_PREFIX}" \ + --build-arg NODE_VERSION="${NODE_VERSION}" \ + --build-arg CHROMIUM_VERSION="${CHROMIUM_VERSION}" \ "${SECRET_ARGS[@]}" \ -t "$3" -f "Dockerfile.$2" .; then exit 0 diff --git a/utils/docker/configure-browsers.mjs b/utils/docker/configure-browsers.mjs new file mode 100644 index 0000000000000..d89a647410eb7 --- /dev/null +++ b/utils/docker/configure-browsers.mjs @@ -0,0 +1,32 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import fs from 'fs'; + +const version = process.argv[2]; +if (!/^\d+\.\d+\.\d+\.\d+$/.test(version)) + throw new Error('Expected a Chrome for Testing version'); + +const file = 'node_modules/playwright-core/browsers.json'; +const browsersJSON = JSON.parse(fs.readFileSync(file, 'utf8')); +for (const name of ['chromium', 'chromium-headless-shell']) { + const browser = browsersJSON.browsers.find(browser => browser.name === name); + if (!browser) + throw new Error(`Missing browser descriptor: ${name}`); + // Keep the revision so the matching Playwright package finds the stable browser. + browser.browserVersion = version; +} +fs.writeFileSync(file, JSON.stringify(browsersJSON, null, 2) + '\n'); diff --git a/utils/docker/latest-versions.mjs b/utils/docker/latest-versions.mjs new file mode 100644 index 0000000000000..26018df3026fb --- /dev/null +++ b/utils/docker/latest-versions.mjs @@ -0,0 +1,33 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +async function fetchJSON(url) { + const response = await fetch(url, { signal: AbortSignal.timeout(30_000) }); + if (!response.ok) + throw new Error(`Failed to fetch ${url}: ${response.status}`); + return response.json(); +} + +const [nodeReleases, chromeReleases] = await Promise.all([ + fetchJSON('https://nodejs.org/dist/index.json'), + fetchJSON('https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json'), +]); +const nodeVersion = nodeReleases.find(release => release.lts)?.version; +const chromiumVersion = chromeReleases.channels?.Stable?.version; +if (!/^v\d+\.\d+\.\d+$/.test(nodeVersion) || !/^\d+\.\d+\.\d+\.\d+$/.test(chromiumVersion)) + throw new Error('Release metadata must contain a Node.js LTS version and a stable Chrome for Testing version'); + +console.log(`${nodeVersion.slice(1)} ${chromiumVersion}`); From a61b45189a0aa451aa7ec718c33d78040106c210 Mon Sep 17 00:00:00 2001 From: "microsoft-playwright-automation[bot]" <203992400+microsoft-playwright-automation[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 15:38:32 +0000 Subject: [PATCH 2/3] fix(docker): limit latest-version selection to Chrome for Testing https://github.com/microsoft/playwright/pull/43679#pullrequestreview-5685251244: Undo every Node.js version change; print the selected Chrome for Testing version in build.sh, which publishing invokes directly. https://github.com/microsoft/playwright/pull/43679#discussion_r4402562400: Undo the Docker documentation addition. https://github.com/microsoft/playwright/pull/43679#discussion_r4402565263: Remove the Docker build test as requested. https://github.com/microsoft/playwright/pull/43679#discussion_r4402576320: Keep configure-browsers.mjs because roll_browser.js requires the source checkout and development dependencies, downloads browsers and regenerates protocols/docs; the image installs a packed release and must retain its revision paths and Firefox/WebKit versions. Fixes: https://github.com/microsoft/playwright/issues/43664 --- docs/src/docker.md | 2 - tests/installation/docker.spec.ts | 74 -------------------------- utils/build/update-playwright-node.mjs | 5 +- utils/docker/Dockerfile.jammy | 6 +-- utils/docker/Dockerfile.noble | 6 +-- utils/docker/Dockerfile.resolute | 6 +-- utils/docker/build.sh | 6 +-- utils/docker/latest-versions.mjs | 12 ++--- 8 files changed, 18 insertions(+), 99 deletions(-) delete mode 100644 tests/installation/docker.spec.ts diff --git a/docs/src/docker.md b/docs/src/docker.md index efa517597a9e8..608d074ecf37d 100644 --- a/docs/src/docker.md +++ b/docs/src/docker.md @@ -7,8 +7,6 @@ title: "Docker" [Dockerfile.noble] can be used to run Playwright scripts in Docker environment. This image includes the [Playwright browsers](./browsers.md#install-browsers) and [browser system dependencies](./browsers.md#install-system-dependencies). The Playwright package/dependency is not included in the image and should be installed separately. -For Node.js images, each build selects the latest stable Chrome for Testing (including Chrome Headless Shell) and the latest Node.js LTS release. Firefox and WebKit remain at the versions bundled with the matching Playwright release. Published images do not update automatically. - ## Usage This Docker image is published to [Microsoft Artifact Registry]. diff --git a/tests/installation/docker.spec.ts b/tests/installation/docker.spec.ts deleted file mode 100644 index a6aa56a69f5f4..0000000000000 --- a/tests/installation/docker.spec.ts +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import fs from 'fs'; -import path from 'path'; -import { pathToFileURL } from 'url'; -import { test, expect } from './npmTest'; - -test('Docker builds select stable Chrome for Testing and Node.js LTS', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43664' } }, async ({ exec, writeFiles, tmpWorkspace }) => { - test.skip(process.platform === 'win32', 'Docker images are built with bash'); - const dockerDir = path.resolve(__dirname, '../../utils/docker'); - await writeFiles({ - 'bin/docker': '#!/bin/sh\nprintf "%s\\n" "$@"\n', - 'fetch.mjs': ` - globalThis.fetch = async url => { - if (url === 'https://nodejs.org/dist/index.json') - return new Response(JSON.stringify([{ version: 'v25.0.0', lts: false }, { version: 'v24.9.0', lts: 'Krypton' }])); - if (url === 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json') - return new Response(JSON.stringify({ channels: { Stable: { version: '143.0.7499.4' }, Beta: { version: '144.0.7500.1' } } })); - throw new Error('Unexpected URL: ' + url); - }; - `, - }); - await fs.promises.chmod(path.join(tmpWorkspace, 'bin/docker'), 0o755); - const output = await exec(`bash "${path.join(dockerDir, 'build.sh')}" --amd64 noble playwright:test`, { - env: { - PATH: path.join(tmpWorkspace, 'bin') + path.delimiter + process.env.PATH, - NODE_OPTIONS: `--import=${pathToFileURL(path.join(tmpWorkspace, 'fetch.mjs'))}`, - }, - }); - expect(output).toContain('NODE_VERSION=24.9.0'); - expect(output).toContain('CHROMIUM_VERSION=143.0.7499.4'); - expect(output).toContain('--pull'); - - await exec('npm i playwright-core'); - const browsersFile = path.join(tmpWorkspace, 'node_modules/playwright-core/browsers.json'); - const original: { browsers: { name: string, revision: string, browserVersion?: string }[] } = JSON.parse(await fs.promises.readFile(browsersFile, 'utf8')); - await exec(`node "${path.join(dockerDir, 'configure-browsers.mjs')}" 143.0.7499.4`); - const configured = JSON.parse(await fs.promises.readFile(browsersFile, 'utf8')); - expect(configured).toEqual({ - ...original, - browsers: original.browsers.map(browser => ['chromium', 'chromium-headless-shell'].includes(browser.name) ? { ...browser, browserVersion: '143.0.7499.4' } : browser), - }); - const downloads = await exec('npx playwright-core install chromium --dry-run'); - expect(downloads).toContain('/builds/cft/143.0.7499.4/'); - for (const name of ['chromium', 'chromium-headless-shell']) { - const descriptor = original.browsers.find(browser => browser.name === name); - expect(downloads).toContain(`${name.replace(/-/g, '_')}-${descriptor.revision}`); - } - - await writeFiles({ 'fetch-error.mjs': 'globalThis.fetch = async () => new Response("", { status: 503 });' }); - const failure = await exec(`bash "${path.join(dockerDir, 'build.sh')}" --amd64 noble playwright:test`, { - env: { - PATH: path.join(tmpWorkspace, 'bin') + path.delimiter + process.env.PATH, - NODE_OPTIONS: `--import=${pathToFileURL(path.join(tmpWorkspace, 'fetch-error.mjs'))}`, - }, - expectToExitWithError: true, - }); - expect(failure).toContain('Failed to fetch'); - expect(failure).toContain('503'); -}); diff --git a/utils/build/update-playwright-node.mjs b/utils/build/update-playwright-node.mjs index 728ae49fbd49f..f56dd38102a91 100644 --- a/utils/build/update-playwright-node.mjs +++ b/utils/build/update-playwright-node.mjs @@ -25,8 +25,9 @@ const dockerfilePaths = await getDockerfilePaths(dockerDirectory); const latestNodeJsLts = await getLatestNodeJsVersion(); for (const dockerfilePath of dockerfilePaths) { - if (refreshDockerfileVersionNumber(latestNodeJsLts, dockerfilePath)) - console.log(`Updated Dockerfile ${path.relative(process.cwd(), dockerfilePath)} to Node.js ${latestNodeJsLts}`); + const nodeMajorVersion = latestNodeJsLts.split('.')[0]; + if (refreshDockerfileVersionNumber(nodeMajorVersion, dockerfilePath)) + console.log(`Updated Dockerfile ${path.relative(process.cwd(), dockerfilePath)} to Node.js ${nodeMajorVersion}.x`); } async function getDockerfilePaths(directory) { diff --git a/utils/docker/Dockerfile.jammy b/utils/docker/Dockerfile.jammy index ec2b57d167bf8..f73051ca7dfe9 100644 --- a/utils/docker/Dockerfile.jammy +++ b/utils/docker/Dockerfile.jammy @@ -4,7 +4,7 @@ FROM ${ACR_CACHE_PREFIX}ubuntu:jammy ARG DEBIAN_FRONTEND=noninteractive ARG TZ=America/Los_Angeles ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright:v%version%-jammy" -ARG NODE_VERSION=24.22.1 # autogenerated via ./update-playwright-node.mjs +ARG NODE_VERSION=24 # autogenerated via ./update-playwright-node.mjs ARG UBUNTU_MIRROR_PREFIX ENV LANG=C.UTF-8 @@ -19,9 +19,9 @@ RUN --mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \ apt-get install -y curl wget gpg ca-certificates && \ mkdir -p /etc/apt/keyrings && \ curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ - echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION%%.*}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ apt-get update && \ - apt-get install -y "nodejs=${NODE_VERSION}-1nodesource1" && \ + apt-get install -y nodejs && \ # Feature-parity with node.js base images. # zstd is used by actions/cache. apt-get install -y --no-install-recommends git openssh-client zstd && \ diff --git a/utils/docker/Dockerfile.noble b/utils/docker/Dockerfile.noble index 46d53ae33c99f..b19816f2e6f8d 100644 --- a/utils/docker/Dockerfile.noble +++ b/utils/docker/Dockerfile.noble @@ -4,7 +4,7 @@ FROM ${ACR_CACHE_PREFIX}ubuntu:noble ARG DEBIAN_FRONTEND=noninteractive ARG TZ=America/Los_Angeles ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright:v%version%-noble" -ARG NODE_VERSION=24.22.1 # autogenerated via ./update-playwright-node.mjs +ARG NODE_VERSION=24 # autogenerated via ./update-playwright-node.mjs ARG UBUNTU_MIRROR_PREFIX ENV LANG=C.UTF-8 @@ -19,9 +19,9 @@ RUN --mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \ apt-get install -y curl wget gpg ca-certificates && \ mkdir -p /etc/apt/keyrings && \ curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ - echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION%%.*}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ apt-get update && \ - apt-get install -y "nodejs=${NODE_VERSION}-1nodesource1" && \ + apt-get install -y nodejs && \ # Feature-parity with node.js base images. # zstd is used by actions/cache. apt-get install -y --no-install-recommends git openssh-client zstd && \ diff --git a/utils/docker/Dockerfile.resolute b/utils/docker/Dockerfile.resolute index 4ecb770a2d334..6559404205529 100644 --- a/utils/docker/Dockerfile.resolute +++ b/utils/docker/Dockerfile.resolute @@ -4,7 +4,7 @@ FROM ${ACR_CACHE_PREFIX}ubuntu:resolute ARG DEBIAN_FRONTEND=noninteractive ARG TZ=America/Los_Angeles ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright:v%version%-resolute" -ARG NODE_VERSION=24.22.1 # autogenerated via ./update-playwright-node.mjs +ARG NODE_VERSION=24 # autogenerated via ./update-playwright-node.mjs ARG UBUNTU_MIRROR_PREFIX ENV LANG=C.UTF-8 @@ -20,9 +20,9 @@ RUN --mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \ apt-get install -y curl wget gpg ca-certificates && \ mkdir -p /etc/apt/keyrings && \ curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ - echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION%%.*}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ apt-get update && \ - apt-get install -y "nodejs=${NODE_VERSION}-1nodesource1" && \ + apt-get install -y nodejs && \ # Feature-parity with node.js base images. # zstd is used by actions/cache. apt-get install -y --no-install-recommends git openssh-client zstd && \ diff --git a/utils/docker/build.sh b/utils/docker/build.sh index 669646792c5d3..5b9ae43bc8d68 100755 --- a/utils/docker/build.sh +++ b/utils/docker/build.sh @@ -42,9 +42,8 @@ if [[ -n "${NPMRC_SECRET:-}" ]]; then SECRET_ARGS+=(--secret "id=npmrc,src=${NPMRC_SECRET}") fi -VERSIONS=$(node ./latest-versions.mjs) -read -r NODE_VERSION CHROMIUM_VERSION <<< "$VERSIONS" -echo "Building with Node.js ${NODE_VERSION} and Chrome for Testing ${CHROMIUM_VERSION}" +CHROMIUM_VERSION=$(node ./latest-versions.mjs) +echo "Building with Chrome for Testing ${CHROMIUM_VERSION}" # Keep each arch image a plain single-platform manifest without the unknown/unknown platform entry. export BUILDX_NO_DEFAULT_ATTESTATIONS=1 @@ -60,7 +59,6 @@ for ((attempt = 1; attempt <= MAX_ATTEMPTS; attempt++)); do if docker build --pull --platform "${PLATFORM}" \ --build-arg ACR_CACHE_PREFIX="${ACR_CACHE_PREFIX}" \ --build-arg UBUNTU_MIRROR_PREFIX="${UBUNTU_MIRROR_PREFIX}" \ - --build-arg NODE_VERSION="${NODE_VERSION}" \ --build-arg CHROMIUM_VERSION="${CHROMIUM_VERSION}" \ "${SECRET_ARGS[@]}" \ -t "$3" -f "Dockerfile.$2" .; then diff --git a/utils/docker/latest-versions.mjs b/utils/docker/latest-versions.mjs index 26018df3026fb..4b1f6020b9dac 100644 --- a/utils/docker/latest-versions.mjs +++ b/utils/docker/latest-versions.mjs @@ -21,13 +21,9 @@ async function fetchJSON(url) { return response.json(); } -const [nodeReleases, chromeReleases] = await Promise.all([ - fetchJSON('https://nodejs.org/dist/index.json'), - fetchJSON('https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json'), -]); -const nodeVersion = nodeReleases.find(release => release.lts)?.version; +const chromeReleases = await fetchJSON('https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json'); const chromiumVersion = chromeReleases.channels?.Stable?.version; -if (!/^v\d+\.\d+\.\d+$/.test(nodeVersion) || !/^\d+\.\d+\.\d+\.\d+$/.test(chromiumVersion)) - throw new Error('Release metadata must contain a Node.js LTS version and a stable Chrome for Testing version'); +if (!/^\d+\.\d+\.\d+\.\d+$/.test(chromiumVersion)) + throw new Error('Release metadata must contain a stable Chrome for Testing version'); -console.log(`${nodeVersion.slice(1)} ${chromiumVersion}`); +console.log(chromiumVersion); From 34d4e2ee5bc6f672c87b77c0377e0063a4f32556 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Fri, 30 Oct 2026 14:52:45 +0000 Subject: [PATCH 3/3] fix(docker): pick the latest Chrome for Testing on the same branch in build.sh Update browsers.json on the host before packing playwright-core, instead of inside the image. Only consider versions on the same branch as browsers.json, from known-good-versions-with-downloads.json. Drop the docker build --pull. --- utils/docker/Dockerfile.jammy | 4 -- utils/docker/Dockerfile.noble | 4 -- utils/docker/Dockerfile.resolute | 4 -- utils/docker/build.sh | 17 ++++--- utils/docker/configure-browsers.mjs | 32 ------------ utils/docker/latest-versions.mjs | 29 ----------- utils/docker/update-chromium-version.mjs | 63 ++++++++++++++++++++++++ 7 files changed, 74 insertions(+), 79 deletions(-) delete mode 100644 utils/docker/configure-browsers.mjs delete mode 100644 utils/docker/latest-versions.mjs create mode 100644 utils/docker/update-chromium-version.mjs diff --git a/utils/docker/Dockerfile.jammy b/utils/docker/Dockerfile.jammy index f73051ca7dfe9..d36b5f1177d90 100644 --- a/utils/docker/Dockerfile.jammy +++ b/utils/docker/Dockerfile.jammy @@ -39,16 +39,12 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright # 1. Add tip-of-tree Playwright package to install its browsers. # The package should be built beforehand from tip-of-tree Playwright. COPY ./playwright-core.tar.gz /tmp/playwright-core.tar.gz -COPY ./configure-browsers.mjs /tmp/configure-browsers.mjs -ARG CHROMIUM_VERSION # 2. Set up playwright-core and install all system dependencies in one layer. RUN install -d -m 777 /ms-playwright /ms-playwright/.links && \ mkdir /ms-playwright-agent && \ cd /ms-playwright-agent && npm init -y && \ npm i /tmp/playwright-core.tar.gz && \ - node /tmp/configure-browsers.mjs "${CHROMIUM_VERSION}" && \ - rm /tmp/configure-browsers.mjs && \ npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \ npm exec --no -- playwright-core install-deps && \ # Workaround for https://github.com/microsoft/playwright/issues/27313 diff --git a/utils/docker/Dockerfile.noble b/utils/docker/Dockerfile.noble index b19816f2e6f8d..627e6fd366f81 100644 --- a/utils/docker/Dockerfile.noble +++ b/utils/docker/Dockerfile.noble @@ -39,16 +39,12 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright # 1. Add tip-of-tree Playwright package to install its browsers. # The package should be built beforehand from tip-of-tree Playwright. COPY ./playwright-core.tar.gz /tmp/playwright-core.tar.gz -COPY ./configure-browsers.mjs /tmp/configure-browsers.mjs -ARG CHROMIUM_VERSION # 2. Set up playwright-core and install all system dependencies in one layer. RUN install -d -m 777 /ms-playwright /ms-playwright/.links && \ mkdir /ms-playwright-agent && \ cd /ms-playwright-agent && npm init -y && \ npm i /tmp/playwright-core.tar.gz && \ - node /tmp/configure-browsers.mjs "${CHROMIUM_VERSION}" && \ - rm /tmp/configure-browsers.mjs && \ npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \ npm exec --no -- playwright-core install-deps && \ rm -rf /var/lib/apt/lists/* diff --git a/utils/docker/Dockerfile.resolute b/utils/docker/Dockerfile.resolute index 6559404205529..30d4880a20ebe 100644 --- a/utils/docker/Dockerfile.resolute +++ b/utils/docker/Dockerfile.resolute @@ -40,16 +40,12 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright # 1. Add tip-of-tree Playwright package to install its browsers. # The package should be built beforehand from tip-of-tree Playwright. COPY ./playwright-core.tar.gz /tmp/playwright-core.tar.gz -COPY ./configure-browsers.mjs /tmp/configure-browsers.mjs -ARG CHROMIUM_VERSION # 2. Set up playwright-core and install all system dependencies in one layer. RUN install -d -m 777 /ms-playwright /ms-playwright/.links && \ mkdir /ms-playwright-agent && \ cd /ms-playwright-agent && npm init -y && \ npm i /tmp/playwright-core.tar.gz && \ - node /tmp/configure-browsers.mjs "${CHROMIUM_VERSION}" && \ - rm /tmp/configure-browsers.mjs && \ npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \ npm exec --no -- playwright-core install-deps && \ rm -rf /var/lib/apt/lists/* diff --git a/utils/docker/build.sh b/utils/docker/build.sh index 5b9ae43bc8d68..b4f88b7989954 100755 --- a/utils/docker/build.sh +++ b/utils/docker/build.sh @@ -16,16 +16,25 @@ if [[ ($1 == '--help') || ($1 == '-h') || ($1 == '') || ($2 == '') ]]; then exit 0 fi +BROWSERS_JSON="../../packages/playwright-core/browsers.json" + function cleanup() { rm -f "playwright-core.tar.gz" + if [[ -f "${BROWSERS_JSON}.bak" ]]; then + mv -f "${BROWSERS_JSON}.bak" "${BROWSERS_JSON}" + fi } trap "cleanup; cd $(pwd -P)" EXIT cd "$(dirname "$0")" # We rely on `./playwright-core.tar.gz` to download browsers into the docker -# image. +# image. The package is packed with the latest Chrome for Testing on the same +# branch, so that the image ships the latest security fixes. +cp "${BROWSERS_JSON}" "${BROWSERS_JSON}.bak" +node ./update-chromium-version.mjs "${BROWSERS_JSON}" node ../../utils/pack_package.js playwright-core ./playwright-core.tar.gz +mv -f "${BROWSERS_JSON}.bak" "${BROWSERS_JSON}" PLATFORM="" if [[ "$1" == "--arm64" ]]; then @@ -42,9 +51,6 @@ if [[ -n "${NPMRC_SECRET:-}" ]]; then SECRET_ARGS+=(--secret "id=npmrc,src=${NPMRC_SECRET}") fi -CHROMIUM_VERSION=$(node ./latest-versions.mjs) -echo "Building with Chrome for Testing ${CHROMIUM_VERSION}" - # Keep each arch image a plain single-platform manifest without the unknown/unknown platform entry. export BUILDX_NO_DEFAULT_ATTESTATIONS=1 @@ -56,10 +62,9 @@ export BUILDX_NO_DEFAULT_ATTESTATIONS=1 MAX_ATTEMPTS=3 for ((attempt = 1; attempt <= MAX_ATTEMPTS; attempt++)); do - if docker build --pull --platform "${PLATFORM}" \ + if docker build --platform "${PLATFORM}" \ --build-arg ACR_CACHE_PREFIX="${ACR_CACHE_PREFIX}" \ --build-arg UBUNTU_MIRROR_PREFIX="${UBUNTU_MIRROR_PREFIX}" \ - --build-arg CHROMIUM_VERSION="${CHROMIUM_VERSION}" \ "${SECRET_ARGS[@]}" \ -t "$3" -f "Dockerfile.$2" .; then exit 0 diff --git a/utils/docker/configure-browsers.mjs b/utils/docker/configure-browsers.mjs deleted file mode 100644 index d89a647410eb7..0000000000000 --- a/utils/docker/configure-browsers.mjs +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import fs from 'fs'; - -const version = process.argv[2]; -if (!/^\d+\.\d+\.\d+\.\d+$/.test(version)) - throw new Error('Expected a Chrome for Testing version'); - -const file = 'node_modules/playwright-core/browsers.json'; -const browsersJSON = JSON.parse(fs.readFileSync(file, 'utf8')); -for (const name of ['chromium', 'chromium-headless-shell']) { - const browser = browsersJSON.browsers.find(browser => browser.name === name); - if (!browser) - throw new Error(`Missing browser descriptor: ${name}`); - // Keep the revision so the matching Playwright package finds the stable browser. - browser.browserVersion = version; -} -fs.writeFileSync(file, JSON.stringify(browsersJSON, null, 2) + '\n'); diff --git a/utils/docker/latest-versions.mjs b/utils/docker/latest-versions.mjs deleted file mode 100644 index 4b1f6020b9dac..0000000000000 --- a/utils/docker/latest-versions.mjs +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -async function fetchJSON(url) { - const response = await fetch(url, { signal: AbortSignal.timeout(30_000) }); - if (!response.ok) - throw new Error(`Failed to fetch ${url}: ${response.status}`); - return response.json(); -} - -const chromeReleases = await fetchJSON('https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json'); -const chromiumVersion = chromeReleases.channels?.Stable?.version; -if (!/^\d+\.\d+\.\d+\.\d+$/.test(chromiumVersion)) - throw new Error('Release metadata must contain a stable Chrome for Testing version'); - -console.log(chromiumVersion); diff --git a/utils/docker/update-chromium-version.mjs b/utils/docker/update-chromium-version.mjs new file mode 100644 index 0000000000000..d16decdc85df9 --- /dev/null +++ b/utils/docker/update-chromium-version.mjs @@ -0,0 +1,63 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Updates browsers.json to the latest Chrome for Testing on the same branch, +// so that the docker image ships the latest security fixes. Chrome releases +// fixes as patch bumps on the same branch, e.g. 156.0.8078.4 -> 156.0.8078.80. +// The revision is kept, so that the browser directory name stays the same. + +import fs from 'fs'; + +const browsersJSONPath = process.argv[2]; +if (!browsersJSONPath) + throw new Error('usage: update-chromium-version.mjs '); + +const browsersJSON = JSON.parse(fs.readFileSync(browsersJSONPath, 'utf8')); +const descriptors = ['chromium', 'chromium-headless-shell'].map(name => { + const descriptor = browsersJSON.browsers.find(browser => browser.name === name); + if (!descriptor) + throw new Error(`Missing browser descriptor: ${name}`); + return descriptor; +}); + +const patchOf = version => Number(version.split('.')[3]); +const currentVersion = descriptors[0].browserVersion; +if (!/^\d+\.\d+\.\d+\.\d+$/.test(currentVersion)) + throw new Error(`Unexpected Chrome for Testing version: ${currentVersion}`); +const branchPrefix = currentVersion.split('.').slice(0, 3).join('.') + '.'; + +const url = 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json'; +const response = await fetch(url, { signal: AbortSignal.timeout(30_000) }); +if (!response.ok) + throw new Error(`Failed to fetch ${url}: ${response.status}`); +const { versions } = await response.json(); + +let latestVersion = currentVersion; +for (const { version, downloads } of versions) { + if (!version.startsWith(branchPrefix) || !downloads.chrome || !downloads['chrome-headless-shell']) + continue; + if (patchOf(version) > patchOf(latestVersion)) + latestVersion = version; +} + +if (latestVersion === currentVersion) { + console.log(`Chrome for Testing ${currentVersion} is the latest on its branch`); +} else { + console.log(`Updating Chrome for Testing ${currentVersion} to ${latestVersion}`); + for (const descriptor of descriptors) + descriptor.browserVersion = latestVersion; + fs.writeFileSync(browsersJSONPath, JSON.stringify(browsersJSON, null, 2) + '\n'); +}