Level 80
@mallaury The console is telling you an exception was thrown. So wrap your code in a try/catch block and you'll be able to catch the exception is see what the error actually is
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I configured a FCM system for my laravel website. But I can not register the serviceworker...
TypeError: ServiceWorker script at https://localhost/firebase-messaging-sw.js for scope https://localhost/ threw an exception during script evaluation.
Here is my serviceworker code :
// Service Worker
importScripts('https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/10.7.1/firebase-messaging.js');
const firebaseConfig = {
apiKey: "****************************",
authDomain: "***********.firebaseapp.com",
projectId: "***********.",
storageBucket: "***********..appspot.com",
messagingSenderId: "***********",
appId: "****************************",
};
firebase.initializeApp(firebaseConfig);
const messaging = firebase.getMessaging();
messaging.onBackgroundMessage(payload => {
const notificationTitle = 'Background Message Title';
const notificationOptions = {
body: notificationTitle,
icon: '<>'
};
self.registration.showNotification(notificationTitle, notificationOptions);
});
self.addEventListener('error', function (event) {
console.error('Erreur dans le service worker:', event.error);
});
I do not know how to debug this code while I do not have any log.
Thanks for your help!
Please or to participate in this conversation.