summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/thirdparty/sw.js
blob: ed91f333bf04e2d79fb626f537b8321e72c033c8 (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
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" },
      })
    );
  }
});