I have been reading for past few hours about Push Notification API and Web Notification API. I also discovered that Google & Apple gives push notification service for free via GCM and APNS respectively.
I am trying to understand if we can implement push notification to browsers using Desktop Notification, which I believe is what Web Notification API does. I saw a google documentation on how this can be done for Chrome here & here.
Now what am still not able to understand is:
- Can we use GCM/APNS to send push notification to all Web Browsers including Firefox & Safari?
- If not via GCM can we have our own back-end to do the same?
I believe all these answered in one answer can help a lot of people who are having similar confusions.
As of now GCM only works for chrome and android. similarly firefox and other browsers has their own api.
Now coming to the question how to implement push notification so that it will work for all common browsers with own back end.
2.after getting endpoint using Ajax save it along with browser name.
3.You need to create back end which has fields for title,message, icon,click URL as per your requirements. now after click on send notification, call a function say send_push(). In this write code for different browsers for example
3.1. for chrome
3.2. for mozilla
for other browsers please google...
I assume you are talking about real push notifications that can be delivered even when the user is not surfing your website (otherwise check out WebSockets or legacy methods like long polling).
GCM is only for Chrome and APNs is only for Safari. Each browser manufacturer offers its own service.
The Push API requires two backends! One is offered by the browser manufacturer and is responsible for delivering the notification to the device. The other one should be yours (or you can use a third party service like Pushpad) and is responsible for triggering the notification and contacting the browser manufacturer's service (i.e. GCM, APNs, Mozilla push servers).
Disclosure: I am the Pushpad founder
So here I am answering my own question. I have got answers to all my queries from people who have build push notification services in the past.
Answer to the original questions asked 3 years ago:
Answer: Google has deprecated GCM as of April 2018. You can now use Firebase Cloud Messaging (FCM). This supports all platforms including web browsers.
Answer: Yes, push notification can be sent from our own back-end. Support for the same has come to all major browsers.
Check this codelab from Google to better understand the implementation.
Implementing own backend in various programming languages.:
Further Readings:
Are there any free services to do the same? There are some companies that provide a similar solution in free, freemium and paid models. Am listing few below:
Note: When choosing a free service remember to read the TOS. Free services often work by collecting user data for various purposes including analytics.
Apart from that, you need to have HTTPS to send push notifications. However you can get https freely via letsencrypt.org