How to create local push notifications in React?

Viewed 675

I had been trying to make push notifications locally in Reactjs. The Notification API works fine with Desktop browsers. But when it comes to Android, the follow error is thrown.

TypeError: Failed to construct 'Notification': Illegal constructor. Use ServiceWorkerRegistration.showNotification() instead.

I am using creat-react-app's default service worker.

How can I use the above said ServiceWorkerRegistration.showNotification() to make notifications. I checked several sites and I am unable to understand the concept.

1 Answers

Could you please show us the code by the way you must contemplate:

​ServiceWorkerRegistration.showNotification(title, [options]).then(function(NotificationEvent) { ... });

in options properties the badge: The URL of an image to represent the notification when there is not enough space to display the notification itself such as, for example, the Android Notification Bar. On Android devices, the badge should accommodate devices up to 4x resolution, about 96 by 96 px, and the image will be automatically masked

Related