Fix browser random in WebWorkers (#2405).
This commit is contained in:
parent
3d6a7ec020
commit
4ba63acc10
@ -9,18 +9,15 @@ const logger = new Logger(version);
|
||||
// Debugging line for testing browser lib in node
|
||||
//const window = { crypto: { getRandomValues: () => { } } };
|
||||
|
||||
let anyGlobal: any = null;
|
||||
try {
|
||||
anyGlobal = (window as any);
|
||||
if (anyGlobal == null) { throw new Error("try next"); }
|
||||
} catch (error) {
|
||||
try {
|
||||
anyGlobal = (global as any);
|
||||
if (anyGlobal == null) { throw new Error("try next"); }
|
||||
} catch (error) {
|
||||
anyGlobal = { };
|
||||
}
|
||||
}
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
|
||||
function getGlobal(): any {
|
||||
if (typeof self !== 'undefined') { return self; }
|
||||
if (typeof window !== 'undefined') { return window; }
|
||||
if (typeof global !== 'undefined') { return global; }
|
||||
throw new Error('unable to locate global object');
|
||||
};
|
||||
|
||||
const anyGlobal = getGlobal();
|
||||
|
||||
let crypto: any = anyGlobal.crypto || anyGlobal.msCrypto;
|
||||
if (!crypto || !crypto.getRandomValues) {
|
||||
|
Loading…
Reference in New Issue
Block a user