check presence of window before using it and appease ts types

This commit is contained in:
Dylan Oliver 2022-03-17 22:30:27 -04:00 committed by Franck Royer
parent 565ffb18fb
commit 9cf2924f7b
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 5 additions and 1 deletions

View File

@ -11,7 +11,11 @@ declare global {
} }
} }
const crypto = window.crypto || window.msCrypto || nodeCrypto.webcrypto; const crypto =
(typeof window !== "undefined" &&
(window as Window) &&
(window.crypto || window.msCrypto)) ||
(nodeCrypto.webcrypto as unknown as Crypto);
const subtle: SubtleCrypto = crypto.subtle || crypto.webkitSubtle; const subtle: SubtleCrypto = crypto.subtle || crypto.webkitSubtle;
if (subtle === undefined) { if (subtle === undefined) {