How to test pushsubscriptionchange test code?

The event is pushsubscriptionchangetriggered by the browser when the push notification server wants the client to re-sign. How can I manually fire this event for testing?

+4
source share
2 answers

Unfortunately, it is not possible to perform any end-to-end testing of this feature. The best you can do is to fire the event through JS from a service worker:

function triggerSubscriptionChange() {
  registration.pushManager.getSubscription().then(subscription => {
    if (subscription) {
      console.log("subscribed, subscription", subscription);
      return subscription.unsubscribe();
    }
  }).then(() => {
    console.log("unsubscribed");
    return registration.pushManager.subscribe({
      userVisibleOnly: true
    });
  }).then(subscription => {
    console.log("subscribed, subscription", subscription);
    self.dispatchEvent(new ExtendableEvent("pushsubscriptionchange"));
  });
}
+3
source

The event also fires when the user removes and re-grants push permission (see https://github.com/w3c/push-api/issues/116 ).

, Firefox , "", "" " ", "".

A pushsubscriptionchange .

pushsubscriptionchange event

+2

All Articles