w3c / push-api

Push API
https://w3c.github.io/push-api/
Other
145 stars 40 forks source link

Should PushManager.subscribe() return the existing subscription or a new one? #305

Closed collimarco closed 2 years ago

collimarco commented 5 years ago

Chrome and Firefox behave as I expected: if a subscription already exists and you call PushManager.subscribe()they simply return the existing subscription.

This behavior is stated pretty clearly also on MDN:

A new push subscription is created if the current service worker does not have an existing subscription.

However I have found that Opera on Android and Samsung Internet on Android create a new subscription, instead of returning the existing one. Is this a bug?

What is the standard behavior? If a subscription already exists, should PushManager.subscribe() return the existing subscription or a new one?

I have read the standard and found that point 10.5 for subscribe says:

When the request has been completed, resolve promise with subscription.

So if resolving the promise imply an exit from the next steps, then browsers should simply return the existing subscription. Can you confirm?

beverloo commented 5 years ago

Yes, the existing subscription should be returned, and Section 10. of the subscribe() method's algorithm specifies this.

marcoscaceres commented 2 years ago

Closing as answered. The spec mandates that the existing subscription should be returned.