I\'ve been trying to redirect users to the \"action\" part of Webpush coming from the backend (PHP).
return (new WebPushMessage)
->title(\'Title\'
If you want to have actions, and each action with a different url, here is my fix.
this.scope.addEventListener('notificationclick', (event) => {
event.notification.close();
var payload = event.notification.data;
var url = payload.url;
if (event.action && payload.actions && payload.actions.length) {
var actions = payload.actions.filter(x => x.action == event.action);
if (actions.length && actions[0].url) {
url = actions[0].url;
}
}
if (clients.openWindow && url) {
event.waitUtil(clients.openWindow(url));
}
});