service-worker.js (458B)
1 let promise_func = null; 2 let promise = new Promise(resolve => promise_func = resolve); 3 4 const SERVICE_WORKER_TEST_CHANNEL_NAME = 'service worker'; 5 const bc3 = new BroadcastChannel(SERVICE_WORKER_TEST_CHANNEL_NAME); 6 bc3.onmessage = e => { 7 bc3.postMessage('done'); 8 promise_func(); 9 }; 10 bc3.postMessage('from worker'); 11 12 // Ensure that the worker stays alive for the duration of the test 13 self.addEventListener('install', evt => { 14 evt.waitUntil(promise); 15 });