1importScripts("https://cdn.moengage.com/webpush/releases/serviceworker_cdn.min.latest.js"); 2 3 4 if ('serviceWorker' in navigator) { 5 if ('serviceWorker' in navigator) { 6 window.addEventListener('load', () => { 7 const swUrl = `/service-worker.js`; // Adjusted to a direct path 8 registerServiceWorker(swUrl); 9 }); 10 } 11 } 12 13 14 function registerValidSW(swUrl) { 15 navigator.serviceWorker 16 .register(swUrl) 17 .then(registration => { 18 registration.onupdatefound = () => { 19 const installingWorker = registration.installing 20 installingWorker.onstatechange = () => { 21 if (installingWorker.state === 'installed') { 22 if (navigator.serviceWorker.controller) { 23 // At this point, the old content will have been purged and 24 // the fresh content will have been added to the cache. 25 // It's the perfect time to display a "New content is 26 // available; please refresh." message in your web app. 27 window.location.reload() 28 } else { 29 // At this point, everything has been precached. 30 // It's the perfect time to display a 31 // "Content is cached for offline use." message. 32 } 33 } 34 } 35 } 36 }) 37 .catch(error => { 38 console.error('Error during service worker registration:', error) 39 }) 40 } 41 42 function registerServiceWorker(swUrl) { 43 navigator.serviceWorker.register(swUrl).then(registration => { 44 registration.onupdatefound = () => { 45 const installingWorker = registration.installing; 46 installingWorker.onstatechange = () => { 47 if (installingWorker.state === 'installed') { 48 if (navigator.serviceWorker.controller) { 49 console.log("New content is available; please refresh to check."); 50 // Optionally prompt the user to reload the page 51 } else { 52 console.log("Content is cached for offline use."); 53 } 54 } 55 }; 56 }; 57 }).catch(error => { 58 console.error('Error during service worker registration:', error); 59 }); 60 } 61 62 63 if ('serviceWorker' in navigator) { 64 navigator.serviceWorker.ready.then(registration => { 65 registration.unregister() 66 }) 67 } 68 69
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.