Skip to content

fix: lazy-load cloudflare:workers to support non-Worker runtimes - #193

Draft
LordCoughmann wants to merge 2 commits into
cloudflare:mainfrom
LordCoughmann:fix/lazy-cloudflare-workers-import
Draft

fix: lazy-load cloudflare:workers to support non-Worker runtimes#193
LordCoughmann wants to merge 2 commits into
cloudflare:mainfrom
LordCoughmann:fix/lazy-cloudflare-workers-import

Conversation

@LordCoughmann

@LordCoughmann LordCoughmann commented May 28, 2026

Copy link
Copy Markdown

Problem

I ran into this when loading @cloudflare/playwright from Node.js, Deno, and Bun: the top-level cloudflare:workers import crashes before connectOverCDP() can be used with an external CDP endpoint.

Reproduction: https://github.com/LordCoughmann/repo-cf-playwright-lazy-import

pnpm install
node index.mjs
# → Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported

Solution

I worked around this in my own fork by resolving cloudflare:workers lazily only when Browser Binding functions are called. This keeps Worker behavior unchanged while allowing the package to load in non-Worker runtimes; invalid Browser Binding calls still report the existing No binding found for ... error.

Validation

  • Existing package build and focused checks pass.
  • npm run test:node-import passes from the non-Worker package directory.
  • The import smoke test verifies that chromium.connectOverCDP is available outside Workers.

Refs: #88, #59

The top-level import of cloudflare:workers causes the module to crash
in non-Worker runtimes (Node.js, Deno, Bun, browsers). Replace with
a lazy getter using createRequire for ESM compliance. The module is
only resolved when Browser Binding functions are actually called.

Call-site errors (No binding found for X) remain unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant