今日帮实习生看的一个 bug,踩的小坑,本地局域网真机调试的时候一直会报错 TypeError: crypto.randomUUID is not a function ,localhost 没有,线上也没有,是 web-llm 库用到的。
查到的原因是:
crypto.randomUUID()
是 Web Crypto API 的一部分,仅在安全上下文(HTTPS)下可用。localhost 被视为安全来源,即使没有 HTTPS 也能使用该 API;但对于其他自定义域名,必须启用 HTTPS。像这种情况一般需要解决么(陷入沉思)
StackOverflow | TypeError: crypto.randomUUID is not a function
翻到另外一个:StackOverflow | How do I create a GUID / UUID?
很好,群友说 Next 自带!
https://nextjs.org/docs/app/api-reference/cli/next#using-https-during-development