/** * Correlation ids for iframe postMessage. `crypto.randomUUID` is Safari * 15.4+ / Chrome 92+; `getRandomValues` covers the SDK's older floor. */ export function randomRequestId(): string { const cryptoObj = globalThis.crypto; if (typeof cryptoObj?.randomUUID === "function") { return cryptoObj.randomUUID(); } const bytes = new Uint8Array(16); if (typeof cryptoObj?.getRandomValues === "function") { cryptoObj.getRandomValues(bytes); } else { for (let i = 0; i < 16; i++) { bytes[i] = Math.floor(Math.random() * 256); } } const version = bytes[6] ?? 0; const variant = bytes[8] ?? 0; bytes[6] = (version & 0x0f) | 0x40; bytes[8] = (variant & 0x3f) | 0x80; const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"), ).join(""); return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`; }