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

Mar*_*lar 1 push-notification google-cloud-messaging

我正在遵循(推送位置入门指南),但在第 6 步中遇到错误:

undefined:1 Uncaught (in promise) DOMException: Registration failed - permission denied
Run Code Online (Sandbox Code Playgroud)

我的 manifest.json 文件根据网络选项卡正确加载。

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

{
  "name": "Push Notifications codelab",
  "gcm_sender_id": "123456789",
  "gcm_user_visible_only": true,
  "permissions": [
    "gcm"
  ]
}
Run Code Online (Sandbox Code Playgroud)

我按照指南在本地主机上运行我的服务器。

小智 10

如果您使用 Brave(浏览器)并遇到相同问题,则必须在设置中启用使用 Google 服务进行推送消息

为了启用它:

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

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