firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.84k stars 889 forks source link

FR: Support `webpush.fcm_options.link` for opening another domain. #5822

Open rockmandash opened 2 years ago

rockmandash commented 2 years ago

[REQUIRED] Describe your environment

[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:

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

guimap commented 2 years ago

Up for this current thread, I'm having this same issue :/ There's any update ?