Reputation: 445
This code show my notifications, all is good, but in the notification popup i see no icon, and click notification just close it and not open window. This code i get from this (Google's tutorial).
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': 'my id'
});
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
var title = '';
var body = '';
if(payload && payload.notification) {
if(payload.notification.body) {
body = payload.notification.body;
if(payload.notification.title) {
title = payload.notification.title;
}
}
}
return self.registration.showNotification(title, {
body: body,
icon: '/img/logos/logo-short-blue.png'
});
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
var appUrl = '/' + event.notification.data.actionUrl;
event.waitUntil(clients.matchAll({
includeUncontrolled: true,
type: 'window'
}).then( activeClients => {
if (activeClients.length > 0) {
activeClients[0].navigate(appUrl);
activeClients[0].focus();
} else {
clients.openWindow(appUrl);
}
})
);
});
Upvotes: 4
Views: 2103
Reputation: 216
from google's guide :
Click actions support only secure HTTPS URLs.
Upvotes: 1
Reputation: 445
You have to use click_action
as url and icon
fields on server side, while forming payload of push-message.
Upvotes: 1