From 41113c04f50f6677844f3248d65fcfdbc67a2b58 Mon Sep 17 00:00:00 2001 From: Kai Vandivier <49666798+KaiVandivier@users.noreply.github.com> Date: Thu, 24 Nov 2022 14:31:26 +0100 Subject: [PATCH] fix(pwa): only count clients in scope (#760) --- pwa/src/service-worker/utils.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pwa/src/service-worker/utils.js b/pwa/src/service-worker/utils.js index 8e71063b8..2f018eef1 100644 --- a/pwa/src/service-worker/utils.js +++ b/pwa/src/service-worker/utils.js @@ -104,15 +104,23 @@ export async function getClientsInfo(event) { // Include uncontrolled clients: necessary to know if there are multiple // tabs open upon first SW installation - const clientsList = await self.clients.matchAll({ - includeUncontrolled: true, - }) + const filteredClientsList = await self.clients + .matchAll({ + includeUncontrolled: true, + }) + .then((clientsList) => + // Filter to just clients within this SW scope, because other clients + // on this domain but outside of SW scope are returned otherwise + clientsList.filter((client) => + client.url.startsWith(self.registration.scope) + ) + ) self.clients.get(clientId).then((client) => { client.postMessage({ type: swMsgs.clientsInfo, payload: { - clientsCount: clientsList.length, + clientsCount: filteredClientsList.length, }, }) })