==index.html==
Intercept All Requests
Loading...
=== service-worker.js==
let fileMap = {};
self.addEventListener('message', event => {
if (event.data === 'INIT') {
event.ports[0].postMessage('SW_READY');
} else if (event.data.type === 'FILE_MAP') {
fileMap = event.data.fileMap;
}
});
self.addEventListener('fetch', event => {
const url = new URL(event.request.url);
console.log('Intercepted request:', event.request);
if (fileMap[url.pathname]) {
event.respondWith(
Promise.resolve(fileMap[url.pathname]).then(blob => new Response(blob))
);
} else {
event.respondWith(fetch(event.request));
}
});