最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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)

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)

Share Improve this question asked Nov 13, 2017 at 12:04 ColucciniColuccini 7281 gold badge7 silver badges19 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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
});
发布评论

评论列表(0)

  1. 暂无评论