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

2022-11-21 15:29:20 浏览数 (1)

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

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

代码语言:javascript复制
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 人点赞