1self.addEventListener("push", (event) => { 2 event.waitUntil( 3 (async () => { 4 try { 5 const data = event.data.json(); 6 7 if (!(self.Notification && self.Notification.permission === 'granted')) { 8 return; 9 } 10 11 await fetch(data.extra.url_track_view); 12 13 await self.registration.showNotification(data.title, { 14 body: data.body, 15 data: { 16 url: data.extra.url_to_open 17 }, 18 icon: data.icon, 19 image: data.image, 20 requireInteraction: data.require_interaction, 21 silent: false 22 }); 23 } catch (e) { 24 console.error(e); 25 } 26 })() 27 ); 28}); 29 30self.addEventListener("notificationclick", (event) => { 31 event.waitUntil( 32 (async () => { 33 const notification = event.notification; 34 const clientList = await clients.matchAll({ type: "window" }); 35 36 for (const client of clientList) { 37 if (client.url === "/" && "focus" in client) { 38 client.focus(); 39 notification.close(); 40 return; 41 } 42 } 43 44 if (clients.openWindow) { 45 clients.openWindow(notification.data.url); 46 notification.close(); 47 return; 48 } 49 })() 50 ); 51}); 52 53self.addEventListener('pushsubscriptionchange', (event) => { 54 event.waitUntil( 55 (async () => { 56 try { 57 await fetch('https://api.webpush.click/subscribe', { 58 method: 'PUT', 59 headers: { 'Content-Type': 'application/json' }, 60 body: JSON.stringify({ 61 expired: event.oldSubscription ? event.oldSubscription.endpoint : null, 62 endpoint: event.newSubscription ? event.newSubscription.endpoint : null, 63 p256dh: event.newSubscription ? event.newSubscription.toJSON().keys.p256dh : null, 64 auth: event.newSubscription ? event.newSubscription.toJSON().keys.auth : null 65 }) 66 }); 67 } catch (e) { 68 console.error('Error updating subscription:', e); 69 } 70 })() 71 ); 72});
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.