Chrome 将 Notification.requestPermission() 的“default”结果视​​为“dennied”

当用户第三次关闭权限对话框时,Chrome 会自动将权限设置为deniedautomatically blocked在导航栏的权限弹出窗口中显示以下消息)。因此,用户关闭对话框的前三次default结果是,但第三次将权限设置为denied

我用来处理这个逻辑的方式是:

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
});

 

posted @ 2022-11-14 13:12  唯一客服系统开发笔记  阅读(150)  评论(0编辑  收藏  举报