1if ('serviceWorker' in navigator && !window.location.href.includes('/stories/embed')) { 2 window.addEventListener('load', async () => { 3 4 const skipWaitingForWorker = (reg) => { 5 if (reg && reg.waiting) { 6 console.log('Auto-updating: calling skipWaiting()'); 7 console.log('Waiting worker state:', reg.waiting.state); 8 console.log('Sending message to waiting worker:', reg.waiting); 9 reg.waiting.postMessage({ type: 'SKIP_WAITING' }); 10 } else { 11 console.log('No waiting worker found'); 12 reg.postMessage({ action: 'skipWaiting' }); 13 } 14 }; 15 16 const reg = await navigator.serviceWorker.getRegistration(); 17 if (!reg) return; 18 19 if (reg.waiting) { 20 skipWaitingForWorker(reg); 21 } 22 23 reg.addEventListener('updatefound', () => { 24 const newWorker = reg.installing; 25 if (!newWorker) return; 26 27 newWorker.addEventListener('statechange', () => { 28 if (newWorker.state === 'installed' && navigator.serviceWorker.controller) { 29 skipWaitingForWorker(reg); 30 } 31 }); 32 }); 33 34 navigator.serviceWorker.addEventListener( 35 'controllerchange', 36 () => window.location.reload(), 37 { once: true } 38 ); 39 }); 40}
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.