mobilusoss / react-web-notification

React component with HTML5 Web Notification API
http://mobilusoss.github.io/react-web-notification
MIT License
270 stars 82 forks source link

Web notification error on android #70

Closed gabyrusu closed 4 years ago

gabyrusu commented 4 years ago

After allowing notifications on android browsers, the app is crashing because of this error:

react-dom.production.min.js:209 TypeError: Failed to construct 'Notification': Illegal constructor. Use ServiceWorkerRegistration.showNotification() instead.

It seems like this is related to android not supporting the "new Notification()" constructor https://bugs.chromium.org/p/chromium/issues/detail?id=481856

georgeOsdDev commented 4 years ago

Can you try named import like below. import * as ReactNotification from 'react-web-notification'

gabyrusu commented 4 years ago

@georgeOsdDev I'm using Typescript so I imported from typings like here https://github.com/mobilusoss/react-web-notification/issues/38 But that's not the problem as on desktop they work just fine. The problem is on android devices (as tested so far) because the "new Notification()" constructor is not implemented and might be removed in the future for desktops as well. See https://bugs.chromium.org/p/chromium/issues/detail?id=481856#c3

georgeOsdDev commented 4 years ago

You can use props.swRegistration. It will not call new Notification().

gabyrusu commented 4 years ago

Oh, how did I missed that? Thanks!