Skip to content

Conversation

ruifigueira
Copy link
Contributor

@ruifigueira ruifigueira commented Aug 10, 2025

Browser installation relied on a postinstall script from puppeteer package which was unreliable with npx-import.

For instance, if we have a workers project with browser binding that doesn't explicitly include puppeteer, the first time we run it it with npx wrangler dev and trigger the launch function, it will install the browser and cache it under ~/.cache/puppeteer.

But if for some reason we delete the cached browser (e.g., we run npx puppeteer browsers clear), and we try to run it the same way as above, it will fail with:

Error: Could not find Chrome (ver. 124.0.6367.207). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npx puppeteer browsers install chrome`) or
 2. your cache path is incorrectly configured (which is: /Users/rfigueira/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
    at ChromeLauncher.resolveExecutablePath (/Users/rfigueira/.npm/_npx/9c191fc107e155e1/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:295:27)
    at ChromeLauncher.executablePath (/Users/rfigueira/.npm/_npx/9c191fc107e155e1/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:209:25)
    at ChromeLauncher.computeLaunchArguments (/Users/rfigueira/.npm/_npx/9c191fc107e155e1/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:89:37)
    at async ChromeLauncher.launch (/Users/rfigueira/.npm/_npx/9c191fc107e155e1/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:70:28)
    at async #handleLoopback (/Users/rfigueira/dev/tmp/puppeteer-test/node_modules/wrangler/node_modules/miniflare/dist/src/index.js:25418:25)

After deleting the browser, and because npx-import is already installed, when we run npxImport("[email protected]") it will just skip the installation, and therefore it won't call the postinstall script associated with that package that actually installs and caches the browser.

  • Tests
    • Tests included
    • Tests not necessary because: existing test cover this change
  • Public documentation
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: feature improvement

Copy link

changeset-bot bot commented Aug 10, 2025

🦋 Changeset detected

Latest commit: 038071a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
miniflare Minor
@cloudflare/pages-shared Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Aug 10, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@10306

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@10306

miniflare

npm i https://pkg.pr.new/miniflare@10306

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@10306

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@10306

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@10306

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@10306

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@10306

wrangler

npm i https://pkg.pr.new/wrangler@10306

commit: 038071a

@ruifigueira ruifigueira force-pushed the brapi-launch-browser branch 2 times, most recently from 01ac5ec to 00297d4 Compare August 10, 2025 10:57
@ruifigueira ruifigueira force-pushed the brapi-launch-browser branch 2 times, most recently from ace5b95 to 77e2976 Compare August 10, 2025 15:48
@ruifigueira ruifigueira marked this pull request as ready for review August 11, 2025 20:37
@ruifigueira ruifigueira requested a review from a team as a code owner August 11, 2025 20:37
@ruifigueira ruifigueira force-pushed the brapi-launch-browser branch from 77e2976 to fdae05d Compare August 11, 2025 20:38
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach! Gets the minimal install (similar to npx-import) for people not using browser-rendering, while having reliable on-demand install for users that do, with caching!

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Aug 13, 2025
Browser installation relied on a postinstall script from puppeteer package which was unreliable with npx-import.

For instance, if we have a workers project with browser binding that doesn't explicitly include `puppeteer`, the first time we run it it with `npx wrangler dev` and trigger the `launch` function, it will install the browser and cache it under `~/.cache/puppeteer`.

But if for some reason we delete the cached browser (e.g., we run `npx puppeteer browsers clear`), and we try to run it the same way as above, it will fail with:

```
Error: Could not find Chrome (ver. 124.0.6367.207). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npx puppeteer browsers install chrome`) or
 2. your cache path is incorrectly configured (which is: /Users/rfigueira/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
    at ChromeLauncher.resolveExecutablePath (/Users/rfigueira/.npm/_npx/9c191fc107e155e1/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:295:27)
    at ChromeLauncher.executablePath (/Users/rfigueira/.npm/_npx/9c191fc107e155e1/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:209:25)
    at ChromeLauncher.computeLaunchArguments (/Users/rfigueira/.npm/_npx/9c191fc107e155e1/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:89:37)
    at async ChromeLauncher.launch (/Users/rfigueira/.npm/_npx/9c191fc107e155e1/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:70:28)
    at async #handleLoopback (/Users/rfigueira/dev/tmp/puppeteer-test/node_modules/wrangler/node_modules/miniflare/dist/src/index.js:25418:25)
```

After deleting the browser, and because `npx-import` is already installed, when we run `npxImport("[email protected]")` it will just skip the installation, and therefore it won't call the `postinstall` script associated with that package that actually installs and caches the browser.
@ruifigueira ruifigueira merged commit ae0c806 into main Aug 13, 2025
47 of 52 checks passed
@ruifigueira ruifigueira deleted the brapi-launch-browser branch August 13, 2025 18:35
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Aug 13, 2025
@lrapoport-cf lrapoport-cf mentioned this pull request Aug 14, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants