web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Crashes in Service Worker: XHR2 is not a constructor

Open Jack-Works opened this issue 3 years ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

image

Uploading image.png…

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.

Jack-Works avatar Jul 26 '22 09:07 Jack-Works

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.

Jack-Works avatar Jul 26 '22 09:07 Jack-Works

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,

Muhammad-Altabba avatar Aug 04 '22 16:08 Muhammad-Altabba

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'.

image

Jack-Works avatar Aug 05 '22 03:08 Jack-Works

I guess this is fixed by #5085?

Jack-Works avatar Aug 23 '22 13:08 Jack-Works

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.

github-actions[bot] avatar Oct 23 '22 00:10 github-actions[bot]