Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async cachedResponseWillBeUsed({cachedResponse, event, request}) {
// Check `event.request` instead of `request` since the latter is a
// code-generated request for the content partial and is not a
// navigation request.
if (event && event.request && event.request.mode === 'navigate') {
const {resultingClientId} = event;
// Don't await this promise (otherwise it would delay the response).
resultingClientExists(resultingClientId).then(async (resultingClient) => {
// Give browsers that don't implement `resultingClientId`` a bit of time
// for the JS to load, since it's likely they also don't implement
// `postMessage()` buffering.
if (!resultingClient) {
await sleep(3000);
}
messageWindows({
type: 'NAVIGATION_REPORT',
payload: {
url: event.request.url,
cacheHit: Boolean(cachedResponse),
},
});
});
}