[ServiceWorker] Clients & postMessage (#609)

A client can message a particular ServiceWorker via:

```js
navigator.serviceWorker.controller.postMessage("Hello");
```

I guess `messageEvent.source` would be a client, but where `client.postMessage` goes isn't properly defined. This is also a problem for clients created by `clients.getAll`.

In my ignorance, I thought `client.postMessage` would go to `global.onmessage`, but `SharedWorker` doesn't have that, and I hadn't really appreciated that `window.onmessage` was only for window-to-window communication.

So yeah, if a ServiceWorker sends a client a message, where does it land?

We could have `navigator.serviceWorker.onmessage` as the target for messages from a SW to this specific client, where `messageEvent.source` is an instance of `ServiceWorker`, allowing state inspection & `postMessage` back.

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/609

Received on Tuesday, 20 January 2015 18:25:57 UTC