'How to use window.crypto.subtle in vscode webview
In VSCode Webview, window.crypto.subtle
not working.
The possible reason is (from MDN):
This feature is available only in secure contexts (HTTPS)
And in VSCode Webview, the window.location.protocal
is data:
So, it has a polyfill to resolve this?
PS: I have tried some lib(eg webcrypto-liner, webcrypto-shim), none of them working.
Solution 1:[1]
I haven't tested your exact same case but I was facing a similar issue. I wanted to use https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID, which has the same restriction
This feature is available only in secure contexts (HTTPS)
I didn't realize it because was accessing a remote server by IP (protocol HTTP), and then realized it testing exposing my own localhost port with ngrok (which hosts over HTTP/HTTPS) and it worked successfully only on HTTPS hosted link.
Hope this helps! :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | BalB |