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 did_run_install_event = false; |
| 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 did_run_install_event = true; |
| 15 }); |
| 16 |
| 17 onmessage = e => { |
| 18 if (e.data.type == 'COUNT_FEATURE') { |
| 19 internals.countFeature(e.data.feature); |
| 20 } else if (e.data.type == 'COUNT_DEPRECATION') { |
| 21 internals.countDeprecation(e.data.feature); |
| 22 } else if (e.data.type == 'CLAIM') { |
| 23 let promise = self.clients.claim() |
| 24 .then(() => e.source.postMessage( |
| 25 {type: 'CLAIMED', restarted: !did_run_install_event})); |
| 26 e.waitUntil(promise); |
| 27 } else if (e.data.type == 'PING') { |
| 28 e.source.postMessage({type: 'PONG'}); |
| 29 } |
| 30 }; |
OLD | NEW |