- From: Jake Archibald <notifications@github.com>
- Date: Mon, 24 Jun 2019 02:28:05 -0700
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Monday, 24 June 2019 09:28:30 UTC
How about this: HTML: ```html <!DOCTYPE html> <h1>See console</h1> <script> navigator.serviceWorker.register('sw.js').then(reg => { reg.installing.postMessage({ type: 'install-data', value: 'hello!' }); }); </script> ``` sw.js: ```js addEventListener('install', event => { event.waitUntil(async function() { const value = await installData; console.log('Service worker saw data:', value); }()); }); const installData = new Promise(resolve => { addEventListener('message', (event) => { if ('type' in event.data && event.data.type === 'install-data') { resolve(event.data.value); } }); }); ``` Live example: https://static-misc.glitch.me/sw-postmessage-install/ Please reopen if this doesn't help. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/w3c/ServiceWorker/issues/1441#issuecomment-504932932
Received on Monday, 24 June 2019 09:28:30 UTC