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.
I suggest using pubnub. I tried using ServiceWorkers and PushNotification from the browser however, however when I tried it webviews did not support this.
https://www.pubnub.com/docs/web-javascript/pubnub-javascript-sdk
GCM/APNS are only for Chrome and Safari respectively.
I think you may be looking for
Notification
:https://developer.mozilla.org/en-US/docs/Web/API/notification
It works in Chrome, Firefox, Opera and Safari.
May I redefine you question as below
Yes. By today (2017/05), you can use same client and server side implementation to handle Chrome, Firefox and Opera (no Safari). Because they have implemented web push notifications in a same way. That is Push API protocol by W3C. But Safari have their own old architecture. So we have to maintain Safari separately.
Refer browser-push repo for guide lines to implement web push notification for your web-app with your own back-end. It explains with examples how you can add web push notification support for your web application without any third party services.
Javier covered Notifications and current limitations.
My suggestion:
window.postMessage
while we wait for the handicapped browser to catch up, elseWorker.postMessage()
to still be operating with Web Workers.These can be the fallback option with dialog box message display handler, for when a Notification feature test fails or permission is denied.
Notification has-feature and denied-permission check:
You can push data from the server to the browser via Server Side Events. This is essentially a unidirectional stream that a client can "subscribe" to from a browser. From here, you could just create new
Notification
objects as SSEs stream into the browser:A bit old, but this article by Eric Bidelman explains the basics of SSE and provides some server code examples as well.
this is simple way to do push notification for all browser https://pushjs.org
});