Hi, You don't use "swPush.notificationClicks" to handle click?
Yes you can use. Here I'm sending data with some default operations which are there in service worker file after you build your angular app.
You can but when the webpage is open.
If the webpage isn't open you need to modify your service worker and add this (this only works for angular ngsw-worker.js file)
// line 1914 this.scope.addEventListener('notificationclick', (event) => { event.notification.close(); // Get all the Window clients event.waitUntil(clients.matchAll({ includeUncontrolled: true, type: 'window' }).then(clientsArr => { // If a Window tab matching the targeted URL already exists, focus that; const hadWindowToFocus = clientsArr.some(windowClient => { windowClient.url === event.notification.data[event.action].url ? (windowClient.focus(), true) : false }); // Otherwise, open a new tab to the applicable URL and focus it. if (!hadWindowToFocus) { clients.openWindow(event.notification.data[event.action].url).then(windowClient => { if (windowClient) { windowClient.focus(); console.log('[Service Worker] - Notification click Received.', event); } }); } })); this.onClick(event); });
sorry if i post code in comments, this is my first comment :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi, You don't use "swPush.notificationClicks" to handle click?
Yes you can use. Here I'm sending data with some default operations which are there in service worker file after you build your angular app.
You can but when the webpage is open.
If the webpage isn't open you need to modify your service worker and add this (this only works for angular ngsw-worker.js file)
// line 1914
this.scope.addEventListener('notificationclick', (event) => {
event.notification.close();
// Get all the Window clients
event.waitUntil(clients.matchAll({ includeUncontrolled: true, type: 'window' }).then(clientsArr => {
// If a Window tab matching the targeted URL already exists, focus that;
const hadWindowToFocus = clientsArr.some(windowClient => { windowClient.url === event.notification.data[event.action].url ? (windowClient.focus(), true) : false });
// Otherwise, open a new tab to the applicable URL and focus it.
if (!hadWindowToFocus) {
clients.openWindow(event.notification.data[event.action].url).then(windowClient => {
if (windowClient) {
windowClient.focus();
console.log('[Service Worker] - Notification click Received.', event);
}
});
}
}));
this.onClick(event);
});
sorry if i post code in comments, this is my first comment :)