Skip to content

Commit

Permalink
[#67324] Make service worker registration optional
Browse files Browse the repository at this point in the history
  • Loading branch information
GPlaczek committed Oct 25, 2024
1 parent 9e994c1 commit 63901ac
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/jswasi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Jswasi {
println("Purge complete");
}

public async init(config?: KernelConfig): Promise<void> {
public async init(config?: KernelConfig, useServiceWorker: boolean = true): Promise<void> {
await this.devFsPromise;

if (!navigator.storage.getDirectory) {
Expand All @@ -88,22 +88,29 @@ export class Jswasi {
return;
}

this.__printk('Registering service worker');
if (!(await initServiceWorker())) {
this.__printk("Service Worker registration failed");
return;
if (useServiceWorker) {
this.__printk('Registering service worker');
if (!(await initServiceWorker())) {
this.__printk("Service Worker registration failed");
return;
}
}

// If SharedArrayBuffer is undefined then most likely, the service
// worker has not yet reloaded the page. In such case, stop further
// execution so that it is not abruptly interrupted by the page being
// reloaded.
if (typeof SharedArrayBuffer === 'undefined') {
this.__printk("SharedArrayBuffer undefined, reloading page");
// On chromium, window.location.reload sometimes does not work.
window.location.href = window.location.href;
if (useServiceWorker) {
this.__printk("SharedArrayBuffer undefined, reloading page");
// On chromium, window.location.reload sometimes does not work.
window.location.href = window.location.href;
} else {
this.__printk("SharedArrayBuffer undefined, aborting");
}
return;
}

if (config == undefined) {
this.__printk('Reading kernel config');
config = await getKernelConfig(this.topLevelFs);
Expand Down

0 comments on commit 63901ac

Please sign in to comment.