Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do feature detection for Web Push?

Is there any easy way to feature detect Web Push API in browsers (Desktop and mobile)

like image 375
Prashant Agrawal Avatar asked Aug 12 '16 07:08

Prashant Agrawal


People also ask

What is the proper way to conduct feature detection?

Check whether a certain method or property (typically an entry point into using the API or other feature you are detecting for) exists in its parent Object. Create an element in memory using Document. createElement() and then check if a property exists on it. The example shown is a way of detecting Canvas support.

How does push notification work in web app?

A push service receives a network request, validates it and delivers a push message to the appropriate browser. If the browser is offline, the message is queued until the the browser comes online. Each browser can use any push service they want, it's something developers have no control over.

Can websites send push notifications IOS?

Overview. When important, time-sensitive events occur, inform your website users with push notifications you send from your server. In Safari 16 in macOS 13 or later, Safari supports web push — push notifications that use the cross-browser Push API, Notifications API, and Service Worker standards.


1 Answers

Some browser versions support only the service worker but not the Push API.

It's recommended that you try to detect the Push API itself.

If you need to check the browser support in a synchronous way (i.e. without waiting for Promise), you can use this (copied from the Pushpad SDK):

function isPushApiSupported() {
  return 'PushManager' in window;
}
like image 191
collimarco Avatar answered Nov 15 '22 20:11

collimarco