clients-matchall-worker.js (1560B)
1 self.onmessage = function(e) { 2 var port = e.data.port; 3 var options = e.data.options; 4 5 e.waitUntil(self.clients.matchAll(options) 6 .then(function(clients) { 7 var message = []; 8 clients.forEach(function(client) { 9 var frame_type = client.frameType; 10 if (client.url.indexOf('clients-matchall-include-uncontrolled.https.html') > -1 && 11 client.frameType == 'auxiliary') { 12 // The test tab might be opened using window.open() by the test framework. 13 // In that case, just pretend it's top-level! 14 frame_type = 'top-level'; 15 } 16 if (e.data.includeLifecycleState) { 17 message.push({visibilityState: client.visibilityState, 18 focused: client.focused, 19 url: client.url, 20 lifecycleState: client.lifecycleState, 21 type: client.type, 22 frameType: frame_type}); 23 } else { 24 message.push([client.visibilityState, 25 client.focused, 26 client.url, 27 client.type, 28 frame_type]); 29 } 30 }); 31 // Sort by url 32 if (!e.data.disableSort) { 33 message.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; }); 34 } 35 port.postMessage(message); 36 }) 37 .catch(e => { 38 port.postMessage('clients.matchAll() rejected: ' + e); 39 })); 40 };