当用户第三次关闭权限对话框时,Chrome 会自动将权限设置为denied
(automatically 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
});