protocol-handler-service-worker.js (843B)
1 // This service worker script should be used by the 2 // protocol-handler-unregister.https.html test to detect unregistered URL 3 // schemes. 4 self.addEventListener('message', async eventInfo => { 5 let success = false; 6 let message = null; 7 8 try { 9 const {clientUrlMatch, navigationUrl} = eventInfo.data; 10 const client = (await clients.matchAll()).find( 11 client => client.url === clientUrlMatch); 12 13 if (client) { 14 try { 15 await client.navigate(navigationUrl); 16 success = true; 17 } catch (navigateException) { 18 message = `navigate failure: ${navigateException.name}`; 19 } 20 } else { 21 message = `no client found matching ${clientUrlMatch}`; 22 } 23 } catch (otherException) { 24 message = `other failure: ${otherException.name}`; 25 } 26 27 eventInfo.source.postMessage({success, message}); 28 });