DEV: allow non focused tab to be primary tab in service worker (#29516)

Follow up to #29388 - when there are no clients in focus, we should take the first visible client as the primary tab.
This commit is contained in:
David Battersby 2024-11-01 09:42:33 +04:00 committed by GitHub
parent 9c17588f6a
commit 8aa4c39c3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -132,9 +132,11 @@ self.addEventListener('message', function(event) {
event.waitUntil(
self.clients.matchAll().then(function(clients) {
const activeClient = clients.find(client => client.focused) || clients.find(client => client.visibilityState === "visible");
clients.forEach(function(client) {
client.postMessage({
primaryTab: client.focused
primaryTab: client.id === activeClient?.id
});
});
})