summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/data/file_page_xhr.html
blob: 387b5285f596059b9e5e107848b59cfb6e33d558 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>

<script>
"use strict";

addEventListener("message", async function(event) {
  const url = new URL("/return_headers.sjs", location).href;

  const webpageFetchResult = await fetch(url).then(res => res.json());
  const webpageXhrResult = await new Promise(resolve => {
    const req = new XMLHttpRequest();
    req.open("GET", url);
    req.addEventListener("load", () => resolve(JSON.parse(req.responseText)),
                         {once: true});
    req.addEventListener("error", () => resolve({error: "webpage xhr failed to complete"}),
                         {once: true});
    req.send();
  });

  postMessage({
    type: "testPageGlobals",
    webpageFetchResult,
    webpageXhrResult,
  }, "*");
}, {once: true});
</script>

</body>
</html>