Skip to content

Commit b4eb412

Browse files
bneijtniper1dcousens
authored
Use globalThis if available (#34)
* Use globalThis if available Use [globalThis](https://developer.mozilla.org/en-US/docs/Web/API/crypto_property) if available. Closes #29 * Update browser.js Co-authored-by: Niklas Shepper Persson <external.niklas.persson@inter.ikea.com> --------- Co-authored-by: Niklas Shepper Persson <external.niklas.persson@inter.ikea.com> Co-authored-by: Daniel Cousens <413395+dcousens@users.noreply.github.com>
1 parent c967173 commit b4eb412

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

browser.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function oldBrowser () {
1212
throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11')
1313
}
1414

15-
const crypto = global.crypto || global.msCrypto
15+
const _global = typeof globalThis !== 'undefined' ? globalThis : global
16+
const crypto = _global.crypto || _global.msCrypto
1617

1718
if (crypto && crypto.getRandomValues) {
1819
module.exports = randomBytes
@@ -46,4 +47,4 @@ function randomBytes (size, cb) {
4647
}
4748

4849
return bytes
49-
}
50+
}

0 commit comments

Comments
 (0)