2

Following this tutorial I am trying to register my chrome browser to the GCM but I can't subscribe the browser:

I am trying to do the same as the following examples without the button. Once you accept the permision request, I want to get the subscription id but it doesn't work:

Here is the project if you want to check the code:

Thank you.

4

2 回答 2

2

您提供的示例项目的问题是 Service Worker 永远不会准备好。

这是由于您的服务工作者 js 文件的位置。它存储在js目录中,因此它的范围只是位于该目录中的页面,并且请求服务工作者的页面在根目录中。

要使服务工作者可用于整个站点,您必须将其放在站点的根目录中。

根据W3C 规范,您也可以通过在调用中设置scopeURL选项来手动设置 Service Worker 的作用域。navigator.serviceWorker.register()

于 2015-07-02T14:22:42.143 回答
1

我找到了这个:

https://developers.google.com/web/updates/2015/03/push-notificatons-on-the-open-web?hl=en

这似乎有一个推送通知的分步实施指南。

于 2015-06-26T08:31:21.967 回答