1self.addEventListener("push", (event) => { 2 event.waitUntil( 3 (async () => { 4 let data = {}; 5 6 /* 7 * Push-Daten lesen 8 */ 9 10 try { 11 if (event.data) { 12 data = event.data.json(); 13 } 14 } catch (error) { 15 console.error("Push JSON Fehler:", error); 16 } 17 18 /* 19 * Badge aktualisieren 20 */ 21 22 const unreadCount = Number(data.unreadCount || 0); 23 24 if (unreadCount > 0 && "setAppBadge" in self.navigator) { 25 try { 26 await self.navigator.setAppBadge(unreadCount); 27 } catch (error) { 28 console.error("Badge konnte nicht gesetzt werden:", error); 29 } 30 } else if (unreadCount === 0 && "clearAppBadge" in self.navigator) { 31 try { 32 await self.navigator.clearAppBadge(); 33 } catch (error) { 34 console.error("Badge konnte nicht gelöscht werden:", error); 35 } 36 } 37 38 /* 39 * Notification anzeigen 40 */ 41 42 await self.registration.showNotification( 43 data.title || "", 44 45 { 46 body: data.body || "", 47 48 icon: "/scripts/web-push/icon.png", 49 50 badge: "/scripts/web-push/badge.png", 51 52 image: data.image || undefined, 53 54 actions: [ 55 { 56 action: "read", 57 58 title: "Artikel jetzt lesen", 59 }, 60 ], 61 62 data: { 63 url: data.url || "", 64 65 articleId: data.articleId || null, 66 }, 67 }, 68 ); 69 })(), 70 ); 71}); 72 73/* 74 * Notification angeklickt 75 */ 76 77self.addEventListener("notificationclick", (event) => { 78 event.notification.close(); 79 80 const url = event.notification.data?.url; 81 82 if (!url) { 83 return; 84 } 85 86 event.waitUntil(clients.openWindow(url)); 87});
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.