blob: 0f08ba74e37b6cd552f8147369ddcb7ca8a428a6 (
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
|
function sendResponseToParent(response) {
return `
<!DOCTYPE html>
<script>
window.parent.postMessage({status: "done", data: "${response}"}, "*");
</script>
`;
}
self.addEventListener("fetch", function(event) {
if (event.request.url.indexOf("index.html") >= 0) {
var response = "good";
try {
importScripts("http://example.org/tests/dom/workers/test/foreign.js");
} catch(e) {
dump("Got error " + e + " when importing the script\n");
}
if (response === "good") {
try {
importScripts("/tests/dom/workers/test/redirect_to_foreign.sjs");
} catch(e) {
dump("Got error " + e + " when importing the script\n");
}
}
event.respondWith(new Response(sendResponseToParent(response),
{headers: {'Content-Type': 'text/html'}}));
}
});
|