-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (45 loc) · 1.28 KB
/
index.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
async function init(waczFile, startingOrigin) {
const baseUrl = new URL(window.location);
baseUrl.hash = "";
const msg = {
msg_type: "addColl",
name: "proxyreplay",
type: "wacz",
file: {"sourceUrl": waczFile},
skipExisting: false,
extraConfig: {
"isLive": false,
"baseUrl": baseUrl.href,
"baseUrlHashReplay": true,
"proxyOrigin": new URL(startingOrigin).origin
},
};
const scope = "/";
if (!navigator.serviceWorker) {
showError("Sorry, Service Workers are not supported in this browser (or mode)");
return;
}
await navigator.serviceWorker.register("/sw.js?root=proxyreplay&proxyOriginMode=1", {scope});
await new Promise((resolve) => {
if (!navigator.serviceWorker.controller) {
navigator.serviceWorker.addEventListener("controllerchange", () => {
resolve();
});
} else {
resolve();
}
});
const p = new Promise((resolve) => {
navigator.serviceWorker.addEventListener("message", (event) => {
if (event.data.msg_type === "collAdded") {
resolve();
}
});
});
navigator.serviceWorker.controller.postMessage(msg);
await p;
window.location.reload();
}
function showError(msg) {
document.querySelector("#msg").innerText = "An Error Occured: " + msg;
}