blob: 9dc00024d519b20808b6d68a1d6cb64536599d2a [file] [log] [blame]
oninstall = (event) => {
if (self.port)
return;
event.waitUntil(new Promise(resolve => self.installingPromiseResolve = resolve));
}
onmessage = (event) => {
if (event.data.port)
self.port = event.data.port;
if (self.installingPromiseResolve) {
self.installingPromiseResolve();
self.installingPromiseResolve = null;
}
if (self.fetchingPromiseResolve) {
self.fetchingPromiseResolve();
self.fetchingPromiseResolve = null;
}
};
onactivate = (event) => {
self.port.postMessage("activating");
}
self.addEventListener('fetch', (event) => {
self.port.postMessage("fetching");
const promise = new Promise(resolve => self.fetchingPromiseResolve = resolve);
event.respondWith(promise.then(async () => {
if (!event.preloadResponse)
return new Response("FAIL: preload not enabled");
const response = await event.preloadResponse;
if (!response)
return new Response("FAIL: no preload response");
return response;
}));
});