diff --git a/src/components/SidePanel.tsx b/src/components/SidePanel.tsx index c2756d1..a606e40 100644 --- a/src/components/SidePanel.tsx +++ b/src/components/SidePanel.tsx @@ -593,7 +593,12 @@ function OcrPanel() { <>
{tr('ข้อความที่อ่านได้', 'Recognised text')}
- + > )} diff --git a/src/lib/util.ts b/src/lib/util.ts index 1c59eff..fcf69b3 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -1,7 +1,15 @@ import type { Pending } from './types'; import { tr } from '../i18n'; -export const uid = () => crypto.randomUUID(); +// crypto.randomUUID only exists in secure contexts (HTTPS/localhost); fall back to getRandomValues elsewhere. +export const uid = (): string => { + if (typeof crypto.randomUUID === 'function') return crypto.randomUUID(); + const b = crypto.getRandomValues(new Uint8Array(16)); + b[6] = (b[6] & 0x0f) | 0x40; + b[8] = (b[8] & 0x3f) | 0x80; + const h = Array.from(b, (x) => x.toString(16).padStart(2, '0')).join(''); + return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`; +}; export function download(data: Blob | Uint8Array, name: string, type = 'application/pdf') { const blob = data instanceof Blob ? data : new Blob([data as BlobPart], { type });