how to handle foreground click notification event
i want the notification click event using
messaging.onMessage...
in foreground
notification clicks are passed to the service worker file.
You would need to add a click event listener as shown here: https://web-push-book.gauntface.com/chapter-05/03-notification-behaviour/#notification-click-event
@gauntface
I tried the above link and found out that event doesn't contain click_action
The "click_action" is a FCM specific field that they implemented inside FCM JS SDK. In their implementation, they store the whole payload in notificationOptions' "data" field, so that they can retrieve it inside the "notificationclick" event handler.
So, instead of:
var options = {
body: payload.notification.body,
icon: payload.notification.icon,
click_action: payload.notification.click_action
};
We should use:
var options = {
body: payload.notification.body,
icon: payload.notification.icon,
click_action: payload.notification.click_action, // To handle notification click when notification is moved to notification tray
data: {
click_action: payload.notification.click_action
}
};
Github code for reference - https://github.com/firebase/firebase-js-sdk/blob/27d27789ad7cb6fc157f60488e151d7f83f710e8/packages/messaging/src/controllers/sw-controller.ts#L242
Note: The FCM documentation misses this specific information.
Hallo Everyone, i would like to implement an click on notification when the app is foreground (it works when the app is background) but not if the app foreground, am using fcm by (firebase cloud function), thanks for everyone
@MasriNaser Did you find a solution to this? I'm stuck here.
@krishnan-ubuntu you can check my comment here for the solution.
@krishnan-ubuntu Can you share your implementation if it's different from the suggested one?
@nimitbhargava yes, I will create a new repo and share it.
@krishnan-ubuntu you can check my comment here for the solution.
Thank you, but I got it working.
Can you help me in getting the click_action to work in the background in firebase web
@krishnan-ubuntu Can you share your implementation if it's different from the suggested one?
Have you got it working in the background
@BharadhanVM
Can you help me in getting the click_action to work in the background in firebase web
You can share your repo here or mail me
Here is my Code . I am sending the notification from the firebase console. When I am sending a post request from the postman and clicking on the notification it redirects me to the URL. But when I am sending it from the firebase console it is not working.
On Wed, Oct 9, 2019 at 5:58 PM Nimit Bhargava [email protected] wrote:
@BharadhanVM https://github.com/BharadhanVM
Can you help me in getting the click_action to work in the background in firebase web You can share your repo here or [mail me](mailto: [email protected])
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-js/issues/137?email_source=notifications&email_token=AKQ3OVOYOZ5KFYGF5Q7KTO3QNXE5NA5CNFSM4DK2EDAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAXWUBY#issuecomment-539978247, or mute the thread https://github.com/notifications/unsubscribe-auth/AKQ3OVOR2EE6SOA4VF7NU33QNXE5NANCNFSM4DK2EDAA .
My repository Link https://github.com/BharadhanVM/Firebase-Web-Notifications.git
On Wed, Oct 9, 2019 at 6:14 PM Bharadhan Deepan < [email protected]> wrote:
Here is my Code . I am sending the notification from the firebase console. When I am sending a post request from the postman and clicking on the notification it redirects me to the URL. But when I am sending it from the firebase console it is not working.
On Wed, Oct 9, 2019 at 5:58 PM Nimit Bhargava [email protected] wrote:
@BharadhanVM https://github.com/BharadhanVM
Can you help me in getting the click_action to work in the background in firebase web You can share your repo here or [mail me](mailto: [email protected])
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-js/issues/137?email_source=notifications&email_token=AKQ3OVOYOZ5KFYGF5Q7KTO3QNXE5NA5CNFSM4DK2EDAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAXWUBY#issuecomment-539978247, or mute the thread https://github.com/notifications/unsubscribe-auth/AKQ3OVOR2EE6SOA4VF7NU33QNXE5NANCNFSM4DK2EDAA .
@BharadhanVM your repo has nothing but empty readme 😅 I guess you should create a StackOverflow question instead of this thread.
Can you check this branch https://github.com/BharadhanVM/Firebase-Web-Notifications/tree/notification-feature . It has the files please
On Wed, Oct 9, 2019 at 6:37 PM Nimit Bhargava [email protected] wrote:
@BharadhanVM https://github.com/BharadhanVM your repo has nothing but empty readme 😅 I guess you should create a StackOverflow question instead of this thread.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-js/issues/137?email_source=notifications&email_token=AKQ3OVLKRJRNCGZ3HMWJ6N3QNXJSFA5CNFSM4DK2EDAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAX2EWY#issuecomment-539992667, or mute the thread https://github.com/notifications/unsubscribe-auth/AKQ3OVOOSZPWGOLM5R6SGUTQNXJSFANCNFSM4DK2EDAA .
@nimitbhargava Here is my repository link https://github.com/BharadhanVM/Firebase-Web-Notifications/tree/notification-feature
@BharadhanVM Can you share the payload information from here
Also, I would refrain from using this thread to solve implementation related issue as it's not FCM issue. I would suggest StackOverflow to ask.
There is nothing printed on the payload ,I am not able to find it on the stackoverflow.Can I have your contact details if possible
On Wed, 9 Oct 2019 at 7:26 PM, Nimit Bhargava [email protected] wrote:
@BharadhanVM https://github.com/BharadhanVM Can you share the payload information from here https://github.com/BharadhanVM/Firebase-Web-Notifications/blob/notification-feature/messaging/public/index.html#L141
Also, I would refrain from using this thread to solve implementation related issue as it's not FCM issue. I would suggest StackOverflow https://stackoverflow.com/questions/ask to ask.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-js/issues/137?email_source=notifications&email_token=AKQ3OVIXQT5626WPCJKG7CDQNXPKBA5CNFSM4DK2EDAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAX674Y#issuecomment-540012531, or mute the thread https://github.com/notifications/unsubscribe-auth/AKQ3OVMH6MLBMJ2XANSP7RLQNXPKBANCNFSM4DK2EDAA .
@BharadhanVM
It could be a possible reason for you to not receive notification when app is on foreground. Please go ahead and create StackOverflow question (from here) and then share the link here. Also tag it with firebase-cloud-messaging so it can be discoverable by the community.
Make sure you follow How to create a Minimal, Reproducible Example