Repository navigation
Fix webview resource loading detach in Safari/WebKit - #321291
Merged
Alexandru Dima (alexdima) merged 1 commit intoJun 15, 2026
Merged
Conversation
When transferable streams are unsupported (Safari/WebKit), webview resource chunks are sent via postMessage with a transfer list. The chunk was wrapped as a view over its underlying ArrayBuffer and that whole ArrayBuffer was transferred. In web/remote mode the chunk can be a view aliasing a larger, shared buffer (e.g. from the IPC deserialize pipeline), so transferring it detached every sibling view. WebKit detaches synchronously, throwing "Underlying ArrayBuffer has been detached from the view" and breaking webview resource loading. Copy the chunk into a freshly-owned ArrayBuffer (sized to exactly the chunk window) before transferring it. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Safari/WebKit-specific failure in webview resource loading where transferring a shared underlying ArrayBuffer via postMessage can synchronously detach sibling views, triggering Underlying ArrayBuffer has been detached from the view or out-of-bounds: subarray in web/remote mode.
Changes:
- In the Safari fallback path (when transferable streams are unsupported), copy each resource chunk into a newly-owned buffer via
Uint8Array#slice()before transferring it. - Add detailed inline commentary explaining why the copy is required on WebKit (synchronous detachment behavior).
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/webview/browser/webviewElement.ts | Copies chunk data before transferring in Safari fallback to avoid detaching shared IPC buffers and breaking resource loading. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
Alexandru Dima (alexdima)
marked this pull request as draft
June 13, 2026 23:38
Alexandru Dima (alexdima)
marked this pull request as ready for review
June 13, 2026 23:39
|
Verified that this PR fixes the 2 distinct error paths in Safari, and VSCode extension webview works properly with it. This PR seems more surgical and fixes both error paths with one change :-) Closing #320190 in favor of this. |
Alexandru Dima (alexdima)
removed the request for review
from Matt Bierner (mjbvz)
June 14, 2026 21:56
Member
Author
|
Given the feedback from er91 (@er91) let's get this in for testing. |
Alexandru Dima (alexdima)
enabled auto-merge (squash)
June 14, 2026 21:56
Paul (pwang347)
approved these changes
Jun 15, 2026
Alexandru Dima (alexdima)
deleted the
alexdima/webview-resource-chunk-detach
branch
June 15, 2026 00:21
This was referenced Jun 17, 2026
2 tasks done
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
fyi Matt Bierner (@mjbvz) this is for #316841 -- looks like if this code got ahold of a slice of a larger buffer, it would send off the entire buffer... this would cause other code to throw when it tried to use other pieces of the larger buffer.
🤖
Context
Fixes the
Underlying ArrayBuffer has been detached from the view or out-of-bounds: subarrayerror seen in web/remote mode on Safari/WebKit.Related: #316841, #314126
Problem
When transferable streams are unsupported (Safari/WebKit), webview resource chunks are sent via
postMessagewith a transfer list. The chunk was wrapped as aUint8Arrayview over its entire underlyingArrayBuffer, and that wholeArrayBufferwas transferred:In web/remote mode the chunk is frequently a view aliasing a larger, shared
ArrayBuffer(e.g. a message buffer sliced into many views by the IPC deserialize pipeline). Transferring that shared buffer detaches every sibling view still in use. WebKit detaches synchronously, so the next IPC read throwsUnderlying ArrayBuffer has been detached from the viewand webview resource loading breaks. V8 (Chrome/Edge/desktop) detaches lazily, which is why this reproduces on Safari/iOS only.Fix
Copy the chunk into a freshly-owned
ArrayBuffer(sized to exactly the chunk window) before transferring it, so the transfer can only ever detach the copy:Uint8Array.prototype.slicereturns an exact-window copy backed by its ownArrayBuffer, leaving the shared source intact.