-
Notifications
You must be signed in to change notification settings - Fork 544
Notification events not working with service workers #68
Comments
Could you please elaborate? |
Sure, So when using a browser such as android chrome which does not have support for the Notification API, push.js uses a serviceworker instead. Currently the logic push.js uses for serviceworker push notifications is to simply register the serviceworker and then call showNotification on it. This means pretty much all the logic following this is unused Lines 245 to 284 in 93014bc
As a result the following push.js options do not work on android chrome
I've had a quick look at the service worker documentation and it doesn't look like it's trivial to wire up that logic to the serviceworker notification. |
Oh shucks, you're right. The |
Thanks for the explanation |
I apologize that I've been sort of MIA for these past few months, but I am currently working on merging in a change that will fix this issue. |
@Nickersoft Any update on when mobile notifications will start working again? |
@nickmask Mobile notifications never stopped working (unless there is some issue I am not aware of). This issue had to do with notification events not firing and throwing console errors on mobile. While this issue has been fixed in bc8932d, it has not been published to NPM yet, as there were some additional changes I was hoping to make before the next release. |
Was it? Did you check it? As far as i see, it wasn't (or even it can't be) fixed - there is no such event as "notificationclink" outside of service worker.
Reference: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/onnotificationclick My current solution is to add notificationclick event listener inside the service worker and then pass it to the parent window via postMessage. You can find an example here - https://github.com/dmitry-korolev/push-js |
Hello @Nickersoft , Same problem here, the notification is shown on mobile but methods (onClick, onShow, ...) don't trigger. Any news about this ? Thanks ! |
@Nickersoft What is the status of this issue? How to get onClick to work on Android Chrome browser? |
Hi guys. I'm currently looking into an issue where the |
Hello @Nickersoft , Edit: with |
HI @Nickersoft please let us know why the onclick is not working on Android chrome? It is not fixed??? |
To be completely honest, I forget what the outcome of my investigation was :/ I can try to reproduce the issue again soon. Looping in @theLufenk to see if he may be able to assist as well. |
@Nickersoft AFAIK, @dmitry-korolev is correct. The only possible solution IMO would be adding an Event Listener inside the service worker. I don't think we want to force the folks to use a compulsory piece of code in their ServiceWorkers. There is another problem though. While Notification.onclick enables us to attach the click handler function to every Notification instance we create, the ServiceWorker logic for the same entails registering a common Event Handler for all notification generated. So in effect, we can have a @Nickersoft @dmitry-korolev I would love to have your opinions on this approach and see if it is a possible solution ATM. And also, how we can refine the process in order not to cause a regression on the "Install and use with minimum hassles" aspect of the library. Let me also try and send in a pull request. Doesn't seem like a lot of changes TBH. |
nudge @Nickersoft @dmitry-korolev |
Hey @theLufenk @dmitry-korolev, sorry for the delay here – I think this approach sounds reasonable if you wanted to give it a shot. |
Add this event listner into your service worker For android chrome
|
Currently on browsers with service workers push.js is not able to handle any events on the notification.
push.js/push.js
Line 189 in 93014bc
The text was updated successfully, but these errors were encountered: