Use proper streams for loading webview resources#311844
Merged
Merged
Conversation
Fixes microsoft#311836 Switch to stream content to webviews. Previously we always read the entire content into a buffer before sending it over This should speed up loading of resources inside webview and reduce memory usage. It's most helpful for videos and other larger files Co-authored-by: Copilot <copilot@github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves webview resource loading performance by switching from buffering entire local resources in memory to streaming them to the webview (including range support), which is particularly beneficial for large assets such as videos.
Changes:
- Add streaming-based resource delivery from host to service worker using chunk and end messages.
- Forward HTTP
Rangerequests to the host so only requested bytes are read from disk and returned as206 Partial Content. - Bump service worker version and update preload wiring/CSP hash to support the new message protocol.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/webview/electron-browser/webviewElement.ts | Removes now-unneeded stream-to-buffer logic specific to Electron webview element. |
| src/vs/workbench/contrib/webview/browser/webviewMessages.d.ts | Updates message contracts for streaming (range request + chunk/end events). |
| src/vs/workbench/contrib/webview/browser/webviewElement.ts | Sends streaming metadata + streams chunks via new message channels; updates SW version expectation. |
| src/vs/workbench/contrib/webview/browser/resourceLoading.ts | Adds range-aware readFileStream options and exposes total file size for headers. |
| src/vs/workbench/contrib/webview/browser/pre/service-worker.js | Implements streaming pipeline (TransformStream) and range forwarding; adjusts caching behavior. |
| src/vs/workbench/contrib/webview/browser/pre/index.html | Updates preload forwarding to support new channels and transfer chunk buffers. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/vs/workbench/contrib/webview/browser/pre/service-worker.js:441
- The 416 response for an unrecognized
Rangeheader setsContent-Range: '*/*', which is not a validContent-Rangevalue for 416 responses (and it also omitsCross-Origin-Resource-Policy). Prefer a spec-compliant header value (e.g.bytes */<size>when known, or omitContent-Rangeif you can't provide it) and include the same access-control headers as other resource responses.
return new Response(null, {
status: 416,
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Range': '*/*',
}
});
- Files reviewed: 5/6 changed files
- Comments generated: 5
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
We can't transfer the underlying buffer in this case
Co-authored-by: Copilot <copilot@github.com>
Yoyokrazy
approved these changes
Apr 22, 2026
This was referenced May 9, 2026
yongsooim
pushed a commit
to yongsooim/audioscope-vsix
that referenced
this pull request
May 9, 2026
Inline each worker bundle and pass wasm bytes via postMessage so blob workers no longer need to fetch sibling modules through the service worker path broken by microsoft/vscode#311844 (VSCode 1.119). Forward loudness Y-axis settings to the engine worker so the spectrogram axis labels follow Fixed mode, not just the graph. Convert the toolbar/transport chrome to a flat 4px monospace look, drop the responsive breakpoints, and stabilize control widths so zoom/play/ speed updates do not shift surrounding elements. Trim the file metadata pill to codec + sample rate; the rest stays accessible in the expanded panel and the transport readout. Replace the timeline blue fill and visible-range overlay with a single white playhead, lift the hover tooltip out of the transport clipping context, and remove the dead --seek-fill/--seek-progress vars. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Fixes #311836
Switches to stream content to webviews. Previously we always read the entire content into a buffer before sending it over. Now we use streams to transfer it as directly as possible. On Chrome and Firefox, transferable streams let us send the byte data directly from the renderer to the service worker
This speeds up loading of resources inside webview and reduces memory usage. It's most helpful for videos and other larger files
Markdown preview with many video files (cache disabled but service worker ready)
Before
After