Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!