-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ethers doesn't work in a Worker #3536
Comments
Instead of passing in the URL directly, try passing in an object that looks like: That should skip the fetch setup that the affects JavaScriptCore-based systems with a custom/non-standard fetch implementation like Cloudflare Workers… :) |
(in v6, the fetch class is much more flexible ;)) |
I'll give the object a shot! But just to make sure we're on the same page here, I'm referring to a Worker, not a Cloudflare Worker |
@samczsun Oh, that issue was mainly regarding Cloudflare workers. I’m not sure why a normal Worker would complain about that value for the fetch. But the object should skip populating it anyways, so may still help you. |
(also, random question; what browser are you using?) |
Latest Chrome. I think maybe it's because my worker is built from a blob url? |
Oh. Possibly. I know Safari used to have weird behaviours (especially with things CORS-ish) for BLOB urls. Did |
@ricmoo ran into a similar issue this week, provider.getBlockNumber() was returning Setting the |
Awesome! I'm going to close this now as fixed. If you have any further issues though, please let me know. Thanks! :) |
Global options would be useful. There are libraries that don't allow you to customize everything. I.e. https://github.com/synapsecns/sdk which uses |
Workaround from ethers-io/ethers.js#3536 (comment) Signed-off-by: Josh Chang <[email protected]>
Ethers Version
5.7.2
Search Terms
No response
Describe the Problem
In a Worker, it seems like
fetch
behaves differently:The cause is the following error:
Failed to execute 'fetch' on 'WorkerGlobalScope': Referrer 'client' is not a valid URL.
, which is set here:ethers.js/packages/web/src.ts/browser-geturl.ts
Line 23 in c80fcdd
It seems this was discussed in #1886 but I'm not sure how to turn it on. Given that this affects vanilla JS and not an esoteric platform, maybe the behavior can be changed to be more flexible?
Code Snippet
No response
Contract ABI
No response
Errors
No response
Environment
Browser (Chrome, Safari, etc)
Environment (Other)
No response
The text was updated successfully, but these errors were encountered: