dynamic-import-given-url-worker.js (758B)
1 // This worker dynamically imports the script URL sent by postMessage(), and 2 // sends back an error name if the dynamic import fails. 3 if ('DedicatedWorkerGlobalScope' in self && 4 self instanceof DedicatedWorkerGlobalScope) { 5 self.onmessage = msg_event => { 6 import(msg_event.data) 7 .then(module => postMessage(module.meta_url)) 8 .catch(e => postMessage(e.name)); 9 }; 10 } else if ( 11 'SharedWorkerGlobalScope' in self && 12 self instanceof SharedWorkerGlobalScope) { 13 self.onconnect = connect_event => { 14 const port = connect_event.ports[0]; 15 port.onmessage = msg_event => { 16 import(msg_event.data) 17 .then(module => port.postMessage(module.meta_url)) 18 .catch(e => port.postMessage(e.name)); 19 }; 20 }; 21 }