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

Javascript error: crypto.randomUUID is not a function #2866

Closed
alexzaech opened this issue Apr 10, 2024 · 5 comments
Closed

Javascript error: crypto.randomUUID is not a function #2866

alexzaech opened this issue Apr 10, 2024 · 5 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@alexzaech
Copy link
Sponsor

Description

Description

When accessing NiceGUI other than using localhost address, the browser JS console shows TypeError: crypto.randomUUID is not a function (nicegui.js:339). UI elements are rendered correctly, but no callback seems to work.

Minimal example to reproduce the issue:

from nicegui import ui

@ui.page("/")
async def home():
    ui.button("Test me", on_click=lambda: ui.notify("Hello, world!"))

if __name__ in {"__main__", "__mp_main__"}:
    ui.run()

Open browser dev tools console to see the error message.

This issue occurs with the latest code from GitHub main branch but NOT with release version 1.4.20.

@falkoschindler
Copy link
Contributor

Oh wow, thanks for spotting this, @alexzaech!
This line has been added in PR #2837. We'll look into it.

@falkoschindler falkoschindler added the bug Something isn't working label Apr 10, 2024
@falkoschindler falkoschindler added this to the 1.4.21 milestone Apr 10, 2024
@rodja
Copy link
Member

rodja commented Apr 10, 2024

Interesting. crypto.randomUUID is only available locally or when serving https: https://stackoverflow.com/a/2117523/364388. I think we should try to use crypto.randomUUID and if it fails we should fall back to a custom uuid generation function (like the one from the StackOverflow answer).

@alexzaech
Copy link
Sponsor Author

alexzaech commented Apr 10, 2024

Thanks @rodja, using it via HTTPS works. Quickly tested as documented here https://www.uvicorn.org/deployment/#running-with-https using self-signed certs created with mkcert

@falkoschindler
Copy link
Contributor

I think I fixed it by adding a fallback function: ed298d7
@alexzaech Do you want to give it a try? 🙂

@alexzaech
Copy link
Sponsor Author

Hi @falkoschindler!

looks like it works. Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants