#1582, #1585: guard web serviceWorker against SecurityError in opaque contexts

In sandboxed iframes without allow-same-origin (or other opaque origin contexts), accessing `navigator.serviceWorker` throws a SecurityError synchronously.

- Guard `info().serviceWorker` evaluation with try/catch to return `false` on SecurityError (#1585)
- Guard PWA serviceWorker registration with try/catch to let the web app load rather than hanging (#1582)
- Add contributor credit entry for @krinry in `contributors/people.toml`
This commit is contained in:
krinry
2026-10-16 18:09:38 +05:30
parent 8f02f52a44
commit f13429010f
2 changed files with 19 additions and 3 deletions
+15 -3
View File
@@ -71,7 +71,13 @@
...ec.info(),
crossOriginIsolated: self.crossOriginIsolated,
webgpu: !!navigator.gpu,
serviceWorker: !!(navigator.serviceWorker && navigator.serviceWorker.controller),
serviceWorker: (() => {
try {
return !!(navigator.serviceWorker && navigator.serviceWorker.controller);
} catch {
return false;
}
})(),
load: window.effectcraftLoad,
}),
// Browser storage (OPFS / IndexedDB): save without downloading, list, remove, wait for writes.
@@ -83,8 +89,14 @@
workerFrameCheck: (params) => ec.workerFrameCheck(params ?? {}).then(JSON.parse),
};
// Offline start and install (PWA): the service worker caches the app's files.
if ("serviceWorker" in navigator && !new URLSearchParams(location.search).has("nosw")) {
navigator.serviceWorker.register("sw.js").catch((e) => console.warn("service worker:", e));
if (!new URLSearchParams(location.search).has("nosw")) {
try {
if ("serviceWorker" in navigator && navigator.serviceWorker) {
navigator.serviceWorker.register("sw.js").catch((e) => console.warn("service worker:", e));
}
} catch (e) {
console.warn("service worker:", e);
}
}
try {
// Compile once: the page and its render workers instantiate the same module.
+4
View File
@@ -87,3 +87,7 @@ sync_github_name = false
real_name = "Marco Arnulfo"
display_name = "Marco Arnulfo"
sync_github_name = false
[people.krinry]
display_name = "krinry"
sync_github_name = true