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

392
Views
FCM - How to send and display notification from vue app

I have an app that is running on firebase BaaS. I need to send notifications to a specific user when an action occur and at the same time retrive the notification to display it.

I've followed some guide and the documentations to implement it in my service worker and I was able to get a notification logged in console with this code when using the firebase console.


importScripts('https://www.gstatic.com/firebasejs/9.1.3/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/9.1.3/firebase-messaging-compat.js');

firebase.initializeApp({
    apiKey: "...",
    authDomain: "...firebaseapp.com",
    databaseURL: "https://...-default-rtdb.firebaseio.com",
    projectId: "...",
    storageBucket: "...appspot.com",
    messagingSenderId: "...",
    appId: "...",
    measurementId: "..."
});

// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();

messaging.onBackgroundMessage( (payload) => {
    console.log('[firebase-messaging-sw.js] Received background message ', payload);
    // Customize notification here for 'data' key
    let { data } = payload
    if( data && data.title && data.body ) {
        const notificationTitle = data.title || 'Test title';
        const notificationOptions = {
            body: data.body || 'Test body',
        };
  
        self.registration.showNotification(notificationTitle, notificationOptions);
    }
});
  
self.addEventListener('notificationclick', (event) => {
    let { notification } = event;
    // this event will not be occoured by notication of FCM 'notification' key
    console.log('[firebase-messaging-sw.js]  Notification clicked: ', event);
    notification.close()
}); 

Since the final user will not have access to the firebase FCM console, how I can add the ability to send a notification from my vue app, and how I can retrive it when a notification is recived?

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!