Skip to content

Fix 'Illegal invocation' error in Cloudflare Workers#282

Draft
narengogi wants to merge 1 commit intomainfrom
fix/cloudflare-worker-fetch-binding-281
Draft

Fix 'Illegal invocation' error in Cloudflare Workers#282
narengogi wants to merge 1 commit intomainfrom
fix/cloudflare-worker-fetch-binding-281

Conversation

@narengogi
Copy link
Member

Fixes #281

The issue was caused by the global.fetch function being returned without proper binding to its execution context in the getFetch() function. When the SDK is used in Cloudflare Workers, the unbound fetch function loses its 'this' reference, resulting in an 'Illegal invocation' TypeError.

This commit ensures that global.fetch is properly bound to the global object, matching the pattern already used for window.fetch and the fallback fetch implementations.

Changes:

  • Updated getFetch() to bind global.fetch to global before returning

Title:

Description:

  • Detailed change 1
  • Detailed change 2
  • ...

Motivation:

Related Issues:
#

Fixes #281

The issue was caused by the global.fetch function being returned
without proper binding to its execution context in the getFetch()
function. When the SDK is used in Cloudflare Workers, the unbound
fetch function loses its 'this' reference, resulting in an
'Illegal invocation' TypeError.

This commit ensures that global.fetch is properly bound to the
global object, matching the pattern already used for window.fetch
and the fallback fetch implementations.

Changes:
- Updated getFetch() to bind global.fetch to global before returning

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.

[Bug]: "Illegal invocation" error when using Portkey SDK with Cloudflare Agent

1 participant