summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/private-network-access/resources/fetcher.js
blob: 3a1859876d406cebe9a2bbc63952d019ddc5ed06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
async function doFetch(url) {
  const response = await fetch(url);
  const body = await response.text();
  return {
    status: response.status,
    body,
  };
}

async function fetchAndPost(url) {
  try {
    const message = await doFetch(url);
    self.postMessage(message);
  } catch(e) {
    self.postMessage({ error: e.name });
  }
}

const url = new URL(self.location.href).searchParams.get("url");
fetchAndPost(url);