Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web: TypeError: Cannot read properties of undefined (reading 'subtle') #6

Open
dskvr opened this issue Apr 14, 2024 · 0 comments
Open

Comments

@dskvr
Copy link

dskvr commented Apr 14, 2024

TypeError: Cannot read properties of undefined (reading 'subtle')

in the bundle:
const hash = await node_crypto_1.webcrypto.subtle.digest(algorithm, data);

reading webcrypto documentation I found
window.crypto.subtle

executed in console:
window.crypto.subtle returns

[[Prototype]]: SubtleCryptodecrypt: ƒ decrypt()deriveBits: ƒ deriveBits()deriveKey: ƒ deriveKey()digest: ƒ digest()encrypt: ƒ encrypt()exportKey: ƒ exportKey()generateKey: ƒ generateKey()importKey: ƒ importKey()sign: ƒ sign()unwrapKey: ƒ unwrapKey()verify: ƒ verify()wrapKey: ƒ wrapKey()constructor: ƒ SubtleCrypto()Symbol(Symbol.toStringTag): "SubtleCrypto"[[Prototype]]: Object

This bug was found while running vite dev on a SvelteKit site, very possible it's related to vite, but regardless seems like the correct reference in the browser is window.crypto

@dskvr dskvr changed the title Needs work in web Web: TypeError: Cannot read properties of undefined (reading 'subtle') Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant