// public/sw.js self.addEventListener("push", (event) => { if (!event.data) return; try { const data = event.data.json(); const title = data.title || "New Notification"; const options = { body: data.body, icon: data.icon || "/icon-192.png" // badge: data.badge || "/badge-72x72.png", // data: data.data || {}, }; event.waitUntil( self.registration.showNotification(title, options) ); } catch (err) { console.error("Push event error:", err); } }); self.addEventListener("notificationclick", (event) => { event.notification.close(); // If you send a `url` in payload.data, open it const url = event.notification.data?.url; if (url) { event.waitUntil(clients.openWindow(url)); } });