Repository navigation
feat(main): stream downloads through a first-party service worker (DSPX-159) - #1098
Draft
dmihalcik-virtru wants to merge 4 commits into
Draft
dmihalcik-virtru wants to merge 4 commits into
dmihalcik-virtru wants to merge 4 commits into
Conversation
Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
…PX-159) Replace StreamSaver, which routed downloads through a service worker on jimmywarting.github.io, with our own worker in web-app/public/sw.js. The page sends output to the worker over a MessagePort, one chunk per pull, and a hidden iframe opens the streamed attachment response. Backpressure from the browser's download manager reaches back to the SDK, so memory stays flat at any file size. The existing sw.js could not have worked: its origin check never matched, and it acknowledged chunks on enqueue, so nothing bounded its queue. Save As now uses the native showSaveFilePicker and is disabled where the browser lacks it, so native-file-system-adapter is gone too. Tests: - Add tests/sink.spec.ts, which exercises the sink with no platform and can run a large, paced download with SINK_TEST_BYTES and SINK_TEST_MIBPS. - Add playwright.moz-firefox.config.ts to run the suite on stock Firefox over WebDriver BiDi. Stock Firefox ignores Playwright's download folder, so specs now find files with downloadPath() from acts.ts. - huge.spec.ts now runs on WebKit too. It still skips Playwright's bundled Firefox, which keeps every response body in memory (DSPX-5084). Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Describe the design as built, consolidate the prototype findings, list follow-ups (DSPX-5084, DSPX-5246), tick the verified acceptance criteria, and record PR #1098. Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
X-Test Failure Reportopentdf-sdk-lib |
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
This replaces StreamSaver in the sample web-app with a first-party streaming download service worker (DSPX-159).
web-app/public/sw.jsis rewritten. The page registers each download over aMessagePort. A hidden iframe then opens<scope>__download__/<id>/<name>, and the worker answers that request with the stream as an attachment. The worker asks for one chunk each time its stream pulls, so backpressure from the browser's download manager reaches back to the SDK.web-app/src/downloadSink.tsis the page side,toFile(). It sends a 10 s keepalive while streaming, and errors and cancels propagate in both directions. If no worker answers within 5 s, it falls back to an in-memory Blob.showSaveFilePicker. It is disabled, with a tooltip, where the browser lacks it.streamsaver,@types/streamsaver, andnative-file-system-adapter.Why
jimmywarting.github.io/StreamSaver.js/mitm.htmlplus a service worker on that origin. It is also unmaintained.sw.jscould not have worked. Its origin check compared against'http://localhost:65432/', and an origin never has a trailing slash. It also acknowledged chunks when it queued them, not when the stream pulled them, so nothing bounded its queue.native-file-system-adapter's Firefox fallback depended on it.Findings
moz-firefoxchannel does the same throughnetwork.addDataCollector. Details are on DSPX-5084.The design and full measurements are in
spec/DSPX-159.md.Test changes
tests/tests/sink.spec.ts. It needs no platform. It importsdownloadSink.tsfrom the dev server and checks:SINK_TEST_BYTESand paced withSINK_TEST_MIBPS, with browser memory sampled.tests/playwright.moz-firefox.config.tsruns the suite on stock Firefox over WebDriver BiDi. It is only usable forhugeon machines with plenty of RAM; see above.downloadPath()inacts.ts. Stock Firefox ignores Playwright's download folder, so specs now find the file with this helper.huge.spec.tsnow runs on WebKit too. It still skips Playwright's bundled Firefox.How to test
By hand: in Firefox, encrypt a multi-GiB file with the Download sink, and watch
about:processes. Memory should stay flat.Not yet verified
roundtrip.spec.tsandhuge.spec.tsagainst a platform. My local platform went down partway through testing. CI's roundtrip job should coverroundtrip, andlarge-tests.yaml(a manual run) covershugeon Chromium and WebKit.Risk
__download__/URLs under its scope. Every other fetch goes to the network untouched.skipWaiting()replaces the old worker right away, which kills any download it is streaming. That is acceptable for a sample app, and it is noted in the spec.