blob: 92a96ff88fb903748aebf6d6a0efaeb529c7ad39 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
var activatePromiseResolve;
addEventListener('activate', function(evt) {
evt.waitUntil(new Promise(function(resolve) {
activatePromiseResolve = resolve;
}));
});
addEventListener('message', async function(evt) {
switch (evt.data) {
case 'CLAIM':
evt.waitUntil(new Promise(async resolve => {
await clients.claim();
evt.source.postMessage('CLAIMED');
resolve();
}));
break;
case 'ACTIVATE':
if (typeof activatePromiseResolve !== 'function') {
throw new Error('Not activating!');
}
activatePromiseResolve();
break;
default:
throw new Error('Unknown message!');
}
});
addEventListener('fetch', function(evt) {
evt.respondWith(new Response('Hello world'));
});
|