When pwa is in background, the serviceworker still uses onMessage not onBackgroundMessage!
- Vorherrschende Sprache
- TypeScript
- Sterne
- 7.8k
- Forks
- 2.2k
- Ø Merge
- 22 Std. 28 Min.
- Gemergte PRs (30 T.)
- 6
Beschreibung
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.
Beitragsleitfaden
Rechercherichtung
Beginne damit, das onMessage-Setup des Dienstes mit der onBackgroundMessage-Registrierung in firebase-messaging-sw.js zu vergleichen, und reproduziere anschließend das Verhalten mit der PWA im Hintergrund. Als erledigt gilt die Aufgabe, wenn der erwartete Handler eingerichtet ist und das Verhalten beim Tippen auf die Benachrichtigung korrigiert oder die Einschränkung eindeutig dokumentiert wurde.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- angular, firebase, typescript
- Bereich
- frontend, web-dev
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 28/100