diff --git a/src/lib/appServiceWorker.ts b/src/lib/appServiceWorker.ts index e9f3af8..307cbf9 100644 --- a/src/lib/appServiceWorker.ts +++ b/src/lib/appServiceWorker.ts @@ -12,17 +12,24 @@ let started = false; export function registerAppServiceWorker(): void { if (started || typeof window === 'undefined' || !('serviceWorker' in navigator)) return; if (Capacitor.isNativePlatform()) { - // The native shell must never inherit an old web app-shell worker. - if ('serviceWorker' in navigator) { - void navigator.serviceWorker.getRegistrations() - .then((regs) => regs.forEach((reg) => { try { reg.unregister(); } catch { /* ignore */ } })) - .catch(() => undefined); - } - if (typeof caches !== 'undefined') { - void caches.keys() - .then((keys) => keys.filter((key) => key.startsWith('skate-spots-shell-')) - .forEach((key) => { void caches.delete(key).catch(() => undefined); })) - .catch(() => undefined); + // The native shell must never inherit an old web app-shell worker. Some + // Android WebViews expose a partial/absent Service Worker API, so every + // call is feature-checked and wrapped — this cleanup must never abort React + // boot (that produced a black screen after the native splash). + try { + if (navigator.serviceWorker && typeof navigator.serviceWorker.getRegistrations === 'function') { + void navigator.serviceWorker.getRegistrations() + .then((regs) => regs.forEach((reg) => { try { reg.unregister(); } catch { /* ignore */ } })) + .catch(() => undefined); + } + if (typeof caches !== 'undefined' && typeof caches.keys === 'function') { + void caches.keys() + .then((keys) => keys.filter((key) => key.startsWith('skate-spots-shell-')) + .forEach((key) => { void caches.delete(key).catch(() => undefined); })) + .catch(() => undefined); + } + } catch { + // Best-effort only; boot must continue. } return; }