1// DP Compass â Service Worker for Web Push Notifications 2 3self.addEventListener("push", (event) => { 4 if (!event.data) return; 5 6 let data; 7 try { 8 data = event.data.json(); 9 } catch { 10 data = { title: "DP Compass", body: event.data.text() }; 11 } 12 13 const options = { 14 body: data.body || "", 15 icon: "/icon-192.png", 16 badge: "/icon-192.png", 17 tag: data.tag || "dp-compass-notification", 18 renotify: true, 19 data: { url: data.url || "/" }, 20 }; 21 22 event.waitUntil(self.registration.showNotification(data.title || "DP Compass", options)); 23}); 24 25self.addEventListener("notificationclick", (event) => { 26 event.notification.close(); 27 28 const url = event.notification.data?.url || "/"; 29 30 event.waitUntil( 31 clients.matchAll({ type: "window", includeUncontrolled: true }).then((windowClients) => { 32 // Focus existing tab if open 33 for (const client of windowClients) { 34 if (client.url.includes(self.location.origin) && "focus" in client) { 35 client.navigate(url); 36 return client.focus(); 37 } 38 } 39 // Open new tab 40 return clients.openWindow(url); 41 }) 42 ); 43});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.