blob: 2a536128fa85572fcfe60d7c9680646de61b529f (
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
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script>
function waitForState(worker, state, context) {
return new Promise(resolve => {
function onStateChange() {
if (worker.state === state) {
worker.removeEventListener("statechange", onStateChange);
resolve(context);
}
}
// First add an event listener, so we won't miss any change that happens
// before we check the current state.
worker.addEventListener("statechange", onStateChange);
// Now check if the worker is already in the desired state.
onStateChange();
});
}
(async function () {
dump("[Dimi]register sw...\n");
let reg = await navigator.serviceWorker.register("sw_worker.js", {scope: "."});
await waitForState(reg.installing, "activated", reg);
window.parent.postMessage({status: "registrationdone"}, "*");
})();
</script>
</head>
<html>
|