Google推送通知 - DOMException:注册失败 - 权限被拒绝

时间:2016-08-05 07:16:55

标签: push-notification google-cloud-messaging

我跟随(getting started with push locations guide),但在第6步遇到错误:

undefined:1 Uncaught (in promise) DOMException: Registration failed - permission denied

我的manifest.json文件正在根据“网络”标签正确加载。

我已将正确的项目编号输入manifest.json。我尝试添加指南中未提及的其他设置:

{
  "name": "Push Notifications codelab",
  "gcm_sender_id": "123456789",
  "gcm_user_visible_only": true,
  "permissions": [
    "gcm"
  ]
}

我按照指南在localhost上运行我的服务器。

3 个答案:

答案 0 :(得分:7)

如果您使用的是Brave(浏览器),并且遇到相同的问题,则必须在设置中启用 Use Google Services for Push Messaging

为了启用它:

Brave settings > Privacy and Security > Use Google Services for Push Messaging

或使用brave://settings/privacy快捷方式。

答案 1 :(得分:2)

我的问题实际上是在我的Chrome设置中。在内容设置下,通知设置为不允许任何网站显示通知。将此设置更改为询问网站何时显示通知为我解决了问题。

答案 2 :(得分:0)

无法执行操作时出现

DOMException,原因可能是逻辑原因,数据丢失,或者实现变得不稳定。您收到错误 DOMException:注册失败 - 权限被拒绝可能是因为清单是从与主页面不同的域加载的。如果您的网页不在网站的根目录,请从thread建议使用<link rel="manifest" href="/manifest.json">。您还可以查看此related SO question

相关问题