Because of how the self variable is created, any access to self.crypto throws an Uncaught TypeError: Illegal invocation exception.
This will happen when the Random.secure() constructor is called. It compiles to Javascript that looks like this:
var $crypto = self.crypto;
if ($crypto != null)
if ($crypto.getRandomValues != null)
return;
throw H.wrapException(P.UnsupportedError$("No source of cryptographically secure random numbers available."));
But accessing crypto will throw.
You can try this yourself in Chrome:
- Open a dev console
var a = Object.create(window);
a.crypto
- Exception is thrown
According to this: uuidjs/uuid#256, it's because it's losing the Crypto context.
My hacky fix is to just make the first line be var self = global; and call it good.
Because of how the
selfvariable is created, any access toself.cryptothrows anUncaught TypeError: Illegal invocationexception.This will happen when the Random.secure() constructor is called. It compiles to Javascript that looks like this:
But accessing
cryptowill throw.You can try this yourself in Chrome:
var a = Object.create(window);a.cryptoAccording to this: uuidjs/uuid#256, it's because it's losing the Crypto context.
My hacky fix is to just make the first line be
var self = global;and call it good.