am getting error "messaging.onBackgroundMessage is not a function at firebase-messaging-sw.js:56:11"
Service worked is getting registered successfully but when I try to send notification, it getting delivered but not with the title and body. Am thinking that this error might be the reason for that.
Help me out in solving this. Thanks. Below is my service worker code :
importScripts('https://www.gstatic.com/firebasejs/3.5.0/firebase-app.js')
importScripts('https://www.gstatic.com/firebasejs/3.5.0/firebase-messaging.js')
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('../firebase-messaging-sw.js')
.then(function (registration) {
console.log('Registration successful, scope is:', registration.scope)
})
.catch(function (err) {
console.log('Service worker registration failed, error:', err)
})
}
firebase.initializeApp({
messagingSenderId: '576646393071',
})
const messaging = firebase.messaging()
messaging.onBackgroundMessage((payload) => {
console.log(
'[firebase-messaging-sw.js] Received background message ',
payload,
)
// Customize notification here
const notificationTitle = 'Background Message Title'
const notificationOptions = {
body: 'Background Message body.',
icon: '/firebase-logo.png',
}
self.registration.showNotification(notificationTitle, notificationOptions)
})