opencode/packages/app/src/utils/uuid.ts
Adam 81ca2df6ad
fix(app): guard randomUUID in insecure browser contexts (#13237)
Co-authored-by: Selim <31136147+selimerunkut@users.noreply.github.com>
2026-02-12 01:05:15 +00:00

12 lines
359 B
TypeScript

const fallback = () => Math.random().toString(16).slice(2)
export function uuid() {
const c = globalThis.crypto
if (!c || typeof c.randomUUID !== "function") return fallback()
if (typeof globalThis.isSecureContext === "boolean" && !globalThis.isSecureContext) return fallback()
try {
return c.randomUUID()
} catch {
return fallback()
}
}