web3.js
web3.js copied to clipboard
Crashes in Service Worker: XHR2 is not a constructor
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior

Expected Behavior
Working.
Steps to Reproduce
Run web3.js in worker.
Web3.js Version
1.7.4
Environment
No response
Anything Else?
Should use fetch if possible.
Note: it try to use xhr2-cookies as a fallback, but it is a Node module, not work on Worker either. We've patched xhr2-cookies to return empty.
Could you please point to a minimal repository or make new one fast on codesandbox.io or similar cloud IDE, so we can help you more? Thanks,
I tried to reproduce this and found XMLHttpRequest is defined in a Worker, but not in a Service Worker.
Our app runs in a service worker (Chrome extension), where XMLHttpRequest is undefined.
The code use typeof XMLHttpRequest === 'undefined' to detect if the runtime is NodeJS, which is incorrect on our platform. Is there anything else you can use? For example, typeof self === 'undefined'.

I guess this is fixed by #5085?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.