I
I
IgorVader2022-02-16 15:50:30
PHP
IgorVader, 2022-02-16 15:50:30

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,
                ],
            ];

I pass the link to the $click_action variable, but when the notification is clicked, the site does not open

Final question: how to open the site by clicking on the

UPDATE notification
in the root of the site there is a firebase-messaging-sw.js
file, 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);
    }));
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IgorVader, 2022-02-17
@IgorVader

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 question

Ask a Question

731 491 924 answers to any question