Notification prompting can only be done from a user gesture.
async function startServiceWorker() { const vapidPublicKey = document.head .querySelector('meta[name="vapid_public_key"]') .getAttribute('content'); await registerServiceWorker(); const subscription = await getPushSubscription(vapidPublicKey); if (!subscription) return; await sendSubscriptionToServer(subscription); }