Add forceCloudflareWorkers option to bypass runtime inference#17
Conversation
Adds getCloudflareWorkersOverride() to common/runtime.ts and logs the runtime decision in init() when a Workers context is present, e.g. `[CH] Cloudflare Workers runtime: true (via override)` vs `(via navigator inference)`. Helps integrators confirm at a glance which signal drove the transport decision. Bumps to 2.4.2. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
@copilot Are you able to review this PR? |
Sure, here's my review: Overall: The approach is clean — converting 🐛 Bug: module-level override is never reset between
Suggested fix in - if (config.options?.forceCloudflareWorkers === true) {
- setCloudflareWorkersOverride(true);
- }
+ // Unconditionally sync the override so repeated init() calls don't bleed state.
+ setCloudflareWorkersOverride(
+ config.options?.forceCloudflareWorkers === true ? true : null
+ );
ℹ️ Suggestion: add unit tests for the new behaviour The repo has Jest/ts-jest configured (
…would give confidence this doesn't regress silently. |
Previously, calling init() with forceCloudflareWorkers:true would leave the module-level override set indefinitely. Subsequent init() calls without the option would silently inherit the forced value because nothing cleared it. Now sync unconditionally — set to true when explicitly forced, otherwise reset to null so navigator inference takes over. Fixes state bleed across init() calls in test suites and any multi-init scenario. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
isCloudflareWorkers is now a function that consults a module-level override before falling back to the navigator.userAgent check. Callers that already know they're on Workers can set options.forceCloudflareWorkers: true on init() to skip inference and guarantee the fetch/await-recordPerformance code paths are used.