diff --git a/islands/RegisterServiceWorker.tsx b/islands/RegisterServiceWorker.tsx index c4b237c..df34f52 100644 --- a/islands/RegisterServiceWorker.tsx +++ b/islands/RegisterServiceWorker.tsx @@ -17,7 +17,7 @@ export default function RegisterServiceWorker() { // }) // }) - const subscription = await (async () => { + async function getSubscription() { const currentSubscription = await registration.pushManager .getSubscription() if (currentSubscription) return currentSubscription @@ -31,9 +31,14 @@ export default function RegisterServiceWorker() { userVisibleOnly: true, applicationServerKey, }) - })() + } - await requestApi('webpush/subscription', 'POST', subscription) + try { + const subscription = await getSubscription() + await requestApi('webpush/subscription', 'POST', subscription) + } catch (cause) { + console.error('Push subscription is not available', { cause }) + } }) }