Re: [w3c/ServiceWorker] thoughts on exposing multiple-instances to sites via the DOM (#1185)

If we added multiple instances today, you could still ensure you were conversing with a specific service worker by either passing a message port with the initial message:

```js
// In the service worker:
const channel = new MessageChannel();
client.postMessage({useThisForReplies: channel.port2}, [channel.port2]);

// In the page:
navigator.serviceWorker.onmessage = event => {
  if (event.data.useThisForReplies) {
    event.data.useThisForReplies.postMessage(…);
  }
};
```

Alternatively `useThisForReplies` could be a random broadcast channel ID.

(this doesn't mean we shouldn't do one of the things @wanderview suggests above, it just hadn't previously occurred to me that there are kinda solutions already)

-- 
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/1185#issuecomment-322864908

Received on Wednesday, 16 August 2017 18:50:26 UTC