If you’re seeing crypto.randomUUID is not a function
when running on a custom local domain for development purposes (eg using localdev.mysite.com:8080
instead of localhost:8080
), the reason for the error is because browsers only allow use of security functions like Node crypto in either https
or localhost
environments, and don’t recognize custom local domains as localhost. There’s a way to override this in the browser, as mentioned in this Stack Overflow link.
- Go to chrome://flags/#unsafely-treat-insecure-origin-as-secure.
- Add the origin which you want to treat as secure i.e., http://example.com:8080.
- Relaunch Chrome.
- Verify by visiting http://example.com:8080 and typing crypto.subtle in the DevTools Console.