1%(import)s 2 3if ('DedicatedWorkerGlobalScope' in self && 4 self instanceof DedicatedWorkerGlobalScope) { 5 self.onmessage = event => onMessageFromParent(event, self); 6} else if ('SharedWorkerGlobalScope' in self && 7 self instanceof SharedWorkerGlobalScope) { 8 onconnect = event => { 9 const port = event.ports[0]; 10 port.onmessage = event => onMessageFromParent(event, port); 11 }; 12} 13 14// Receive a message from the parent and start the test. 15function onMessageFromParent(event, port) { 16 const configurationError = "%(error)s"; 17 if (configurationError.length > 0) { 18 port.postMessage({error: configurationError}); 19 return; 20 } 21 22 invokeRequest(event.data.subresource, 23 event.data.sourceContextList) 24 .then(result => port.postMessage(result)) 25 .catch(e => { 26 const message = (e.error && e.error.stack) || e.message || "Error"; 27 port.postMessage({error: message}); 28 }); 29} 30