From 26b4206d879673f8e2cbbb615b59bb211c8ea3fc Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 14 Jun 2026 16:23:43 +0200 Subject: [PATCH] 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). --- .puppeteerrc.json | 4 ++-- test/test.mjs | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.puppeteerrc.json b/.puppeteerrc.json index 4401066f6..a1d055219 100644 --- a/.puppeteerrc.json +++ b/.puppeteerrc.json @@ -1,13 +1,13 @@ { "chrome": { - "skipDownload": false, + "skipDownload": true, "version": "stable" }, "chrome-headless-shell": { "skipDownload": true }, "firefox": { - "skipDownload": false, + "skipDownload": true, "version": "nightly" } } diff --git a/test/test.mjs b/test/test.mjs index e35a0e2c6..a2a1a733b 100644 --- a/test/test.mjs +++ b/test/test.mjs @@ -28,6 +28,7 @@ import { downloadManifestFiles, verifyManifestFiles, } from "./downloadutils.mjs"; +import { execSync } from "child_process"; import fs from "fs"; import istanbulCoverage from "istanbul-lib-coverage"; import istanbulReportGenerator from "istanbul-reports"; @@ -1095,9 +1096,13 @@ async function startBrowser({ } async function startBrowsers({ baseUrl, initializeSession, numSessions = 1 }) { - // Remove old browser revisions from Puppeteer's cache. Updating Puppeteer can - // cause new browser revisions to be downloaded, so trimming the cache will - // prevent the disk from filling up over time. + // Install the browsers. + for (const browser of ["firefox@nightly", "chrome@stable"]) { + 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(); const browserNames = ["firefox", "chrome"];