4

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 ?

Nicolas D
  • 115
  • 2
  • 7

1 Answers1

2

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.

Chris Love
  • 3,740
  • 1
  • 19
  • 16
  • So it is not possible to `focus()` a tab with the same origin as the `click_action` ? The service worker is forced to open a new tab everytime ? What about if the webapp is in standalone mode ? (It is surprising because it seems that the FCM SDK is trying to retrieve a tab of the same origin) – Nicolas D Dec 19 '17 at 16:07
  • 1
    I have the same problem, and if you try examples from https://github.com/firebase/quickstart-js all works as expected, after click on push notification user is redirected to already opened tab. I can't get this working in my app. – demsey Jan 18 '18 at 03:55
  • I got that working but the URL must be exactly the same, including the hashbang if you have one – demsey Jan 18 '18 at 04:01
  • let me know what you mean by hashbang @demsey – Sulaiman Nov 16 '19 at 12:21
  • url.com#!example or url.com#example – demsey Nov 17 '19 at 20:19