-
Notifications
You must be signed in to change notification settings - Fork 41
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
Expose pushManager on Navigator #368
Conversation
Actually, thinking about this... if an (main thread) origin (i.e., "a site") has a persistent environment settings object, and service worker has its own independently persistent environment-settings object, then we could say that every environment has an associated push subscription (which can be This could work because:
Tying subscription to the environment then that could answer how push subscriptions are associated with execution contexts. |
Thanks for writing this up Marcos. I'm going to probably step aside on this one and defer to @saschanaz. Both of us are about to go on some leave, so I hope you don't mind if this takes a little while. |
No problem at all. I'll put up a few PRs over xmas and try to keep them small. I talked to Anne about using "environment", but he suggested they are too volatile... so, I'm going to create some kind of persistent "push subscriptions store" instead. That will be just simple store that handles the association between push subscriptions, service workers, and the origin. |
Some early thought:
Perhaps we can associate push manager to storage bottle as Web Locks does for lock managers?: https://w3c.github.io/web-locks/#lock-managers |
</li> | ||
<li>Let |sw| be |registration|'s [=service worker registration/active worker=]. | ||
<li>If |sw| is null and |global| is a {{ServiceWorkerRegistration}}, [=queue a global |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ServiceWorkerGlobalScope?
PushManager is only supported in workers, and this data should be identical to the parent feature. It's not for Safari, and that's wrong, so just remove the entry. Note that it might be available in the window context in the future: w3c/push-api#368
PushManager is only supported in workers, and this data should be identical to the parent feature. It's not for Safari, and that's wrong, so just remove the entry. Note that it might be available in the window context in the future: w3c/push-api#368
I was looking at tackling this but ran into #384. Because #360 actually describes something that I think we can use. It suggests that a "window push subscription" is 1:1 with a push subscription for a service worker registration whose scope is I think we should just create a service worker registration for that scope when none exists and bypass the active worker check (which seems to be there mainly for consistency). An issue that we run into, but the existing specification also runs into, is this line in the Service Workers specification:
But it seems to me it could just as well say that it's being updated in place (or that some state, such as the push subscription, is carried over). This setup has these benefits:
Thoughts? |
@jakearchibald I know it's been a while, but maybe you could have a look at #368 (comment) given your experience with service workers. I'd appreciate it! |
In practice I don't think that sentence in the service worker spec means much. The actual algorithms around registering service workers (i.e. starting with https://w3c.github.io/ServiceWorker/#start-register-algorithm) already update an existing registration in place rather than creating a new one if the scope url matches. If I understand it correctly, I believe you're proposing introducing a service worker registration that doesn't have any service workers associated with it. That does seem a bit odd to me, although I don't think anything would necessarily break by changing that assumption... I think there might be some subtlety about what should happen when a service worker is later registered at that same scope but installation fails (should that unregister the "/" registration as currently spec'ed, or would we want to go back to having a registration without a service worker?). |
Having a Service Worker Registration without an active ServiceWorker feels like it discards a fairly fundamental invariant that may currently be reflected quite deeply into existing browser implementations. (It would not be a minor thing to relax this invariant in Gecko.) Can push subscription storage just be a map from (WindowClient or ServiceWorkerRegistration) to (PushSubscription)? And then we can sprinkle some "Eligible PushSubscription" dust on top for lifetime management of the contents of the map to deal with the fact that browsers have complex session management things going on, especially on resource-constrained devices and where the ServiceWorkers spec has not concretely addressed w3c/ServiceWorker#626. This allows browsers latitude in retaining push subscriptions for WindowClients that aren't currently loaded. Also, this avoids complications with magic treatment of the scope "/" potentially interacting weirdly with the proposal at w3c/ServiceWorker#1512. |
Thanks both for weighing in!
|
The more I think about this the more I'm inclined to stick with a service worker registration as specification device as it just answers so many questions that would otherwise have to be answered in some other way for this rather small scenario. |
I'm confused by this. Are you suggesting that if a window registers a push subscription and the origin did not previously have a service worker registration for the scope "/" then a browser would be equally compliant if getRegistrations() returned or did not return a new registration with scope "/"? |
Thanks. I need to think about the best approach some more. I forgot how web-exposed registrations are. It seems annoying to have to almost duplicate them, but maybe that's the best we can do. |
Maybe:
|
@asutherland I just wanted to belatedly thank you for your suggestion there. I'm pretty close to being able to provide a new take on this PR that implements that. There might still be some hand-waving, but I think it improves upon the status quo. I will create it as a new PR as the approach changed quite a bit, but will cross-link this one. |
This is part of the Declarative Web Push initiative (see #360) and mainly makes sense when that is supported, although could be independently supported in theory. This makes window.pushManager work by making push subscriptions tied to a scope rather than a service worker registration. Most often push subscriptions remain 1:1 with service worker registrations, but the scope whose serialized path is "/" is treated specially from now on and can exist independently. This obsoletes #368.
Closing this in favor of #393. Review appreciated! |
Part of #360
This PR introduces:
pushManager
to distinguish between service worker scope and running in a regular window.Discussion (or stuff I'm not super happy with):
The current spec is currently hand-wavy about how push registrations are persistently associated with a service worker (which is ok), but not it gets a little bit messier because we need to distinguish between the Window object associated registration and the service worker ones.
Anyone got any suggestions as to what I could use to hand the registration off instead?
The following tasks have been completed:
Implementation commitment:
Preview | Diff