小编Fra*_* LG的帖子

发送网络推送通知时出错:没有端点?

我创建了一个基本的应用程序,尝试使用 web-push 节点库发送推送通知。\n但是,我总是遇到错误:“你必须至少传入一个端点”\n我不明白,因为我“subscribe”(使用 ServiceWorker Api subscribe() 方法),它创建一个到我的本地主机地址的端点

\n\n

事实上,我真的不知道该怎么做才能解决这个问题

\n\n

这是我的“订阅”代码:

\n\n
async   subscribe() {\n   const sw = await navigator.serviceWorker.ready; \n   const applicationServerPublicKey = \'BADCyHKPTCj1B9Knvmz2_EF1iLieHVZX2eEcCnMLvmMJA2ADlcDILgDC31ztGp1T1TznLpaJ14GQbdIM4APrr6k\';\n   const applicationServerKey = this.urlB64ToUint8Array(applicationServerPublicKey);\n   console.log("le service worker est " + sw);\n   sw.pushManager.subscribe({\n       userVisibleOnly: true,\n      applicationServerKey: applicationServerKey,\n   }).then(\n       subscription => {\n           console.log("User is subscribed with the subscription : ");\n           console.log(subscription);\n
Run Code Online (Sandbox Code Playgroud)\n\n

在控制台上,我可以看到在“订阅”对象中有一个端点\n这里是发送通知的代码:

\n\n
console.log("Juste avant d\'envoyer la notif on veut envoyer \xc3\xa0  :")\nconsole.log(this.state.endpoint)\n\nwebpush.sendNotification(\n  this.state.endpoint,\n  payload,\n  options\n);\n
Run Code Online (Sandbox Code Playgroud)\n\n

但我进入控制台:

\n\n
\n

Juste avant d\'envoyer la notif on …

javascript service-worker web-push

5
推荐指数
1
解决办法
4176
查看次数

标签 统计

javascript ×1

service-worker ×1

web-push ×1