summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/sw.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/sw.js')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/sw.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/sw.js b/packages/meshbay-hub/src/meshbay_hub/static/sw.js
index d0a8805..119687d 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/sw.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/sw.js
@@ -29,6 +29,11 @@ self.addEventListener('message', (event) => {
readable: data.readable,
filename: data.filename || 'download',
size: Number(data.size) || 0,
+ // Answered when the navigation actually reaches us. The page waits for it:
+ // if this worker is never asked for the URL — an uncontrolled page, or a
+ // browser that blocks a download from a hidden iframe — nothing drains the
+ // stream and the page's first write blocks for good.
+ port: data.port || null,
});
// A tab that is closed before it navigates would leave a stream here for the
// life of the worker.
@@ -44,6 +49,9 @@ self.addEventListener('fetch', (event) => {
const entry = pending.get(url.pathname.slice(PREFIX.length));
if (!entry) return;
pending.delete(url.pathname.slice(PREFIX.length));
+ if (entry.port) {
+ try { entry.port.postMessage({ type: 'mbdl-serving', id: url.pathname }); } catch { /* gone */ }
+ }
const headers = {
'Content-Type': 'application/octet-stream',