onMessage() not fired when app is in background (Web javascript).
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- firebase, javascript
Línea de trabajo
Comienza comparando la documentación de Firebase Web Messaging sobre onMessage(), onBackgroundMessage() y los clics en notificaciones con el código index y el fragmento sw.js proporcionados. Reproduce el flujo de la ventana en segundo plano usando Firebase SDK 8.9.1 y verifica después si el comportamiento documentado del callback coincide con la expectativa comunicada, e identifica qué aclaración o cambio en el repositorio está respaldado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I building a simple demo chat app with fcm integrated for new message notification. As far as I know, in fcm doc regarding onMessage(), it said this method get called when:
(1) a message is received while the app has focus
(2) - the user clicks on an app notification created by a service worker messaging.onBackgroundMessage handler.
But I'm not sure why onMessage() callback is not fired when my app is in background.
Step 1: Describe your environment
- Operating system: OSX Big Sur
- Browser: All
- Firebase SDK version: 8.9.1
Step 2: Describe the problem:
onMessage() callback is not fired when my app is in background.
Steps to reproduce:
- hide current browser window to make it in background state.
- send test message.
Observed Results:
onBackgroundMessage() from sw.js get called fine, but when I clicked on the notification to land on my app window, onMessage() did not get triggered (it's only triggered when the current browser window is in foreground state). It did not show any error or warning.
Expected Results:
onMessage() should be fired after I clicked the notification to have my app focused.
Relevant Code:
this is my index file
const messaging = firebase.messaging();
function sendTokenToServer(fcm_token) {
let player_sn = '{{Auth::id()}}';
axios.post('api/save-token', {
fcm_token,
player_sn
})
.then(function(response) {
// console.log(response);
})
.catch(function(error) {
console.log(error);
});
}
messaging.getToken({
vapidKey: '{{config("fcm.VAPID")}}'
}).then((currentToken) => {
// console.log(currentToken)
if (currentToken) {
sendTokenToServer(currentToken)
} else {
// Show permission request UI
console.log('No registration token available. Request permission to generate one.');
// ...
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
// ...
});
messaging.onMessage((payload) => {
console.log('onMessage');
console.log(payload)
});
this is my sw.js
importScripts('https://cdnjs.cloudflare.com/ajax/libs/firebase/8.10.1/firebase.js');
importScripts('https://cdnjs.cloudflare.com/ajax/libs/firebase/8.10.1/firebase-messaging.min.js');
const firebaseConfig = {
apiKey: "AIzaSyBE90OnfKk6MELQ2-Z_DVLYp4maXVzvQO8",
authDomain: "ninja-firestore-tut-nov11.firebaseapp.com",
databaseURL: "https://ninja-firestore-tut-nov11-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "ninja-firestore-tut-nov11",
storageBucket: "ninja-firestore-tut-nov11.appspot.com",
messagingSenderId: "28680409583",
appId: "1:28680409583:web:66bef6c94232b88816e61a"
};
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
messaging.onBackgroundMessage((payload) => {
console.log('onBackgroundMessage ', payload);
// Customize notification here
const {title, body} = payload.notification;
const notificationTitle = title;
const notificationOptions = {
body: body,
icon: '/firebase-logo.png'
};
// self.registration.showNotification(notificationTitle,
// notificationOptions);
});
Note: I need to comment self.registration.showNotification(notificationTitle, notificationOptions); to avoid the notification got duplicate.
Any help on this would be much appreciated...
Thank you.
- Lenguaje dominante
- TypeScript
- Estrellas
- 5.4k
- Forks
- 3.7k
- Merge medio
- 3 d 28 min
- PR fusionados (30 d)
- 2
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de firebase/quickstart-js
-
PaymentAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 10/100
firebase/quickstart-js#945 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
firebase/quickstart-js#937 · 1 comentario ·
-
Get the region of my firebase function from frontend fileQuizá libre de nuevo @anjalisharma0909 la tomó hace 230 días y no hay ningún pull request abierto. Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
firebase/quickstart-js#907 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 32/100
firebase/quickstart-js#837 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
firebase/quickstart-js#825 ·
Todos los issues de firebase/quickstart-js
Issues similares
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
lingdojo/kana-dojo#32663 · 1 comentario · 5 reacciones ·
Los mantenedores suelen responder en 1 día
-
Admin: Title Separator field can't be cleared (input falls back to "|")Posiblemente ocupada @emdashbot la tomó hoy. Abiertobot:bug bot:in-review
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
emdash-cms/emdash#4236 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
PHP workflow streaming requests buffer the full SSE responsePosiblemente ocupada @Winoren la tomó hoy. Abiertoreview: medium
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
langgenius/dify#44270 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
area:holodeck review-finding
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
hyperdrive-technology/holodeck#142 ·
Los mantenedores suelen responder en 1 día
-
session-worker-compile.yml uses a floating oven-sh/setup-bun@v2 tag instead of the pinned SHAAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
code-yeongyu/senpi#3573 ·
Los mantenedores suelen responder en 1 día