Answer the question
In order to leave comments, you need to log in
Why are there two notifications in the service worker?
Good day, I don’t understand a little why two notifications come from the service worker,
the worker code itself:
importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-messaging.js');
firebase.initializeApp({
'messagingSenderId': 'sender id'
});
var messaging = firebase.messaging();
self.addEventListener('push', function(event) {
var json_data = JSON.parse(event.data.text());
console.log('[Service Worker] Push JSON:', json_data);
var not_title = json_data.notification.title;
var not_data = {
body: json_data.notification.body.length > 100 ? json_data.notification.body.substr(0, 97) + '...' : json_data.notification.body,
icon: 'path to icon',
vibrate: [200, 100, 200, 100, 200, 100, 200],
click_action: json_data.notification.click_action
};
if(json_data.data) {
// not_data.badge = payload.notification.data.image ? payload.notification.data.image : '';
not_data.image = json_data.data.image ? json_data.data.image : '';
}
event.waitUntil(self.registration.showNotification(not_title, not_data));
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question