Created attachment 403573 [details] Simplified repro Sending messages via postMessage to a ServiceWorker does not work from inside an iframe. To repro this, download the attached zip. Serve the files locally. Open from-iframe.html in Safari Go to Develop->Service Workers->localhost Go to Console and notice there are no 'postMessage received:' logs here. If you open from-main-window.html, you will see the postMessage events. This works correctly in FireFox. Chrome has a bug registering ServiceWorkers from iframes so it doesn't make it to the point of postMessage - https://bugs.chromium.org/p/chromium/issues/detail?id=1102209 from-iframe.html: <iframe></iframe> <script> const iframe = document.querySelector('iframe'); iframe.contentDocument.write(` <body> <script> (async () => { document.body.insertAdjacentHTML('beforeend', 'registering service-worker.js<br>'); const reg = await navigator.serviceWorker.register('/service-worker.js'); const sw = reg.installing; sw.postMessage('after register'); sw.onstatechange = () => { document.body.insertAdjacentHTML('beforeend', \`statechange to: \${sw.state}<br>\`); sw.postMessage('statechange to ' + sw.state); }; })(); </${'script'}> </body>`); </script> service-worker.js: console.log('service worker loaded'); addEventListener('message', event => { console.log('postMessage received:', event.data); }); from-main-window.html: <body> <script> (async () => { document.body.insertAdjacentHTML('beforeend', 'registering service-worker.js<br>'); const reg = await navigator.serviceWorker.register('/service-worker.js'); const sw = reg.installing; sw.postMessage('after register'); sw.onstatechange = () => { document.body.insertAdjacentHTML('beforeend', `statechange to: ${sw.state}<br>`); sw.postMessage('statechange to ' + sw.state); }; })(); </script> </body>
<rdar://problem/65203340>
Issue is that the iframe is not registered as a service worker client.
Created attachment 406027 [details] Patch
Created attachment 457601 [details] Patch
Created attachment 457603 [details] Patch
Created attachment 457606 [details] Patch
Created attachment 457618 [details] Patch
Comment on attachment 457618 [details] Patch r=me
The check to reduce service worker client registrations out of http/blob/about is not working with extension schemes. I'll remove it.
Created attachment 457681 [details] Patch for landing
Created attachment 457685 [details] Patch
Committed r292905 (249675@main): <https://commits.webkit.org/249675@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 457685 [details].