Skip to content

Commit e3a853f

Browse files
authored
Add check if crypto.getRandomValues is available
On some IE11 the randomBytes helper crashes with "TypeError: getRandomValues is not defined". The reason is not clear, maybe something pollutes self.crypto with a bad polyfill. Nevertheless it makes sense to fall back to Math.random if crypto.getRandomValues is not available.
1 parent 1fb82be commit e3a853f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/firestore/src/platform/browser/random_bytes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function randomBytes(nBytes: number): Uint8Array {
3030
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3131
typeof self !== 'undefined' && (self.crypto || (self as any)['msCrypto']);
3232
const bytes = new Uint8Array(nBytes);
33-
if (crypto) {
33+
if (crypto && crypto.getRandomValues) {
3434
crypto.getRandomValues(bytes);
3535
} else {
3636
// Falls back to Math.random

0 commit comments

Comments
 (0)