You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I got the background and foreground and all working,But do this:
Close the browser tab and disconnect internet from your browser (I use tripmode firewall to do this)
2.Send a message to the client
3.Connect back the browser and visit the website.
4.You get no new messages.
5.Send another message now.
6.You'll see the old message also comes in with the new one.
So really?Shall I just send an empty message everytime the user gets in just to push the old messages which he didn't receive because he was offline?I don't think so.It sounds more like a bug to me.
Relevant Code:
firebase-messaging-sw.js
// Give the service worker access to Firebase Messaging.// Note that you can only use Firebase Messaging here, other Firebase libraries// are not available in the service worker.importScripts('https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js');importScripts('https://www.gstatic.com/firebasejs/7.20.0/firebase-messaging.js');// Initialize the Firebase app in the service worker by passing in// your app's Firebase config object.// https://firebase.google.com/docs/web/setup#config-objectfirebase.initializeApp({//Stuff removed for no abusing});// Retrieve an instance of Firebase Messaging so that it can handle background// messages.constmessaging=firebase.messaging();messaging.setBackgroundMessageHandler(function(payload){console.log('[firebase-messaging-sw.js] Received background message ',payload);// Customize notification hereconstnotificationTitle='Background Message Title';constnotificationOptions={body: 'Background Message body.',// icon: '/firebase-logo.png'};returnself.registration.showNotification(notificationTitle,notificationOptions);});
bundle.js
import*asfirebasefrom"firebase/app";import"firebase/messaging";varfirebaseConfig={//removed};// Initialize Firebasefirebase.initializeApp(firebaseConfig);constmessaging=firebase.messaging();messaging.usePublicVapidKey("BC6x_n00j4PlXpAl4Dhuck7mkuBqPJ67AmB33YBGSgzsM2hPQUIlkdyqL94vmFNfb9pKAHiC1gM6D3l07O7RsUM");// Get Instance ID token. Initially this makes a network call, once retrieved// subsequent calls to getToken will return from cache.constshowToken=(msg)=>{console.log(msg);};messaging.getToken().then((currentToken)=>{if(currentToken){// sendTokenToServer(currentToken);// updateUIForPushEnabled(currentToken);console.log(currentToken);}else{// Show permission request.console.log('No Instance ID token available. Request permission to generate one.');// Show permission UI.// updateUIForPushPermissionRequired();// setTokenSentToServer(false);}}).catch((err)=>{console.log('An error occurred while retrieving token. ',err);showToken('Error retrieving Instance ID token. ',err);// setTokenSentToServer(false);});// Callback fired if Instance ID token is updated.messaging.onTokenRefresh(()=>{messaging.getToken().then((refreshedToken)=>{console.log('Token refreshed.');// Indicate that the new Instance ID token has not yet been sent to the// app server.// setTokenSentToServer(false);// Send Instance ID token to app server.// sendTokenToServer(refreshedToken);// ...console.log(refreshedToken);}).catch((err)=>{console.log('Unable to retrieve refreshed token ',err);showToken('Unable to retrieve refreshed token ',err);});});messaging.onMessage((payload)=>{console.log('Message received. ',payload);});
The text was updated successfully, but these errors were encountered:
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Steps to reproduce:
I got the background and foreground and all working,But do this:
2.Send a message to the client
3.Connect back the browser and visit the website.
4.You get no new messages.
5.Send another message now.
6.You'll see the old message also comes in with the new one.
So really?Shall I just send an empty message everytime the user gets in just to push the old messages which he didn't receive because he was offline?I don't think so.It sounds more like a bug to me.
Relevant Code:
firebase-messaging-sw.js
bundle.js
The text was updated successfully, but these errors were encountered: