PageSourceSearch

https://dailycaller.com/firebase-messaging-sw.js

js dailycaller.com collected 2026-10-01 07:14:16 UTC 2,854 bytes, 80 lines download raw bytes

1// Here is is the code snippet to initialize Firebase Messaging in the Service
2// Worker when your app is not hosted on Firebase Hosting.
3
4// Give the service worker access to Firebase Messaging.
5// Note that you can only use Firebase Messaging here. Other Firebase libraries
6// are not available in the service worker.
7importScripts('https://www.gstatic.com/firebasejs/11.6.1/firebase-app-compat.js')
8importScripts(
9  'https://www.gstatic.com/firebasejs/11.6.1/firebase-messaging-compat.js'
10)
11
12// Initialize the Firebase app in the service worker by passing in
13// your app's Firebase config object.
14// https://firebase.google.com/docs/web/setup#config-object
15
16const firebaseConfig = {
17  apiKey: "AIzaSyDUB2SjfgMarp0zW_cLFuAD9kEi_PXnpoo",
18  authDomain: "dailycaller-com.firebaseapp.com",
19  projectId: "dailycaller-com",
20  storageBucket: "dailycaller-com.firebasestorage.app",
21  messagingSenderId: "103679174461",
22  appId: "1:103679174461:web:cb3445cec29c0ab7afc754",
23  measurementId: "G-9N0VBZ63FS"
24}
25const dailyCallerUrl = "https://dailycaller.com"
26
27firebase.initializeApp(firebaseConfig)
28
29// Retrieve an instance of Firebase Messaging so that it can handle background
30// messages.
31const messaging = firebase.messaging()
32
33self.addEventListener('push', function (event) {
34  const data = event.data.json()
35  const options = {
36    body: data.notification.body,
37    icon: data.notification.icon,
38    click_action: data.notification.click_action ?? dailyCallerUrl,
39  }
40  event.waitUntil(
41    self.registration.showNotification(data.notification.title, options)
42  )
43})
44
45self.addEventListener('notificationclick', function(event) {
46  event.notification.close();
47
48  event.waitUntil(
49    clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function(clientList) {
50      for (const client of clientList) {
51        if (client.url.includes('dailycaller.com') && 'focus' in client) {
52          return client.focus();
53        }
54      }
55      return clients.openWindow(dailyCallerUrl);
56    })
57  );
58});
59
60// If you would like to customize notifications that are received in the
61// background (Web app is closed or not in browser focus) then you should
62// implement this optional method.
63// Keep in mind that FCM will still show notification messages automatically
64// and you should use data messages for custom notifications.
65// For more info see:
66// https://firebase.google.com/docs/cloud-messaging/concept-options
67messaging.onBackgroundMessage(function (payload) {
68  console.log(
69    '[firebase-messaging-sw.js] Received background message ',
70    payload
71  )
72  // Customize notification here
73  // const notificationTitle = 'Background Message Title'
74  // const notificationOptions = {
75  //   body: 'Background Message body.',
76  //   icon: '/firebase-logo.png',
77  // }
78
79  // self.registration.showNotification(notificationTitle, notificationOptions)
80})

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.