Coluccini
Coluccini

Reputation: 718

Chrome treats 'default' result from Notification.requestPermission() as 'denied'

The Notification.requestPermission() has 3 possible results: granted, denied and default.

In Chrome you get default when the user close the permission dialog using the X instead of explicitly saying block. But, if after getting default as result, you call Notification.permission you get denied, making impossible to retry asking permission again in the future.

It this by design? is there a way to make chrome treating differently this two results? Firefox treats this in the right way (you can ask permissions until the user explicitly denied it)

Upvotes: 4

Views: 2333

Answers (1)

Coluccini
Coluccini

Reputation: 718

I'll leave this just in case someone is looking for an answer:

When the user had closed the permission dialog for the third time Chrome will automatically set the permission to denied (it shows a automatically blocked message below on the permission popup from the navbar). So the first three times the user close the dialog you gets default as result, but on the third time the permission are set to denied.

The way I'm using to work with this logic is:

window.Notification.requestPermission().then((result) => {
  if (result === 'denied') {
     // the user has denied permission
     return;
  }

  if (result === 'default') {
    // the user has closed the dialog
    if (window.Notification.permission === 'denied') {
       // the browser has decided to automatically denied permission 
    }
    return;
  }

  // the user has granted permission
});

Upvotes: 8

Related Questions