Skip to content

Commit

Permalink
Fix: Initialize Firebase App in firebase-messaging-sw.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lokeshwar777 committed Mar 31, 2024
1 parent 0379f19 commit a16e946
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions public/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ try {
importScripts(
"https://www.gstatic.com/firebasejs/9.0.0/firebase-messaging-compat.js"
);
// firebase.initializeApp(firebaseConfigObject);
var firebaseConfigObject = {
apiKey: "API_KEY",
authDomain: "PROJECT_ID.firebaseapp.com",
databaseURL: "https://DATABASE_NAME.firebaseio.com",
projectId: "PROJECT_ID",
storageBucket: "PROJECT_ID.appspot.com",
messagingSenderId: "SENDER_ID",
appId: "APP_ID",
measurementId: "G-MEASUREMENT_ID",
};
firebase.initializeApp(firebaseConfigObject);
} catch (e) {
importScripts("/__/firebase/7.15.0/firebase-app.js");
importScripts("/__/firebase/7.15.0/firebase-messaging.js");
Expand All @@ -29,7 +39,7 @@ if (firebase.messaging.isSupported()) {
image: payload.notification.image
};

const promiseChain = clients
const promiseChain = self.clients
.matchAll({
type: "window",
includeUncontrolled: true
Expand All @@ -41,7 +51,7 @@ if (firebase.messaging.isSupported()) {
}
})
.then(() => {
return registration.showNotification(
return self.registration.showNotification(
notificationTitle,
notificationOptions
);
Expand Down

0 comments on commit a16e946

Please sign in to comment.