Answer the question
In order to leave comments, you need to log in
Chrome notification not opening site?
I successfully receive a token to send a push notification to google chrome
I send a notification to a windows 10 PC
$request_body = [
'registration_ids' => $arTokenUsers,
'notification' => [
'title' => $title,
'body' => $body,
'icon' => $icon,
'click_action' => $click_action,
],
];
self.addEventListener('notificationclick', function(event) {
console.log('On notification click: ', event.notification.tag);
// Android doesn't close the notification when you click on it
// See: http://crbug.com/463146
event.notification.close();
event.waitUntil(clients.matchAll({ type: 'window' }).then(clientsArr => {
const hadWindowToFocus = clientsArr.some(windowClient => windowClient.url === event.notification.url ? (windowClient.focus(), true) : false);
// Otherwise, open a new tab to the applicable URL and focus it.
if (!hadWindowToFocus) clients.openWindow(event.notification.url ).then(windowClient => windowClient ? windowClient.focus() : null);
}));
});
Answer the question
In order to leave comments, you need to log in
in the root of the site there is a file firebase-messaging-sw.js
this file is called when a notification arrives
self.addEventListener('notificationclick', function(event) {
console.log('On notification click: ', event.notification.tag);
// Android doesn't close the notification when you click on it
// See: http://crbug.com/463146
event.notification.close();
event.waitUntil(clients.matchAll({ type: 'window' }).then(clientsArr => {
const hadWindowToFocus = clientsArr.some(windowClient => windowClient.url === event.notification.url ? (windowClient.focus(), true) : false);
// Otherwise, open a new tab to the applicable URL and focus it.
if (!hadWindowToFocus) clients.openWindow(event.notification.url ).then(windowClient => windowClient ? windowClient.focus() : null);
}));
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question