Push Notifications Chrome (register and wait notifications)

1.8k views Asked by At

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.

2

There are 2 answers

0
pau.moreno On BEST ANSWER

The problem with the example project you give is that the Service Worker never gets ready.

This is due to the location of your service worker js file. It is stored in the js directory, so its scope are only the pages located in this directory, and the page requesting for the service worker is in the root dir.

To make a service worker available for the whole site, you must put it in the site's root directory.

According to the W3C specification, you can also set the Service Worker's scope manually by setting the scopeURL option in the navigator.serviceWorker.register() call.

1
Arathi Sreekumar On

There is this one I found:

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

Which seems to have a step by step implementation guide to push notification.