chromium/chrome/test/data/workers/fetch_from_worker.html

<script>
  const params = new URLSearchParams(location.search);
  const worker = new Worker(
      params.has('script') ? params.get('script') : 'fetch_from_worker.js');

  let resolve;
  worker.onmessage = e => { resolve(e.data); };

  function fetch_from_worker(url) {
    let p = new Promise(r => { resolve = r; });
    worker.postMessage({url});
    return p;
  }
</script>