2

I want to open the browser when a user clicks on the notification.

I have a firebase Project with Angular and i have a service worker registered which gets the notification. What Option is to set to open the browser on notification click ?

This is what i have so far and it does not work. ( I have it from here )

self.registration.showNotification(notificationTitle, notificationOptions);
self.addEventListener('notificationclick', function(event) {
  event.notification.close();
  clients.openWindow("/prices");
},false);

It does also not work with absolute URL.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Joniras
  • 1,258
  • 10
  • 32
  • @frank-van-puffelen any ideas on this? or any pointers on handling click in firebsae service worker. – Shumail Oct 12 '18 at 14:12
  • Have you tried using the promise .THEN .ELSE functions to check output/errors? – McMurphy Oct 16 '18 at 03:45
  • 1
    do you mean , on notification click the application should open in the new browser tab – ravi Oct 16 '18 at 08:40
  • clients.openWindow("/prices").then().else(err => {}) – McMurphy Oct 17 '18 at 00:28
  • @ravi yes, thats what i want – Joniras Oct 17 '18 at 16:11
  • @McMurphy ill try that as soon as possible – Joniras Oct 17 '18 at 16:11
  • 1
    @Joniras https://stackoverflow.com/questions/52225110/notificationclick-event-service-worker/52232540#52232540 could you please take a look at it what is does is ,it checks whether the application is open, by using variable appUrl which is URL of the application, if the application is not open ,it will open the application in new browser tab ,and if the application is already open in browser tab it will just focus on it. – ravi Oct 18 '18 at 14:16
  • @ravi yes this was the solution !! also some of this actually: https://stackoverflow.com/questions/50755931/firebase-set-background-message-handler – Joniras Oct 22 '18 at 10:24

0 Answers0