Firebase-js-sdk: FR: Focus tab of the same origin (but not with the same url)

Created on 19 Dec 2017  ยท  8Comments  ยท  Source: firebase/firebase-js-sdk

[REQUIRED] Describe your environment

  • Operating System version: Ubuntu 16.04 / Chrome 63 / Node 8.9
  • Firebase SDK version: 4.8.1
  • Firebase Product: messaging

[REQUIRED] Describe the problem

When receiving a push message with a click_action in the notification payload, the service-worker tries to find a tab with the same url than the click_action.

If it succeeds, the service worker focus this tab.
If it fails, the service worker opens a new tab (or window).

But the url of the tab has to be exactly the same url than the click_action.
If a tab with the same origin than the click_action but with a different url (a different page, for my case in a one page application with Polymer) is found, the service worker will open a new tab instead of focusing this tab and send a message to it (to tell the application to change the page for example).

Steps to reproduce:

  1. Integrate the firebase-js-sdk into an application
    1.b. Navigate into the application
  2. Send a push notification to a client (with a click_action in the payload)
  3. Click on this notification
  4. See that will open a new tab (or window)

Relevant code : https://github.com/firebase/firebase-js-sdk/blob/7db74e6111051eab499b0d3e95fb0789200cb14a/packages/messaging/src/controllers/sw-controller.ts#L265

Example

Notification payload:
{ notification: { 'title': 'Title', 'body': 'Message body', 'click_action': 'https://example.firebaseapp.com/demo/commands/' } }
Url of the inactive tab : https://example.firebaseapp.com/demo

messaging feature request

All 8 comments

I would like to take this on as it's currently affecting our project forcing to workaround it by making use of setBackgroundMessageHandler and custom notificationclick event handler. Is this worth working on or there is no intention of doing any changes here, at least as of yet?

Did you find any solution to this huge problem?

I think it could be easily resolved, instead of the equal operator (here), we could use an include instead

I will make a PR with that ๐Ÿ™‚

----- Edit

Done ๐Ÿ˜„

Hi Nicolas,

It sounds great, but where is this file located?

Shlomo Aran
054-7399-340

On Fri, Mar 20, 2020 at 11:20 AM Nicolas Delperdange <
[email protected]> wrote:

I think it could be easily resolved, instead of the equal operator (here
https://github.com/firebase/firebase-js-sdk/blob/master/packages/messaging/src/controllers/sw-controller.ts#L282),
we could use an include instead

I will make a PR with that ๐Ÿ™‚

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-js-sdk/issues/390#issuecomment-601602975,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABLKC3ISCBU56SNGQZRX6EDRIMYODANCNFSM4EI5OVVQ
.

I have made the pull request, waiting for maintainers to review ๐Ÿ™‚

Hi Nicolas,

Now I realize that you are the firebase programmer.
So,

  1. this really a great product!
  2. This problem is huge, so if you can solve it, it will make it much
    better.
    Please do it as soon as you can, and let me know when I can use it.

Thanks,
Shlomo;

Shlomo Aran
054-7399-340

On Fri, Mar 20, 2020 at 11:20 AM Nicolas Delperdange <
[email protected]> wrote:

I think it could be easily resolved, instead of the equal operator (here
https://github.com/firebase/firebase-js-sdk/blob/master/packages/messaging/src/controllers/sw-controller.ts#L282),
we could use an include instead

I will make a PR with that ๐Ÿ™‚

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-js-sdk/issues/390#issuecomment-601602975,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABLKC3ISCBU56SNGQZRX6EDRIMYODANCNFSM4EI5OVVQ
.

Thank you so much.

Shlomo Aran
054-7399-340

On Fri, Mar 20, 2020 at 11:37 AM Nicolas Delperdange <
[email protected]> wrote:

I have made the pull request, waiting for maintainers to review ๐Ÿ™‚

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-js-sdk/issues/390#issuecomment-601609365,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABLKC3PFA52GW44T2RBC5Y3RIM2NTANCNFSM4EI5OVVQ
.

Hi Nicolas,

I received a message that the issue of oenning "new page" when the origin
is the same is closed.
Is this means that it is done, or it was rejected.
It is extremely important and you wrote that it is simple to implement.

If it is done, do I need to do something in my code to get it, or is it
coming from the server?

Thanks.

Shlomo Aran
054-7399-340

On Fri, Mar 20, 2020 at 11:20 AM Nicolas Delperdange <
[email protected]> wrote:

I think it could be easily resolved, instead of the equal operator (here
https://github.com/firebase/firebase-js-sdk/blob/master/packages/messaging/src/controllers/sw-controller.ts#L282),
we could use an include instead

I will make a PR with that ๐Ÿ™‚

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-js-sdk/issues/390#issuecomment-601602975,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABLKC3ISCBU56SNGQZRX6EDRIMYODANCNFSM4EI5OVVQ
.

Was this page helpful?
0 / 5 - 0 ratings