Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM notification on-click always open in new tab (web-app Polymer)

I'm trying to implement Firebase Cloud Messaging in a web-app (with Polymer and a service-worker and using the custom-sw of the SDK).

It is working great (on both desktop and android) but when the user click on the notification it is always opening the click_action in a new tab even if a tab of the same origin is opened (but not focused).

click_action = "https://example.firebaseapp.com/demo/command"
Url of inactive tab = "https://example.firebaseapp.com/demo"

It seems that the getWindowClient_ method of the FCM SDK is not parsing correctly the URL of active clients and so can't call focus() on the inactive tab.

Any idea how to resolve this ?

like image 502
Nicolas D Avatar asked Aug 31 '25 03:08

Nicolas D


1 Answers

That is how it is designed. It caught me off guard at first, but after I thought about it, the new tab/window made sense.

1) the service worker is a separate process from the browser. 2) when a notification displays it is not associated with a browser tab/window. 3) changing the url in an existing window would most likely confuse/irritate the user.

When the user clicks your button the notification assumes no active tab on the origin. So it opens a new window.

like image 69
Chris Love Avatar answered Sep 02 '25 18:09

Chris Love