-
Notifications
You must be signed in to change notification settings - Fork 1.5k
crypto.randomUUID is not a function
when running locally
#2326
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
Comments
it's either https or expanding even if we did a try catch, our static dependencies are resolved and run before ... we can't intercept errors in there before our code gets even a chance to run P.S. by localhost I literally mean it ... it's not P.S.2 MDN seems to disagree around |
a-ha ... it was documented indeed: https://docs.pyscript.net/2025.3.1/faq/#typeerror-cryptorandomuuid-is-not-a-function |
thank you! I confirm that with I don't know how hard it is (and if it's even possible), but from the "naive user" point of view, I think it would be nice to detect the "non secure environment" case and display a nice error in the DOM, possibly with a link to the FAQ. |
that's the issue ... as soon as any dependency uses features that require https or localhost, which is the norm for modern Web development, we can't intercept those calls so we put a copy and paste error in our docs that explains what's going on but a search in any search engine would reveal the exact same issue (and solution) all over the Web ... in this case In short, static import happens before our code runs, if those throws already, our code won't run. I would close this and maybe think about a way, at least in our stack, to mitigate the issue but I feel like it'd be quite a rewrite and for little gain ... I believe WASM features can be also half/broken in non secured/localhost env 🥲 |
What I was thinking is something like:
|
that cannot work because there are static imports which have absolute priority over the code that is importing ... it doesn't matter if you import after that line, static imports (needed to bundle) are always before anything happening in your module. // a.js
console.log('a');
import './b.js'; // b.js
console.log('b'); when you run if |
sorry if I say nonsense, as you know my JS knowledge is very limited 😅. |
We could have a top module import in core but even the error logic is in another module that could have 3rd party dependencies but I’ll give it a shot and see if that works |
Sounds good to me. Note that these are just my 2 cents, feel free to ignore my suggestions if you think it's low priority. Thanks! |
We could go further and just redirect from 0.0.0.0 to localhost out of the box … even less to do for users, no issues in importing modules that might use trusted APIs … less to learn though, yet convenient? |
I like it :) |
This is the content of my directory:
index.html:
pyscript.toml:
main.py:
I tried to start a local web server:
When opening the browser, the page is completely blank, and devtools shows this:
The same code works fine on pyscript.com:
https://pyscript.com/@antocuni/lingering-sound/latest
The text was updated successfully, but these errors were encountered: