DOMException:注册失败-权限被拒绝 [英] DOMException: Registration failed - permission denied

查看:724
本文介绍了DOMException:注册失败-权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正常运行的Web通知脚本.但是,当我在chrome版本43中进行测试时,出现错误"DOMException:注册失败-权限被拒绝".在订阅阶段会发生此错误.

I have a web notification script which works fine. However when i was testing in chrome version 43, I get the error "DOMException: Registration failed - permission denied". This error occurs during the subscription stage.

这是通常的注册过程的代码段

Here's the code snippet which is the usual process of registration

navigator.serviceWorker.register('sw.js').then(function(reg) {
    console.log('[ServiceWorker] Registration Obj', reg);
    reg.pushManager.subscribe({
        userVisibleOnly: true
    }).then(function(sub) {
        //This never executes and catch gets called
        console.log('Subscription successful, Subscription endpoint:', sub.endpoint);
    }).catch(function(error) {
        console.log("Error during subscription ", error);
    });
}).catch(function(error) {
    if (Notification.permission === 'denied') {
        console.warn('Permission for Notifications was denied');
    } else {
        console.error('Unable to subscribe to push.', error);
    }
});

在上面的代码中,我执行reg.pushManager.subscribe()的步骤期间发生了错误.

In the above code, the error occurs during the step where i do reg.pushManager.subscribe().

  • 在Chrome 49中不会发生这种情况.
  • 此错误始终在chrome 43版上发生.

[注意]我假设它是chrome版本43的一个普遍问题,但是当我检查goroost.com和pushcrew之类的网站时,它们似乎工作正常.仅有我的不工作

推荐答案

我遇到了此问题. 除了prajnavantha答案之外,这还可能是由于浏览器通知是否被阻止而意外单击导致的. 要在Chrome中修复此问题,请转到设置"->单击显示高级设置"->隐私"下,单击内容设置"->然后在通知"下选择管理例外项".进入这里后,允许通知受影响的URL.

I've encountered this problem. in addition to prajnavantha answers, this may be caused by accidentally clicking the browser notification when it block it or not. To fix this in Chrome, go to Settings->click 'Show Advanced Settings'->Under 'Privacy' click 'Content Settings'->Then under 'Notifications' select 'Manage Excpetions'. Once you're in here, allow the notification for the URL affected.

这篇关于DOMException:注册失败-权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆