summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/thirdparty/sw.js
blob: ea844e8f2beac555f13f3980d8fb74f0627d3741 (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
self.addEventListener("fetch", function(event) {
  dump("fetch " + event.request.url + "\n");
  if (event.request.url.includes("iframe2.html")) {
    var body =
      "<script>" +
      "window.parent.postMessage({" +
      "source: 'iframe', status: 'swresponse'" +
      "}, '*');" +
      "var w = new Worker('worker.js');" +
      "w.onmessage = function(evt) {" +
      "window.parent.postMessage({" +
      "source: 'worker'," +
      "status: evt.data," +
      "}, '*');" +
      "};" +
      "</script>";
    event.respondWith(
      new Response(body, {
        headers: { "Content-Type": "text/html" },
      })
    );
    return;
  }
  if (event.request.url.includes("worker.js")) {
    var body = "self.postMessage('worker-swresponse');";
    event.respondWith(
      new Response(body, {
        headers: { "Content-Type": "application/javascript" },
      })
    );
    return;
  }
});