blob: 0ecd801106be0606a4633ebfdee727a3ea3905f6 (
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;
}
});
|