From 4c97c578bbf9c0082cf4c8452dee9bca5d65b90f Mon Sep 17 00:00:00 2001 From: Jose Olarte III Date: Wed, 13 May 2026 20:57:14 +0800 Subject: [PATCH] fix(notifications): fall back when crypto.randomUUID is missing If randomUUID is unavailable (older WebViews), generate a one-time ID with Date.now + random segment, log a single DeviceId warning, and persist it as before so registration still works. --- src/services/notifications/deviceId.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/services/notifications/deviceId.ts b/src/services/notifications/deviceId.ts index 4efe4772..ffe17c39 100644 --- a/src/services/notifications/deviceId.ts +++ b/src/services/notifications/deviceId.ts @@ -3,7 +3,16 @@ import { Preferences } from "@capacitor/preferences"; const DEVICE_ID_KEY = "stable_device_id"; function generateDeviceId(): string { - return crypto.randomUUID(); + if (typeof crypto !== "undefined" && crypto.randomUUID) { + return crypto.randomUUID(); + } + + // eslint-disable-next-line no-console + console.warn( + "[DeviceId] crypto.randomUUID unavailable, using fallback generator", + ); + + return `${Date.now()}-${Math.random().toString(36).slice(2)}`; } export async function getOrCreateDeviceId(): Promise {