Skip to content

Commit 64a4af9

Browse files
committed
Defeat webkit's overzealousness
1 parent 205de68 commit 64a4af9

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

lib/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,14 @@ export function detectPrng(allowInsecure: boolean = false, root?: any): PRNG {
123123
const browserCrypto = root && (root.crypto || root.msCrypto)
124124

125125
if (browserCrypto) {
126-
try {
127-
return () => {
126+
return () => {
128127
const buffer = new Uint8Array(1)
129128
browserCrypto.getRandomValues(buffer)
130129
return buffer[0] / 0xff
131-
}
132-
} catch (e) {}
130+
}
133131
} else {
134132
try {
135-
const nodeCrypto = require("crypto")
133+
const nodeCrypto = global["require"]("crypto")
136134
return () => nodeCrypto.randomBytes(1).readUInt8() / 0xff
137135
} catch (e) {}
138136
}

0 commit comments

Comments
 (0)