Source code

Revision control

Copy as Markdown

Other Tools

<!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>