Enforce stale core contracts in the worker without native startup I/O

This commit is contained in:
Jonathan Sykes
2026-10-08 10:05:38 +08:00
parent 57edb410c3
commit 97eb31e732
7 changed files with 40 additions and 13 deletions

View File

@@ -27,12 +27,11 @@
return {bytes,digest};
}
async function start() {
if(!manifest.appCache || !root.crypto?.subtle || (!root.Lazy.captureApp&&!root.navigator?.serviceWorker?.controller))return external(key);
if(!manifest.appCache || !root.crypto?.subtle || !root.Lazy.captureApp)return external(key);
const expected=manifest.files['/app.js'].h;
let cache;
try { cache=await root.caches?.open('ytplayer-assets'); } catch {}
let response=await cache?.match(key);
if(!root.Lazy.captureApp && response?.ok && response.headers.get('X-Asset-Hash')===expected)return external(key);
if(!response || response.headers.get('X-Asset-Hash')!==expected) {
try { response=await (root.Lazy.appResponse || root.fetch(key,{credentials:'same-origin'})); } catch {}
}
@@ -57,7 +56,6 @@
// CacheStorage may share a full quota with saved music. Never remove data
// to make room; boot from these verified bytes even if caching is refused.
try { await cache?.put(key,response); } catch(error) { root.console.warn('[app-cache]',error.message); }
if(!root.Lazy.captureApp)return external(key);
const node=doc.createElement('script');node.textContent=new root.TextDecoder().decode(bytes);
execute(node);
}