firebase / firebase/firebase-js-sdk
FR: Support `webpush.fcm_options.link` for opening another domain.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 37
Description
### [REQUIRED] Describe your environment
* Operating System version: macOS 12.0.1
* Browser version: Chrome 96
* Firebase SDK version: 9.6.1
* Firebase Product: cloud messaging
### [REQUIRED] Describe the problem
According to the code below, when a user clicks the notification from FCM, it can only open the same domain.
https://github.com/firebase/firebase-js-sdk/blob/cdada6c68f9740d13dd6674bcb658e28e68253b6/packages/messaging/src/listeners/sw-listeners.ts#L130-L136
It would be fantastic if we could open a URL from another domain.
For the time being, I've devised a workaround: directly above the call to `firebase.messaging(),` insert your own `notificationclick`:
```js
self.addEventListener('notificationclick', event => {
const url = event.notification.data.FCM_MSG.notification.click_action
clients.openWindow(url)
})
firebase.messaging()
```
It is necessary to install an event listener sooner rather than later since it will be halted by the following line:
https://github.com/firebase/firebase-js-sdk/blob/cdada6c68f9740d13dd6674bcb658e28e68253b6/packages/messaging/src/listeners/sw-listeners.ts#L121-L122
Contributor guide
Assessment
This issue has not been assessed yet.