{"action":"created","issue":{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/677","labels_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/677/labels{/name}","comments_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/677/comments","events_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/677/events","html_url":"https://github.com/slightlyoff/ServiceWorker/issues/677","id":67587627,"number":677,"title":"Client.postMessage should return a Promise","user":{"login":"johnmellor","id":563043,"avatar_url":"https://avatars.githubusercontent.com/u/563043?v=3","gravatar_id":"","url":"https://api.github.com/users/johnmellor","html_url":"https://github.com/johnmellor","followers_url":"https://api.github.com/users/johnmellor/followers","following_url":"https://api.github.com/users/johnmellor/following{/other_user}","gists_url":"https://api.github.com/users/johnmellor/gists{/gist_id}","starred_url":"https://api.github.com/users/johnmellor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnmellor/subscriptions","organizations_url":"https://api.github.com/users/johnmellor/orgs","repos_url":"https://api.github.com/users/johnmellor/repos","events_url":"https://api.github.com/users/johnmellor/events{/privacy}","received_events_url":"https://api.github.com/users/johnmellor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-10T12:47:18Z","updated_at":"2015-04-14T07:18:08Z","closed_at":null,"body":"[Client.postMessage](https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#client-postmessage-method) can fail for various reasons, for example:\r\n\r\n- user or JS closed the tab\r\n- user or JS navigated* the tab to a non-same-origin URL\r\n- tab is still open, but browser evicted it from RAM\r\n\r\nAs suggested in https://github.com/slightlyoff/ServiceWorker/issues/609#issuecomment-74920652 and https://github.com/slightlyoff/ServiceWorker/issues/626#issuecomment-74918907, it would be useful if Client.postMessage returned a Promise that would be resolved once the message event has been fired on the client, or rejected if the client ceases to exist before the message event can be fired.\r\n\r\nExample use case [from](https://github.com/slightlyoff/ServiceWorker/issues/609#issuecomment-74920652) @jakearchibald:\r\n> After a push message, a SW may find a focused & visible client and post a message to it, but that fails because the tab has since been closed. Developers should be able to catch that case and show a notification instead.\r\n\r\n@annevk [is concerned](https://github.com/slightlyoff/ServiceWorker/issues/609#issuecomment-75936104) that this would expose GC, but it remains unclear why it's bad for JS to be able to tell which tabs are still open/alive - especially since this can already be achieved by polling. So far, these concerns don't seem to outweigh the utility of the use case above.\r\n\r\n*: some browsers have a back-forward cache (a.k.a. fastback) feature like https://wiki.mozilla.org/DocShell:Fastback - in such cases navigation doesn't destroy a client, it merely pauses all timers. In such cases where timers are paused, I guess the promise should neither resolve nor reject, but instead wait until the timers are resumed (e.g. because the user returns to the cached page) or the client ceases to exist (e.g. because the client is evicted from the back-forward cache)."},"comment":{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/comments/92671425","html_url":"https://github.com/slightlyoff/ServiceWorker/issues/677#issuecomment-92671425","issue_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/677","id":92671425,"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-04-14T07:18:08Z","updated_at":"2015-04-14T07:18:08Z","body":"Apologies to have closed #609 without this issue being addressed.\r\n\r\nSo the use case is clear, but I'm a bit unclear about how to spec this bit:\r\n> tab is still open, but browser evicted it from RAM\r\n\r\neven after having gone through #626. Some kind of \"Note\" will do for it?"}}