1self.addEventListener("install", () => { 2 self.skipWaiting(); 3}); 4 5self.addEventListener("activate", (event) => { 6 event.waitUntil(clients.claim()); 7}); 8 9self.addEventListener("notificationclick", (event) => { 10 event.notification.close(); 11 12 const targetUrl = new URL( 13 event.notification.data?.url || "/", 14 self.location.origin, 15 ).href; 16 17 event.waitUntil( 18 clients 19 .matchAll({ 20 type: "window", 21 includeUncontrolled: true, 22 }) 23 .then(async (windowClients) => { 24 const targetClient = windowClients.find( 25 (client) => client.url === targetUrl, 26 ); 27 if (targetClient) { 28 return targetClient.focus(); 29 } 30 31 const siteClient = windowClients[0]; 32 if (siteClient) { 33 try { 34 const navigatedClient = await siteClient.navigate(targetUrl); 35 return (navigatedClient || siteClient).focus(); 36 } catch (error) { 37 console.warn("Cannot reuse the existing window, open a new window instead.", error); 38 } 39 } 40 41 return clients.openWindow(targetUrl); 42 }), 43 ); 44});
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.