Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
Accessing Dexie(Indexed db) inside FCM onBackgroundMessageHandler

I am using FCM for push notifications in my web app and everything is working fine foreground and background except the fact that when my browser is closed, I am receiving FCM notifications but unable to process them. I am storing the data from FCM in an Indexed db wrapped by Dexie and my db is not updated with the FCM data values when the browser is itself closed. However, if my app's tab is closed but the browser is open, things work fine, I am using the below code to do my task in my firebase service worker :

messaging.onBackgroundMessage(async function (payload) {
  console.log('Received background message ', payload);

  const notificationTitle = payload.data.title;
  const notificationOptions = {
    body: payload.data.body,
    tag: "notification-1",
    
  };

  if(!db){
    await initDb()
  }

  if (payload.data.type == 'DATA') {
   await addDataToDb(payload.data.item)
  }

  self.registration.showNotification(notificationTitle,
    notificationOptions);
});

async function initDb() {
  console.log("Initializing Dexie")
  db = await new Dexie('AppDB').open()
  Dexie.getDatabaseNames().then((names) => {
    console.log('Db names ' + names)
  });
}

DB updating code is all fine as it works as expected when the browser is still running. Can someone please help me here?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda