diff --git a/service-worker.js b/service-worker.js index 0658489..7a381a9 100644 --- a/service-worker.js +++ b/service-worker.js @@ -177,9 +177,11 @@ let decrementActiveFetches = (clientId) => { // (and new fetches will fire in a moment, because a CSS file just // got fetched) or not self.clients.get(clientId).then((client)=>{ - client.postMessage({ - allFetched: true - }) + if (client !== null) { + client.postMessage({ + allFetched: true + }) + } }) .then(()=>{ self.log('service-worker', 'all-fetched message sent.') @@ -255,8 +257,10 @@ let LibResilientResourceInfo = class { self.clients.get(clientId).then((client)=>{ // set the client this.client = client - // Send a message to the client. - this.client.postMessage(this.values); + // Send a message to the client + if (this.client !== null) { + this.client.postMessage(this.values); + } }) } } @@ -287,7 +291,7 @@ let LibResilientResourceInfo = class { }) self.log('service-worker', msg) // send the message to the client - if (this.client && changed) { + if (this.client && changed && (this.client !== null)) { this.client.postMessage(this.values); } } @@ -497,10 +501,12 @@ let getResourceThroughLibResilient = (request, clientId, useStashed=true, doStas // inform! self.log('service-worker', 'fetched version method or ETag differs from stashed for:', url) self.clients.get(reqInfo.clientId).then((client)=>{ - client.postMessage({ - url: url, - fetchedDiffers: true - }) + if (client !== null) { + client.postMessage({ + url: url, + fetchedDiffers: true + }) + } }) } } @@ -582,7 +588,7 @@ self.addEventListener('fetch', event => { // if event.resultingClientId is available, we need to use this // otherwise event.clientId is what we want // ref. https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId - var clientId = event.clientId + var clientId = (event.clientId !== null) ? event.clientId : 'unknown-client' if (event.resultingClientId) { clientId = event.resultingClientId // yeah, we seem to have to send the client their clientId @@ -595,11 +601,13 @@ self.addEventListener('fetch', event => { self.clients .get(clientId) .then((client)=>{ - client.postMessage({ - clientId: clientId, - plugins: self.LibResilientPlugins.filter(p=>(!p.indirect)).map((p)=>{return p.name}), - serviceWorker: 'COMMIT_UNKNOWN' - }) + if (client !== null) { + client.postMessage({ + clientId: clientId, + plugins: self.LibResilientPlugins.filter(p=>(!p.indirect)).map((p)=>{return p.name}), + serviceWorker: 'COMMIT_UNKNOWN' + }) + } }) }