@ethersproject/random not working properly in service worker
See original GitHub issueDescribe the bug
I’m using ethers.js on a wallet (chrome-extension) project.
Everything worked well in when testing in web pages. But when I move the code to background.js
(run as a service worker), it starts to complain about “no secure random source avaialble” (<-- a typo here!).
Actually I solved this issue in my project by adding following code into the beginning of the service worker code:
self.global = { crypto: self.crypto };
So I believe we can be avoid of this issue by adding another condition here:
Hope I’m understanding the error correctly.
Reproduction steps
Run any code that uses randomBytes
in @ethersproject/random
under service worker environment.
Environment: Win10 Desktop Chrome v96 Chrome Extension Manifest V3 background service worker
Search Terms
getRandomValues
UNSUPPORTED_OPERATION
service worker
crypto
no secure random source avaialble
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
This is quite possible. I’ll schedule this fix for the next release. 😃
Awesome! Glad to hear it. 😃
Thanks!