From be4e05b8caa52dacf1c1251552527f4b800752b5 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 16 Aug 2021 20:42:25 +0300 Subject: [PATCH] Notifications: Fix new window always popping up on click (#1392) --- src/serviceWorker/pushNotification.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/serviceWorker/pushNotification.ts b/src/serviceWorker/pushNotification.ts index 07518e2d4..d0ffde01b 100644 --- a/src/serviceWorker/pushNotification.ts +++ b/src/serviceWorker/pushNotification.ts @@ -163,12 +163,14 @@ async function focusChatMessage(client: WindowClient, data: { chatId?: number; m } export function handleNotificationClick(e: NotificationEvent) { - const appUrl = self.location.href.replace('serviceWorker.js', ''); + const appUrl = new URL(self.registration.scope).origin; e.notification.close(); // Android needs explicit close. const { data } = e.notification; const notifyClients = async () => { const clients = await self.clients.matchAll({ type: 'window' }) as WindowClient[]; - const clientsInScope = clients.filter((client) => client.url === self.registration.scope); + const clientsInScope = clients.filter((client) => { + return new URL(client.url).origin === appUrl; + }); e.waitUntil(Promise.all(clientsInScope.map((client) => { clickBuffer[client.id] = data; return focusChatMessage(client, data);