OLD | NEW |
---|---|
(Empty) | |
1 // This should be accessed only in the install event or the message event. When | |
2 // this is false, it implies that this service worker is restarted after the | |
3 // install event. | |
4 let run_install_event = false; | |
falken
2017/02/08 05:01:54
nit: maybe did_install or did_run_install_event is
nhiroki
2017/02/09 05:11:32
Done.
| |
5 | |
6 self.addEventListener('install', e => { | |
7 var scope = new URL(self.registration.scope); | |
8 if (scope.searchParams.get('type') == 'features-during-install') { | |
9 internals.countFeature(scope.searchParams.get('feature')); | |
10 internals.countDeprecation(scope.searchParams.get('deprecated')); | |
11 } else if (scope.searchParams.get('type') == 'skip-waiting') { | |
12 e.waitUntil(self.skipWaiting()); | |
13 } | |
14 run_install_event = true; | |
15 }); | |
16 | |
17 onmessage = e => { | |
18 if (e.data.type == 'COUNT_FEATURE') { | |
19 internals.countFeature(e.data.feature); | |
20 e.source.postMessage({type: 'COUNTED'}); | |
21 } else if (e.data.type == 'COUNT_DEPRECATION') { | |
22 internals.countDeprecation(e.data.feature); | |
23 e.source.postMessage({type: 'COUNTED'}); | |
24 } else if (e.data.type == 'CLAIM') { | |
25 let promise = self.clients.claim() | |
26 .then(() => e.source.postMessage( | |
27 {type: 'CLAIMED', restarted: !run_install_event})); | |
28 e.waitUntil(promise); | |
29 } | |
30 }; | |
OLD | NEW |