diff --git a/.github/workflows/test-and-check.yml b/.github/workflows/test-and-check.yml index b4b47b7e24..2bb4670273 100644 --- a/.github/workflows/test-and-check.yml +++ b/.github/workflows/test-and-check.yml @@ -136,6 +136,33 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} + # Browser Run tests in `packages/miniflare/test/plugins/browser/index.spec.ts` + # and the `fixtures/browser-run` fixture use `@puppeteer/browsers` to + # download Chrome into the global Wrangler cache. Caching that binary + # across CI runs avoids ~150 MB of repeat downloads per run and reduces + # the surface area for the intermittent partial-extraction race that + # surfaces as `The browser folder (...) exists but the executable (...) + # is missing` (see #13971, #13980). + # + # The Browser Run fixture is skipped on Ubuntu (AppArmor), but the + # miniflare browser spec runs everywhere, so the cache is needed on all + # three OSes for `packages-and-tools` and on Windows + macOS for + # `fixtures`. + - name: Restore Chrome browser cache (Browser Run) + if: steps.changes.outputs.everything_but_markdown == 'true' && (matrix.suite == 'packages-and-tools' || (matrix.suite == 'fixtures' && matrix.os != 'ubuntu-latest')) + uses: actions/cache@v4 + with: + # The Chrome version lives in + # `packages/miniflare/src/plugins/browser-rendering/browser-version.ts`. + # Bumping that constant invalidates this cache automatically via + # `hashFiles()` — a cache miss only triggers a fresh download, no + # functional impact. + key: chrome-${{ runner.os }}-${{ hashFiles('packages/miniflare/src/plugins/browser-rendering/browser-version.ts') }} + path: | + ~/.cache/.wrangler/chrome + ~/Library/Caches/.wrangler/chrome + ~/AppData/Local/xdg.cache/.wrangler/chrome + - name: Run tests (tools only) # tools _only_ needs to be tested on Linux because they're only intended to run in CI if: steps.changes.outputs.everything_but_markdown == 'true' && matrix.suite == 'packages-and-tools' && matrix.os == 'ubuntu-latest' diff --git a/packages/miniflare/src/index.ts b/packages/miniflare/src/index.ts index ccdc8bdaf4..9df90d06e4 100644 --- a/packages/miniflare/src/index.ts +++ b/packages/miniflare/src/index.ts @@ -63,6 +63,7 @@ import { WORKFLOWS_PLUGIN_NAME, } from "./plugins"; import { RPC_PROXY_SERVICE_NAME } from "./plugins/assets/constants"; +import { BROWSER_VERSION } from "./plugins/browser-rendering/browser-version"; import { CUSTOM_SERVICE_KNOWN_OUTBOUND, CustomServiceKind, @@ -1550,13 +1551,7 @@ export class Miniflare { ); const { sessionId, browserProcess, startTime, wsEndpoint } = await launchBrowser({ - // Puppeteer v22.13.1 supported chrome version: - // https://pptr.dev/supported-browsers#supported-browser-version-list - // - // It should match the supported chrome version for the upstream puppeteer - // version from which @cloudflare/puppeteer branched off, which is specified in: - // https://github.com/cloudflare/puppeteer/?tab=readme-ov-file#workers-version-of-puppeteer-core - browserVersion: "126.0.6478.182", + browserVersion: BROWSER_VERSION, log: this.#log, tmpPath: this.#tmpPath, headful, diff --git a/packages/miniflare/src/plugins/browser-rendering/browser-version.ts b/packages/miniflare/src/plugins/browser-rendering/browser-version.ts new file mode 100644 index 0000000000..ea8e14f309 --- /dev/null +++ b/packages/miniflare/src/plugins/browser-rendering/browser-version.ts @@ -0,0 +1,14 @@ +/** + * The Chrome browser version downloaded by Miniflare's Browser Run binding. + * + * Puppeteer v22.13.1 supported chrome version: + * https://pptr.dev/supported-browsers#supported-browser-version-list + * + * It should match the supported chrome version for the upstream puppeteer + * version from which @cloudflare/puppeteer branched off, which is specified in: + * https://github.com/cloudflare/puppeteer/?tab=readme-ov-file#workers-version-of-puppeteer-core + * + * Bumping this value also invalidates the Chrome binary cache in + * `.github/workflows/test-and-check.yml` (which uses `hashFiles()` on this file). + */ +export const BROWSER_VERSION = "126.0.6478.182";