-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client.postMessage should return a Promise #677
Comments
As an implementer I'd rather that this just failed. We can't even guarantee that the SW itself will stay alive by the time the page is restored. |
Tracked in crbug.com/461416 but needs spec decision. |
@jungkees if we expose evicted clients, I think they should be another type that doesn't have |
@annevk would it be wrong to make this return a promise given it doesn't elsewhere on the platform? |
Setting this as v1, as we can't go from a method that throws to one that returns a promise, so this needs deciding soon. |
How can you figure things out by polling without the other side cooperating? |
I used I would prefer the
|
F2F: it isn't worth changing this one instance of |
Yo: https://github.com/nolanlawson/promise-worker 😃 Not saying this solves every use case (e.g. it can't send ArrayBuffers or raw JSON), but I think it demonstrates this is indeed pretty easy to solve in userland. |
Client.postMessage can fail for various reasons, for example:
As suggested in #609 (comment) and #626 (comment), 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.
Example use case from @jakearchibald:
@annevk is concerned 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.
*: 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).
The text was updated successfully, but these errors were encountered: