PageSourceSearch

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

js worldstar.com collected 2026-09-25 14:34:24 UTC 3,439 bytes, 112 lines download raw bytes

1/* eslint-disable */
2importScripts(
3  'https://www.gstatic.com/firebasejs/9.18.0/firebase-app-compat.js',
4);
5importScripts(
6  'https://www.gstatic.com/firebasejs/9.18.0/firebase-messaging-compat.js',
7);
8
9const AUTHORIZED_SUBDOMAINS = [
10  'localhost',
11  'stage',
12  'v2-staging',
13  'v2',
14  'preview',
15  'preview-staging',
16  'preview-localhost',
17];
18
19const defaultConfig = {
20  apiKey: 'AIzaSyCHcbax-cz17PSX-2PsHgLcR4SI6RK9B1A',
21  authDomain: 'auth.worldstarhiphop.com',
22  databaseURL: 'https://wshh-b00d4.firebaseio.com',
23  projectId: 'wshh-b00d4',
24  storageBucket: 'wshh-b00d4.appspot.com',
25  messagingSenderId: '291183115057',
26  appId: '1:291183115057:web:9e4524f783be0c3d3f0e10',
27  measurementId: 'G-HM4QS6BBEL',
28};
29
30firebase.initializeApp(defaultConfig);
31let messaging;
32try {
33  messaging = firebase.messaging.isSupported() ? firebase.messaging() : null;
34} catch (err) {
35  console.error('Failed to initialize Firebase Messaging', err);
36}
37
38// To display background notifications
39if (messaging) {
40  try {
41    // This works just for push notifications sent by Backend.
42    // Please don't send them from the Firebase console. If you send them via the console, you will get an error.
43    // The user is going to receive the push notification twice.
44    // https://stackoverflow.com/questions/66697332/firebase-web-push-notifications-is-triggered-twice-when-using-onbackgroundmessag
45    messaging.onBackgroundMessage((payload) => {
46      if (!payload?.data) {
47        return;
48      }
49
50      const notificationTitle = 'Worldstar';
51      const notificationOptions = {
52        body: payload.data?.body,
53        tag: payload.data?.body, // tag is added to ovverride the notification with latest update
54        icon: payload.data?.imageURL,
55        data: {
56          url: payload.data?.url, // This should contain the URL you want to open
57        },
58      };
59
60      // Skip push notifications sent via the firebase console.
61      if (payload?.collapseKey) {
62        return new Promise(function (resolve, reject) {});
63      } else {
64        self.registration.showNotification(
65          notificationTitle,
66          notificationOptions,
67        );
68      }
69    });
70  } catch (err) {
71    console.error('push notification error:', err);
72  }
73}
74
75function getSubdomain(hostName) {
76  if (!hostName) return '';
77  const hostnameParts = hostName.split('.');
78  const subdomain = hostnameParts.length > 2 ? hostnameParts[0] : '';
79  return subdomain && AUTHORIZED_SUBDOMAINS.includes(subdomain)
80    ? `${subdomain}.`
81    : '';
82}
83
84// Handling Notification click
85self.addEventListener('notificationclick', (event) => {
86  event?.notification.close(); // Closing the notification when clicked
87  const subdomain = getSubdomain(self.location.hostname);
88  const urlToOpen =
89    `https://${subdomain || ''}${event?.notification?.data?.url?.replace(
90      'https://',
91      '',
92    )}?notification=1` || 'https://worldstarhiphop.com/discover';
93
94  event.waitUntil(
95    clients
96      .matchAll({
97        type: 'window',
98      })
99      .then((windowClients) => {
100        // Check if there is already a window/tab open with the target URL
101        for (const client of windowClients) {
102          if (client.url === urlToOpen && 'focus' in client) {
103            return client.focus();
104          }
105        }
106        // If not, open a new window/tab with the target URL
107        if (clients.openWindow) {
108          return clients.openWindow(urlToOpen);
109        }
110      }),
111  );
112});

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.