Prashant Agrawal
Prashant Agrawal

Reputation: 670

Is there any callback on permission change for web push notification?

Let say a user set permission to allow for receiving push notification but later changed those permissions to denied or default .

Is there some callback for this exposed in Serviceworker.

Upvotes: 3

Views: 2435

Answers (1)

Jeff Posnick
Jeff Posnick

Reputation: 56064

There's no event that's exposed to the service worker.

There's an event that you could listen for from the context of pages, via the Permissions API:

navigator.permissions.query({name: 'notifications'}).then(function(permission) {  
  // Initial status is available at permission.state

  permission.onchange = function() {  
    // Whenever there's a change, updated status is available at this.state
  };
});

Upvotes: 13

Related Questions