Search code examples
google-chromefirefoxservice-workerweb-pushpush-api

Questions about keeping Service Worker Push Subscriptions In Sync


I've read the push subscription can get out of sync between the browser and the push service.

I've seen two remediations, both look to be non-standard:

  1. ServiceWorkerGlobalScope.onpushsubscriptionchange
  2. GCM send response, mentioned here, spelled out here
    • understandably non-standard

I presume any application should handle both of these points at which a subscription can be identified to be out-of-sync (and any/all).

Questions:

  1. In general, are there always just the two areas an application can be made aware of a subscription out-of-sync situation? (1. service worker event 2. push service response) Seems reasonable, looking for confirmation.
  2. Will the ServiceWorkerGlobalScope.onpushsubscriptionchange event (or some equivalent) make it into the authoritative standard?
  3. In lieu of a service worker event standard, why not just keep the expected subscription endpoint around (in client-side state) and anytime you query the PushManager for the subscription, check if it is out-of-sync (different than expected)?

Solution

  • The pushsubscriptionchange event is documented as part of the Push API specification. That should be considered authoritative, and it mentions there onpushsubscriptionchange is exposed as part of ServiceWorkerGlobalScope.

    I don't know offhand whether pushsubscriptionchange event is fired in all browsers that support the Push API as of this writing, but I believe the general idea is that it's the (eventual) solution to the use case you describe.