self.addEventListener("push", (event) => { let data = { title: "FOLX TV", body: "Neuer Inhalt verfügbar!", url: "/" }; try { data = event.data.json(); } catch (e) {} event.waitUntil( self.registration.showNotification(data.title, { body: data.body, icon: "/favicon.png", badge: "/favicon.png", data: { url: data.url || "/" }, }) ); }); self.addEventListener("notificationclick", (event) => { event.notification.close(); let url = event.notification.data?.url || "/"; if (!url.startsWith("/") || url.startsWith("//")) url = "/"; event.waitUntil( clients.matchAll({ type: "window", includeUncontrolled: true }).then((clientList) => { for (const client of clientList) { if (client.url.includes(self.location.origin) && "focus" in client) { client.navigate(url); return client.focus(); } } return clients.openWindow(url); }) ); });