{"action":"created","issue":{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/609","labels_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/609/labels{/name}","comments_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/609/comments","events_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/609/events","html_url":"https://github.com/slightlyoff/ServiceWorker/issues/609","id":54919967,"number":609,"title":"Clients & postMessage","user":{"login":"jakearchibald","id":93594,"avatar_url":"https://avatars.githubusercontent.com/u/93594?v=3","gravatar_id":"","url":"https://api.github.com/users/jakearchibald","html_url":"https://github.com/jakearchibald","followers_url":"https://api.github.com/users/jakearchibald/followers","following_url":"https://api.github.com/users/jakearchibald/following{/other_user}","gists_url":"https://api.github.com/users/jakearchibald/gists{/gist_id}","starred_url":"https://api.github.com/users/jakearchibald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakearchibald/subscriptions","organizations_url":"https://api.github.com/users/jakearchibald/orgs","repos_url":"https://api.github.com/users/jakearchibald/repos","events_url":"https://api.github.com/users/jakearchibald/events{/privacy}","received_events_url":"https://api.github.com/users/jakearchibald/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":34,"created_at":"2015-01-20T18:25:23Z","updated_at":"2015-02-25T09:48:52Z","closed_at":null,"body":"A client can message a particular ServiceWorker via:\r\n\r\n```js\r\nnavigator.serviceWorker.controller.postMessage(\"Hello\");\r\n```\r\n\r\nI 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`.\r\n\r\nIn 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.\r\n\r\nSo yeah, if a ServiceWorker sends a client a message, where does it land?\r\n\r\nWe 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."},"comment":{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/comments/75932699","html_url":"https://github.com/slightlyoff/ServiceWorker/issues/609#issuecomment-75932699","issue_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/609","id":75932699,"user":{"login":"jungkees","id":1331169,"avatar_url":"https://avatars.githubusercontent.com/u/1331169?v=3","gravatar_id":"","url":"https://api.github.com/users/jungkees","html_url":"https://github.com/jungkees","followers_url":"https://api.github.com/users/jungkees/followers","following_url":"https://api.github.com/users/jungkees/following{/other_user}","gists_url":"https://api.github.com/users/jungkees/gists{/gist_id}","starred_url":"https://api.github.com/users/jungkees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jungkees/subscriptions","organizations_url":"https://api.github.com/users/jungkees/orgs","repos_url":"https://api.github.com/users/jungkees/repos","events_url":"https://api.github.com/users/jungkees/events{/privacy}","received_events_url":"https://api.github.com/users/jungkees/received_events","type":"User","site_admin":false},"created_at":"2015-02-25T09:48:52Z","updated_at":"2015-02-25T09:48:52Z","body":"@jakearchibald In case of the uncontrolled clients gotten from `self.clients.matchAll({ includeUncontrolled: true })`, client.postMessage should still land in the service worker client's global.navigator.serviceWorker.onmessage as long as the ServiceWorkerContainer object exists. Are we on the same page?"}}