firebase / firebase/firebase-js-sdk

On click action, the browser focuses on the tab with same host, but doesn't open the new URL [messaging]

Open
#3,922 6 comments 7 reactions 0 assignees View on GitHub
api: messaging documentation feature request
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### [REQUIRED] Describe your environment

* Operating System version: Ubuntu 20.04, Android 10
* Browser version: Chrome 86.0.4240.75 (same version on Ubuntu and Android)
* Firebase SDK version: 7.22.1
* Firebase Product: messaging (@firebase/messaging@0.7.1)

### [REQUIRED] Describe the problem

#### Steps to reproduce:

When clicking on a message with `payload.fcmOptions.link` or `payload.notification.click_action`, the browser tries to find a tab with the __same host__ as the URL in message. If this tab doesn't exist, the browser opens a new one with the the message's URL; otherwise, it __just focuses on__ the found tab, but doesn't __open the new URL__.

Therefore, if there is a inactive tab on https://example.com/good-bye, clicking on a message with `payload.fcmOptions.link: 'https://example.com/cart'` will focus on tab https://example.com/good-bye, instead of opening https://example.com/cart.

#### Relevant Code:

I think this issue was caused by a modification in the method `SwController.getWindowClient` by pull request #2772.

The controller tries to find a client based on a URL. If it succeeds, the service worker focuses on this tab. If it fails, the service worker opens a new tab.

Before the commit 18fb16b7, no clients would be returned if there was no tab with the same URL:
https://github.com/firebase/firebase-js-sdk/blob/5a60243bf264967819fc5c3897892084c5eb4d43/packages/messaging/src/controllers/sw-controller.ts#L280-L285

After the merge, a tab with the same `location.host` than message's URL is being reused, ignoring the passed URL:
https://github.com/firebase/firebase-js-sdk/blob/18fb16b74ed0e6b4e3a2b379a11fb07d6ab654e0/packages/messaging/src/controllers/sw-controller.ts#L280-L285

In the scenario prior 18fb16b7 (@firebase/messaging <= 0.6.13), the service worker would open the message's URL in a new tab.
In the scenario after 18fb16b7 (@firebase/messaging > 0.6.13), the service worker __only focuses on__ any tab with same `host`, ignoring the message's URL.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.