Skip to content

onMessage payload click_action and icon not received because propagateNotificationPayload #5824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rockmandash opened this issue Dec 20, 2021 · 8 comments

Comments

@rockmandash
Copy link

[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

This function removes click_action and icon when onMessage is called by foreground app.

function propagateNotificationPayload(
payload: MessagePayload,
messagePayloadInternal: MessagePayloadInternal
): void {
if (!messagePayloadInternal.notification) {
return;
}
payload.notification = {};
const title = messagePayloadInternal.notification!.title;
if (!!title) {
payload.notification!.title = title;
}
const body = messagePayloadInternal.notification!.body;
if (!!body) {
payload.notification!.body = body;
}
const image = messagePayloadInternal.notification!.image;
if (!!image) {
payload.notification!.image = image;
}
}

And the image is not supported on macOS 12, which makes the code very confusing.

@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@zwu52
Copy link
Member

zwu52 commented Dec 28, 2021

@rockmandash I assume you are sending through the legacy send API since click_action and icon has been deprecated after v1 Send. I can make a PR to fill them in.

@rockmandash
Copy link
Author

rockmandash commented Dec 29, 2021

@zwu52 I did not utilize a legacy API, thus my payload is as follows:

{
  "message": {
    "token": "",
    "notification": {
      "title": "",
      "body": ""
    },
    "webpush": {
      "fcm_options": {
        "link": ""
      },
      "notification": {
        "icon": ""
      }
    }
  }
}

The FCM backend formats the webpush.fcm_options.link to click_action automatically.

For firebase-messaging-sw.js, my payload works normally in background mode without doing anything.

However, when it comes to foreground messages, these two payloads are lost, which is why I created this issue.

@guiiamorim
Copy link

I'm also having this issue, I cant see any of the fcm_options on the event handlers provided by the sdk. For the link to appear I have to make my own notificationclick event handler on the service worker:
image
Also, if I add an event listener on the push event I can retrieve the click_action parsing the event data to json. Someone found a solution for this?

@guimap
Copy link

guimap commented May 13, 2022

@guiiamorim the code
image
works for you ? For me, this event never reach, because this code
https://github.com/firebase/firebase-js-sdk/blob/master/packages/messaging/src/listeners/sw-listeners.ts#L121

@DellaBitta
Copy link
Contributor

It looks like an attempted fix was merged in. Could you check to see if it fixes this issue? Thanks!

@google-oss-bot
Copy link
Contributor

Hey @rockmandash. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Contributor

Since there haven't been any recent updates here, I am going to close this issue.

@rockmandash if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@firebase firebase locked and limited conversation to collaborators Jul 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants