Skip to content

Use proper streams for loading webview resources#311844

Merged
mjbvz merged 9 commits into
microsoft:mainfrom
mjbvz:dev/mjbvz/new-earwig
Apr 22, 2026
Merged

Use proper streams for loading webview resources#311844
mjbvz merged 9 commits into
microsoft:mainfrom
mjbvz:dev/mjbvz/new-earwig

Conversation

@mjbvz
Copy link
Copy Markdown
Collaborator

@mjbvz mjbvz commented Apr 22, 2026

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

Screenshot 2026-04-21 at 11 29 43 PM

After

Screenshot 2026-04-21 at 11 27 57 PM

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>
Copilot AI review requested due to automatic review settings April 22, 2026 05:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Range requests to the host so only requested bytes are read from disk and returned as 206 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 Range header sets Content-Range: '*/*', which is not a valid Content-Range value for 416 responses (and it also omits Cross-Origin-Resource-Policy). Prefer a spec-compliant header value (e.g. bytes */<size> when known, or omit Content-Range if 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

Comment thread src/vs/workbench/contrib/webview/browser/pre/service-worker.js
Comment thread src/vs/workbench/contrib/webview/browser/pre/service-worker.js
Comment thread src/vs/workbench/contrib/webview/browser/resourceLoading.ts
Comment thread src/vs/workbench/contrib/webview/browser/webviewElement.ts Outdated
Comment thread src/vs/workbench/contrib/webview/browser/webviewElement.ts Outdated
mjbvz and others added 4 commits April 21, 2026 23:05
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>
@mjbvz mjbvz marked this pull request as ready for review April 22, 2026 16:45
mjbvz and others added 4 commits April 22, 2026 09:55
Co-authored-by: Copilot <copilot@github.com>
We can't transfer the underlying buffer in this case
Co-authored-by: Copilot <copilot@github.com>
@mjbvz mjbvz enabled auto-merge April 22, 2026 17:19
@mjbvz mjbvz merged commit b980ef3 into microsoft:main Apr 22, 2026
26 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.118.0 milestone Apr 22, 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use real streaming for loading webview resources

3 participants