I'm at my wit's end here. Is there any way to do this, knowing that web workers can't access the window object? Please help!
The Crypto. getRandomValues() method lets you get cryptographically strong random values. The array given as the parameter is filled with random numbers (random in its cryptographic meaning).
The Window. crypto property returns the crypto object associated with the global object. This is a read-only property. This object allows web pages to access certain cryptographic related services.
I know this is an old question but i stumbled accross and things changed. Most browsers do support crypto in webworkers now.
In webworkers you can access self which does not contain all of the "window" properties (especially nothing dom-related), but holds API methods like crypto functions.
Therefore you can simply access self.crypto.getRandomValues() from within webworker.
I made a fiddle as an example: http://jsfiddle.net/jbrosi/yj17gomk/
However please not that calls to webworker and back are also having a small performance impact and most expensive crypto functions (like crypto.subtle.encrypt are async and should therefore not block your mainthread at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With