Help with PWA app

457478955475 2 months ago

hello!
I created a PWA and set everything up in Firebase and Traccar, but the problem is that notifications only appear when the app is opened; they pile up, and then all arrive at once when the app is launched. Could I have configured the Service Worker incorrectly?

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

firebase.initializeApp({
  apiKey: 'myapikeynumber',
  authDomain: 'lalalala.firebaseapp.com',
  projectId: 'lalalatracker-7b12a',
  storageBucket: 'lalalalaltracker-7b12a.firebasestorage.app',
  messagingSenderId: '802233432533',
  appId: '1:0000000000:web:db1ea00000000ee55c',
});

const messaging = firebase.messaging();

messaging.onBackgroundMessage((payload) => {
  console.log('[Firebase] Notification received in the background:', payload);

  const notification = payload.notification || {};

  const title = notification.title || 'Harpia Tracker';
  const body = notification.body || '';

  self.registration.showNotification(title, {
    body,
    icon: '/favicon.ico',
    badge: '/favicon.ico',
    tag: payload.messageId || `harpia-${Date.now()}`,
    renotify: true,
    data: payload.data || {},
  });
});

The browser console shows that everything is fine.

Anton Tananaev 2 months ago

Are you talking about web push notifications? That's not something we officially support.

457478955475 2 months ago

Okay, I'll keep trying on my own.