PageSourceSearch

https://mk8.online/firebase-messaging-sw.js?v=7

js mk8.online collected 2026-10-08 08:29:52 UTC 3,030 bytes, 93 lines download raw bytes

1importScripts('https://www.gstatic.com/firebasejs/10.9.0/firebase-app-compat.js');
2importScripts('https://www.gstatic.com/firebasejs/10.9.0/firebase-messaging-compat.js');
3
4//// DEV env
5//const firebaseConfig = {
6//    apiKey: "AIzaSyAfHhJLRXRurT9YGmmHFrpJDBYdjxp1Ph8",
7//    authDomain: "afbgg-dev.firebaseapp.com",
8//    projectId: "afbgg-dev",
9//    storageBucket: "afbgg-dev.appspot.com",
10//    messagingSenderId: "809207300555",
11//    appId: "1:809207300555:web:7e23fb69de1dd1eea1764e",
12//    measurementId: "G-Q95EDKE5QC"
13//};
14
15//// PROD env
16const firebaseConfig = {
17    apiKey: "AIzaSyDSWJEJp6-fGpzUS5Ab1cikTqx-LhBVlwg",
18    authDomain: "afbgg-e8e58.firebaseapp.com",
19    projectId: "afbgg-e8e58",
20    storageBucket: "afbgg-e8e58.appspot.com",
21    messagingSenderId: "138504149073",
22    appId: "1:138504149073:web:666e48cc353fe7fe5b4070",
23    measurementId: "G-ZKPC375X30"
24};
25
26// Initialize Firebase
27firebase.initializeApp(firebaseConfig);
28
29const messaging = firebase.messaging();
30
31// 🔹 Force update immediately when new SW is found
32self.addEventListener("install", (event) => {
33    self.skipWaiting();
34});
35
36self.addEventListener("activate", (event) => {
37    event.waitUntil(
38        (async () => {
39            await clients.claim();
40        })()
41    );
42});
43
44// 🔹 Always fetch firebase-notification.js fresh (bypass cache)
45self.addEventListener("fetch", (event) => {
46    if (event.request.url.includes("firebase-notification.js")) {
47        event.respondWith(
48            fetch(event.request, { cache: "no-store" }).catch(() => {
49                // fallback if offline
50                return caches.match(event.request);
51            })
52        );
53    }
54})
55
56
57self.addEventListener("notificationclick", function (event) {
58    event.notification.close();
59    
60    const url = self.location.origin;
61    
62    event.waitUntil(
63        clients.matchAll({ type: 'window', includeUncontrolled: true }).then(windowClients => {
64            // Check if there is already a window/tab open with the target URL
65            for (var i = 0; i < windowClients.length; i++) {
66                var client = windowClients[i];
67                // If so, just focus it.
68                if (client.url === url && 'focus' in client) {
69                    return client.focus();
70                }
71            }
72            // If not, then open the target URL in a new window/tab.
73            if (clients.openWindow) {
74                return clients.openWindow(url);
75            }
76        })
77    );
78})
79
80// Background message handler
81messaging.onBackgroundMessage((payload) => {
82
83    console.log('[SW] Background message received:', payload);
84
85    // Customize the notification here
86    const notificationTitle = payload.data?.title || 'Notification';
87    const notificationOptions = {
88        body: payload.data?.body || '',
89        icon: payload.data?.icon
90    };
91
92    self.registration.showNotification(notificationTitle, notificationOptions);
93});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.