Vue PWA mylog Source Code

firebase-messaging-sw.js

그랜파 개발자 2024. 11. 13. 03:55

firebase-messaging-sw.js

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

// Your web app's Firebase configuration (same as in your firebase.js)
const firebaseConfig = {
  apiKey: "your-api-key",
  authDomain: "your-auth-domain",
  projectId: "your-project-id",
  storageBucket: "your-storage-bucket",
  messagingSenderId: "your-messaging-sender-id",
  appId: "your-app-id",
};

// Initialize Firebase
firebase.initializeApp(firebaseConfig);

// Retrieve Firebase Messaging object.
const messaging = firebase.messaging();

messaging.onBackgroundMessage(function (payload) {
  console.log('Received background message ', payload);
  // Extract notification data
  const notificationTitle = payload.notification.title;
  const notificationOptions = {
    body: payload.notification.body,
    icon: payload.notification.icon || "/img/push-noti-icon.png",
    badge: "/img/push-badge-icon.png",
    image: "/img/push-image.png",
    data: { url: payload.notification.click_action || 'https://velog.io/@inetsos/posts' } // Custom data for the click event
  };

  self.registration.showNotification(notificationTitle, notificationOptions);
});

'Vue PWA mylog Source Code' 카테고리의 다른 글

functions/index.js  (1) 2024.11.15
main.js  (0) 2024.11.14
store/mylogs.js  (0) 2024.11.11
store/fcm.js  (0) 2024.11.09
store/auth.js  (0) 2024.11.09