Why Does My Embeddable Throw Crypto Errors When Running on a Custom Local Domain?

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.

  1. Go to chrome://flags/#unsafely-treat-insecure-origin-as-secure.
  2. Add the origin which you want to treat as secure i.e., http://example.com:8080.
  3. Relaunch Chrome.
  4. Verify by visiting http://example.com:8080 and typing crypto.subtle in the DevTools Console.