From 6385fc236ead6d156ef2ff2defd7f43586b99177 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 6 Mar 2026 23:28:02 -0800 Subject: fix notification click to reuse existing tab Co-Authored-By: Claude Opus 4.6 --- src/service-worker.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/service-worker.js b/src/service-worker.js index ca0d472b..89f4cf47 100644 --- a/src/service-worker.js +++ b/src/service-worker.js @@ -127,17 +127,19 @@ self.addEventListener("push", (event) => { self.addEventListener("notificationclick", (event) => { event.notification.close(); - const url = event.notification.data.url || "/"; + const path = event.notification.data.url || "/"; + const target = new URL(path, self.location.origin).href; event.waitUntil( clients.matchAll({ type: "window", includeUncontrolled: true }).then((clientList) => { for (const client of clientList) { - if (client.url === url && "focus" in client) { + if (new URL(client.url).origin === self.location.origin && "focus" in client) { + client.navigate(target); return client.focus(); } } if (clients.openWindow) { - return clients.openWindow(url); + return clients.openWindow(target); } }), ); -- cgit v1.2.3