Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

95
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda