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

216
Vistas
How to call firebase function after browser window close

I am working on an angular & firebase application. trying to call firebase function/API that will send an email to the user if the user closes the browser/tab. I tried to execute some code on "beforeunload" event but it is not executing after the browser/tab closed. any suggestions will be very helpful. Thank you.

@HostListener('window:beforeunload', ['$event'])
unloadHandler(event: any) {
  this.sendCartInfo()
}
  
sendCartInfo() {
  let data = await this.cartService.getCollectionData();

  let mail = await this.auth.sendAbEmail({
    cartItems: data.products,
    email: data.email,
  });
}

async sendAbEmail(cartItems) {
  return this.http
  .post<any>('https://firebase-url.net/app/auth/abondoned',cartItems, {
    headers: { Authorization: `Bearer ${await this.getFirebaseToken()}` },
  }).toPromise();
}

export const abEmail = (toEmail: string, data, cart) => {
  const msg = {
    to: toEmail,
    from: {
      email: "noreply@abc.com",
      name: appName,
    },
    templateId: template_ids.dummy,
    dynamic_template_data: { ...data, cart: cart.cartItems },
  };
  return sgMail.send(msg);
};

export const cronFunction = functions.pubsub
  .schedule(`every 2 seconds`)
  .onRun((context) => {
   sgMail.send(msg);
});

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