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

Document, polyfill, or make friendlier error message when crypto.subtle is undefined #158

Open
diehuxx opened this issue Jul 19, 2023 · 2 comments

Comments

@diehuxx
Copy link

diehuxx commented Jul 19, 2023

Context: https://discord.com/channels/937858703112155166/1130936915038843021/1131012879810842665

Minimal reproduction: https://github.com/tylerami/react-web5-test

We've had a few people run into this on Discord. The root cause is that crypto.subtle is undefined for http origins. The error message is not the most clear. Might be worth documenting in a README or having a friendlier error message.

@angiejones
Copy link
Member

more context from @diehuxx for those not on Discord:

The error is coming from crypto.subtle being undefined when using browser environments with insecure origin. localhost is treated similar to https in some browsers, which is why most people wouldn't run into the issue at first. It's only when they do local networking that it becomes relevant.

@frankhinek
Copy link
Contributor

We could also potentially check the isSecureContext and throw a more helpful error message.

 if (globalThis.isSecureContext === false) throw new Error('instructive message')

More info: https://developer.mozilla.org/en-US/docs/Web/API/isSecureContext

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

3 participants