Configure Puppeteeer to not download Chrome/Firefox by default

We currently download Chrome/Firefox immediately on `npm install`
invocations because Puppeteer's postinstall script does that by default.
However, this is wasteful if the user/workflow doesn't actually need to
run Puppeteer or its browsers, for example in GitHub Actions workflows
that do linting, static analysis or other tasks like updating locales or
publishing artifacts.

This commit therefore makes sure no browser binaries get pulled in by
default anymore, and defers doing that until it's actually necessary,
which is when we want to start the browsers in the `startBrowsers`
function of `test.mjs`.

Locally this brings the `npm install` runtime down from 8.998 to 1.800
seconds, and as a bonus it results in better log output too because it
now shows which browser versions were used in the run (whereas
previously with `npm install` this information was not sent to stdout).
This commit is contained in:
Tim van der Meij 2026-06-14 16:23:43 +02:00
parent 6bfefa53da
commit 26b4206d87
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
2 changed files with 10 additions and 5 deletions

View File

@ -1,13 +1,13 @@
{ {
"chrome": { "chrome": {
"skipDownload": false, "skipDownload": true,
"version": "stable" "version": "stable"
}, },
"chrome-headless-shell": { "chrome-headless-shell": {
"skipDownload": true "skipDownload": true
}, },
"firefox": { "firefox": {
"skipDownload": false, "skipDownload": true,
"version": "nightly" "version": "nightly"
} }
} }

View File

@ -28,6 +28,7 @@ import {
downloadManifestFiles, downloadManifestFiles,
verifyManifestFiles, verifyManifestFiles,
} from "./downloadutils.mjs"; } from "./downloadutils.mjs";
import { execSync } from "child_process";
import fs from "fs"; import fs from "fs";
import istanbulCoverage from "istanbul-lib-coverage"; import istanbulCoverage from "istanbul-lib-coverage";
import istanbulReportGenerator from "istanbul-reports"; import istanbulReportGenerator from "istanbul-reports";
@ -1095,9 +1096,13 @@ async function startBrowser({
} }
async function startBrowsers({ baseUrl, initializeSession, numSessions = 1 }) { async function startBrowsers({ baseUrl, initializeSession, numSessions = 1 }) {
// Remove old browser revisions from Puppeteer's cache. Updating Puppeteer can // Install the browsers.
// cause new browser revisions to be downloaded, so trimming the cache will for (const browser of ["firefox@nightly", "chrome@stable"]) {
// prevent the disk from filling up over time. execSync(`npx puppeteer browsers install ${browser}`, { stdio: "inherit" });
}
// Remove old browser revisions from Puppeteer's cache. The commands above can
// download new browser revisions, so this prevents the disk from filling up.
await puppeteer.trimCache(); await puppeteer.trimCache();
const browserNames = ["firefox", "chrome"]; const browserNames = ["firefox", "chrome"];