client-url-creation-url-sw.js (800B)
1 // This is a service worker script used by the client-url-creation-url test. 2 // It exists only to look up the client URL of the test iframe and send it back 3 // to the test page. 4 addEventListener('message', message_event => { 5 const port = message_event.data.port; 6 7 const async_work = async () => { 8 try { 9 const clients = await self.clients.matchAll(); 10 11 // In our test there should be exactly one client that is our test 12 // navigation iframe. 13 if (clients.length == 1) { 14 const client = clients[0]; 15 port.postMessage(client.url); 16 } else { 17 port.postMessage(`error: expected 1 client, not ${clients.length}`); 18 } 19 } catch (error) { 20 port.postMessage(`error: ${error.message}`); 21 } 22 }; 23 message_event.waitUntil(async_work()); 24 });