Fix browser random in WebWorkers (#2405).

This commit is contained in:
Richard Moore 2021-12-24 02:05:10 -05:00
parent 3d6a7ec020
commit 4ba63acc10

@ -9,18 +9,15 @@ const logger = new Logger(version);
// Debugging line for testing browser lib in node // Debugging line for testing browser lib in node
//const window = { crypto: { getRandomValues: () => { } } }; //const window = { crypto: { getRandomValues: () => { } } };
let anyGlobal: any = null; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
try { function getGlobal(): any {
anyGlobal = (window as any); if (typeof self !== 'undefined') { return self; }
if (anyGlobal == null) { throw new Error("try next"); } if (typeof window !== 'undefined') { return window; }
} catch (error) { if (typeof global !== 'undefined') { return global; }
try { throw new Error('unable to locate global object');
anyGlobal = (global as any); };
if (anyGlobal == null) { throw new Error("try next"); }
} catch (error) { const anyGlobal = getGlobal();
anyGlobal = { };
}
}
let crypto: any = anyGlobal.crypto || anyGlobal.msCrypto; let crypto: any = anyGlobal.crypto || anyGlobal.msCrypto;
if (!crypto || !crypto.getRandomValues) { if (!crypto || !crypto.getRandomValues) {