LibWeb: Add ServiceWorker job registration and execution

Now we can register jobs and they will be executed on the event loop
"later". This doesn't feel like the right place to execute them, but
the spec needs some updates in this regard anyway.
This commit is contained in:
Andrew Kaster 2024-10-03 20:17:49 -06:00 committed by Andreas Kling
commit 29416befe6
Notes: github-actions[bot] 2024-10-04 05:09:03 +00:00
8 changed files with 281 additions and 20 deletions

View file

@ -2,19 +2,22 @@
<script src="../include.js"></script>
<script>
asyncTest(done => {
setTimeout(() => {
// We need to do this spoofing later in the event loop so that we don't end up
// telling the test runner the wrong URL in page_did_finish_loading.
spoofCurrentURL("https://example.com/service-worker-register.html");
spoofCurrentURL("https://example.com/service-worker-register.html");
let swPromise = navigator.serviceWorker.register("service-worker.js");
let swPromise = navigator.serviceWorker.register("service-worker.js");
swPromise
.then(registration => {
println(`ServiceWorker registration successful with scope: ${registration.scope}`);
done();
})
.catch(err => {
println(`ServiceWorker registration failed: ${err}`);
done();
});
swPromise
.then(registration => {
println(`ServiceWorker registration successful with scope: ${registration.scope}`);
done();
})
.catch(err => {
println(`ServiceWorker registration failed: ${err}`);
done();
});
}, 0);
});
</script>