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
When pwa is in background, the serviceworker still uses onMessage not onBackgroundMessage! #3469
Comments
This issue does not seem to follow the issue template. Make sure you provide all the required information. |
Or is it possible that the service worker no longer needs to be set up separately because the browsers have changed and have now implemented their own service worker for notifications in the background and ignore the onBackgroundMessage-method in firebase-messaging-sw.js on mobile phones? THAT would explain why I don't receive notifications with the static message (onBackgroundMessage) when the app is in the background. Edit: Used codes for orientation |
Yeah i also am experiencing similar issue I get the notification in foreground as programmed and on background also but the background notification in ProgressiveWebApps(PWA) only comes when i open the PWA, It is as if the service worker is not running in background and gets wakedUp when we open the application. |
Hi, |
Of Course there is:
below is an example of how you may proceed: self.addEventListener('notificationclick', (event) => {
console.log('Notification clicked:', event.notification);
// Prevent the browser from focusing the Notification's related Window
event.notification.close();
// Use event.waitUntil() to extend the lifetime of the event handler until finished
event.waitUntil(
// Find or open the relevant client
clients.matchAll({
type: 'window',
includeUncontrolled: true // Include uncontrolled clients (tabs) such as those opened by the user
})
.then(clientsList => {
// Check if any client is already open for the URL
for (let client of clientsList) {
if (client.url === '/' && 'focus' in client) {
return client.focus();
}
}
// If no client is already open, open a new window/tab
if (clients.openWindow) {
return clients.openWindow('/');
}
})
);
}); |
Hello,
when I send a push notification to my app, the onMessage method is called even if it is in the background! Actually, the onBackgroundMessage should then be called, right? The problem now is that when I tap on the message box in Android, the Progressive Web Application is not brought to the foreground. Apparently Android thinks that the app is in the foreground? The message box disappears when I tap on it and the number of incoming messages also disappears from the app icon.
Is there any way to fix this?
The onMessage is defined in a service
this.message$ = new Observable(sub => onMessage(this.messaging, it => sub.next(it))).pipe( tap(payload => {this.print.info('MessagingService initFCMMessaging() FCM fmessage', { payload });}) );
The onBackgroundMessage is defined in the firebase-messaging-sw.js with static text.
`messaging.onBackgroundMessage(function(payload) {
// Customize notification here
const notificationTitle = 'My title';
const notificationOptions = {
body: 'My Bodytext',
icon: '/firebase-logo.png' || '/assets/icons/icon-72x72.png'
};
self.registration.showNotification(notificationTitle, notificationOptions);
});`
I only noticed this because I defined a static text for the background message.
The text was updated successfully, but these errors were encountered: