1self.addEventListener('push', function (event) { 2 if (!(self.Notification && self.Notification.permission === 'granted')) { 3 return; 4 } 5 6 var data = {}; 7 8 // Get data from notification 9 if (event.data) { 10 data = event.data.json(); 11 } 12 13 var title = data.Title; 14 var message = data.Message; 15 var icon = data.Icon; 16 var link = data.Link; 17 18 // Show received notification 19 event.waitUntil(self.registration.showNotification(title, { 20 body: message, 21 icon: icon, 22 badge: icon, 23 data: { url: link } 24 })); 25}); 26 27self.addEventListener('notificationclick', function (event) { 28 var data = ""; 29 if (event.notification.data) { 30 data = event.notification.data; 31 } 32 var url = data.url; 33 if (url) { 34 event.waitUntil( 35 clients.matchAll({ type: 'window' }).then(windowClients => { 36 // Check if there is already a window/tab open with the target URL 37 for (var i = 0; i < windowClients.length; i++) { 38 var client = windowClients[i]; 39 // If so, just focus it. 40 if (client.url === url && 'focus' in client) { 41 return client.focus(); 42 } 43 } 44 // If not, then open the target URL in a new window/tab. 45 if (clients.openWindow) { 46 return clients.openWindow(url); 47 } 48 }) 49 ); 50 } 51})
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.