OLD | NEW |
| (Empty) |
1 self.onfetch = function(e) { | |
2 if (e.request.url.indexOf('clients-get-frame.html') >= 0 || | |
3 e.request.url.indexOf('clients-get-client-types') >= 0) { | |
4 // On navigation, the client id should be null. | |
5 if (e.clientId === null) { | |
6 e.respondWith(fetch(e.request)); | |
7 } else { | |
8 e.respondWith(Response.error()); | |
9 } | |
10 return; | |
11 } | |
12 e.respondWith(new Response(e.clientId)); | |
13 }; | |
14 | |
15 self.onmessage = function(e) { | |
16 var port = e.data.port; | |
17 var client_ids = e.data.clientIds; | |
18 var message = []; | |
19 | |
20 e.waitUntil(Promise.all( | |
21 client_ids.map(function(client_id) { | |
22 return self.clients.get(client_id); | |
23 })) | |
24 .then(function(clients) { | |
25 // No matching client for a given id or a matched client is off-origin | |
26 // from the service worker. | |
27 if (clients.length == 1 && clients[0] == undefined) { | |
28 port.postMessage(clients[0]); | |
29 } else { | |
30 clients.forEach(function(client) { | |
31 if (client instanceof Client) { | |
32 message.push([client.visibilityState, | |
33 client.focused, | |
34 client.url, | |
35 client.frameType]); | |
36 } else { | |
37 message.push(client); | |
38 } | |
39 }); | |
40 port.postMessage(message); | |
41 } | |
42 })); | |
43 }; | |
OLD | NEW |