-
Notifications
You must be signed in to change notification settings - Fork 901
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
Add await
to onBackgroundMessage
callback
#5762
Conversation
|
Binary Size ReportAffected SDKs
Test Logs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍🏼 I've been having this issue and looking for an alternative until this fix is released. It looks like using synchronized-promise
in a compiled Webpack app works.
import { initializeApp } from 'firebase/app'
import { getMessaging, onBackgroundMessage } from 'firebase/messaging/sw'
import sp from 'synchronized-promise'
const showNotification = sp((title, options) => {
return self.registration.showNotification(title, options);
});
onBackgroundMessage(messaging, () => {
showNotification('Title', {}));
});
This solution doesn't work in a browser 😟 |
You are right, this is actually raising an error that I hadn't noticed when developing. That said, my notification is still displaying properly without Chrome's default notification, and it seems like the thrown error might be what is "fixing" the initial problem 😅 |
@philippevezina It might work because your bundler added polyfill for |
Hello! Resolution proposed in this PR works in our testing, and looks like it's enough. Thank you very much :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a changeset?
🙏 |
I am still having the same issues as described in #5516 ( currently on [email protected] ) , getting 2 notifications windows, first is the onBackgroundMessage(messaging, (payload) => {
const notificationTitle = "Message from " + payload.data["contact"];
const notificationOptions = {
body: payload.data["message"],
icon: "/img/icons/android-chrome-192x192.png",
data: payload.data,
};
self.registration.showNotification(notificationTitle, notificationOptions);
console.log("[service-worker] Received background message ", payload);
}); |
Did you try something like this? onBackgroundMessage(messaging, (payload) => {
const notificationTitle = "Message from " + payload.data["contact"];
const notificationOptions = {
body: payload.data["message"],
icon: "/img/icons/android-chrome-192x192.png",
data: payload.data,
};
console.log("[service-worker] Received background message ", payload);
return self.registration.showNotification(notificationTitle, notificationOptions);
}); |
oh yeah, for some reason I didn't see that last comment on the original issue (or didn't see that it was adding a |
|
To resolve issue