2

I found this tutorial that claims that it can be done using a combination of the follow HTML5 APIs:

  • Notifications API
  • Service Workers API
  • Push API

Apparently all 3 are required for this to work but when I search them in caniuse it doesn't appear that any one mobile browser supports all three APIs. Is there another way to go about this?

lola_the_coding_girl
  • 843
  • 2
  • 10
  • 22

2 Answers2

1

It's correct, you need to use a combination of those three APIs in order to send off-site (app-like) notifications to mobile. Currently the only browser that supports them is Chrome on Android.

  • The Service Worker is a way to run some Javascript functions in background even when the website is closed
  • The Push API is built upon the service workers and provides a way to activate it when a push signal is received. It also describes how the push signal should be propagated from your server through the browser manufacturer's servers and how to collect the device endpoint (a secret url that allows you to send push notifications to a device)
  • The Notification API is used to build and display the notification

If you use a service like Pushpad (I am the founder) it won't take too much for you to add push notifications to your web app, so you may start supporting Android and when other devices will support web push you'll get them for free without having to change your code.

collimarco
  • 34,231
  • 36
  • 108
  • 142
0

The information on caniuse.com is inaccurate. Try this simple PUSH demo in the Service Worker Cookbook with Chrome for Android v50 and you will see its working.

Answering to your question anyway, if you're working with a pure web application, the only way of showing native notifications is through Web Notifications API, you can then emulate push notifications via websockets, server sent events and reconnect when online by using NavigatorOnLine API but the you need the user to keep the browser running.

Notice that browsers able to use the Push API implies Service Worker support, at least, partially.

Salva
  • 6,507
  • 1
  • 26
  • 25