IgorVader
@IgorVader

Сhrome notification не открывает сайт?

Успешно получаю токен для отправки push уведомления в google chrome
Делаю отправку уведомление на пк с windows 10
$request_body = [
                'registration_ids' => $arTokenUsers,
                'notification' => [
                    'title' => $title,
                    'body' => $body,
                    'icon' => $icon,
                    'click_action' => $click_action,
                ],
            ];

в переменную $click_action передаю ссылку , но при клике по уведомлению не открываются сайт

Итоговый вопрос : как открывать сайт по клику на уведомлению

UPDATE
в корне сайта есть файл firebase-messaging-sw.js
данный файл вызывается когда приходит уведомление
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);
    }));
});
  • Вопрос задан
  • 244 просмотра
Решения вопроса 1
IgorVader
@IgorVader Автор вопроса
в корне сайта есть файл firebase-messaging-sw.js
данный файл вызывается когда приходит уведомление
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);
    }));
});
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы