service-worker-helper.js (775B)
1 "use strict"; 2 3 // Service workers, once activated, will use 'clients.claim()' 4 // so that clients loaded in the same scope do not need to be reloaded 5 // before their fetches will go through this service worker. 6 // (https://developer.mozilla.org/en-US/docs/Web/API/Clients/claim) 7 self.addEventListener("activate", (event) => { 8 event.waitUntil(clients.claim()); 9 }); 10 11 // The service worker intercepts fetch calls and posts a message with the url to the 12 // 'requests-test' broadcast channel, which the test should be listening for. 13 self.addEventListener('fetch', (event) => { 14 const requestChannel = new BroadcastChannel('requests-test'); 15 var url = event.request.url; 16 17 requestChannel.postMessage({ 18 url: url, 19 message: "Service worker saw this URL: " + url 20 }); 21 });