Skip to content

Commit

Permalink
fix(pwa): only count clients in scope (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier authored Nov 24, 2022
1 parent 0e11e56 commit 41113c0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pwa/src/service-worker/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
})
})
Expand Down

0 comments on commit 41113c0

Please sign in to comment.