1

So far I found out that if one wants to opt in for browser push notifications they get a random string from GCM that identifies their device for future references. In this case when a backend service wishes to send a browser push notification would sent to the previously generated id.

My question, is, is it possible to subscribe directly to a topic in browsers as is the case for mobile apps.

Emma
  • 323
  • 3
  • 16

2 Answers2

1

There is a common misconception between what Chrome, Opera on Android and Samsung Browser does vs what should be done.

In the early days of Web Push on Chrome, a GCM endpoint would be returned and you had to use the GCM API to send a message. This was just a temporary solution to offer push on the web until GCM supported the Web Push Protocol, which is a standards based API for sending a push message. The Web Push Protocol does not offer a topic style API.

GCM now supports the Web Push Protocol and should be what you use to send messages as this will work for Firefox, Chrome, Opera on Android, Samsung Browser and any future browser that supports web push.

The important information:

When using web push on Chrome DO NOT use the GCM API

Matt Gaunt
  • 9,434
  • 3
  • 36
  • 57
  • What are the reasons for not using GCM API, if I understand correctly this API allows one to actually subscribe users to the service and get started dispatching the push notifications. – Emma Aug 25 '16 at 09:59
  • 1
    The GCM API is proprietary and a service run by Google. The web needs an API which has a standard which any browser can can implement. – Matt Gaunt Aug 28 '16 at 15:45
  • Ok, got it. Thanks – Emma Sep 01 '16 at 14:36
0

After poking around from google I figured out this is only a feature supported for mobile apps.

For example for Android one can use the GsmPubSub class to access the topics subscription functionality which is not available in chrome browser. So, if you would like to send browser push notifications you may have to stick to the subscription endpont that you get at registration from the description here

Emma
  • 323
  • 3
  • 16
  • There was a recently announced Firebase Cloud Messaging JavaScript library that may have what you were looking for. See my answer [here](http://stackoverflow.com/a/38091520/4625829). – AL. Oct 18 '16 at 04:13