Repository navigation
webview: skip load handlers when pending frame is unmounted (#344744) - #344773
Merged
Dmitriy Vasyura (dmitrivMS) merged 5 commits intoNov 17, 2026
Merged
Dmitriy Vasyura (dmitrivMS) merged 5 commits into
Dmitriy Vasyura (dmitrivMS) merged 5 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The inline script changes leave the CSP hash stale, causing browsers to block the bootstrap script and preventing webviews from initializing.
1 open issue
What changed in this PR
This PR addresses #344744 by skipping webview load work for iframes removed during rapid content updates, preventing access to a detached frame’s null contentWindow.
Changes:
- Add mounted-frame checks before deferred content writes and
DOMContentLoadedhandling. - Guard load-handler setup, load events, and the fallback timeout against detached frames.
| File | Description |
|---|---|
src/vs/workbench/contrib/webview/browser/pre/index.html |
Adds detached-frame guards throughout the webview loading lifecycle. |
Review effort: Balanced
Contributor
Author
|
@microsoft-github-policy-service agree |
Aaron Munger (amunger)
previously approved these changes
Nov 16, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Existing preload tests would pass without the guards, so deterministic coverage is needed for iframe replacement before the deferred callback and removal before the 200 ms fallback.
1 open issue
1 resolved since last review
Review effort: Max
Resolve the preload CSP conflict by hashing the combined inline script. Co-authored-by: Copilot <[email protected]>
Dmitriy Vasyura (dmitrivMS)
requested review from
TylerLeonhardt,
Michael Lively (Yoyokrazy),
Alexandru Dima (alexdima),
Alex Ross (alexr00),
Dmitriy Vasyura (dmitrivMS),
Henning Dieterichs (hediet),
Logan Ramos (lramos15),
Ladislau Szomoru (lszomoru),
Raymond Zhao (rzhao271),
Sandeep Somavarapu (sandy081) and
SteVen Batten (sbatten)
as code owners
November 17, 2026 00:14
Collaborator
|
Sorry about that, fixing... |
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge
November 17, 2026 00:22
Dmitriy Vasyura (dmitrivMS)
approved these changes
Nov 17, 2026
roblourens
approved these changes
Nov 17, 2026
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 #344744
Problem
When a webview view sets
webview.optionsand thenwebview.htmlin quick succession (e.g. insideresolveWebviewView), two content update messages are dispatched to the webview host.newFrame), attaches it todocument.body, and begins loading./fake.html.DOMContentLoaded,onFrameLoadedschedules asetTimeout(..., 0)to write content and callhookupOnLoadHandlers(newFrame).previousPendingFrame.remove()) to replace it with a new one.setTimeoutfrom the first frame runs,newFrameis already detached from the DOM. An unmounted iframe element hascontentWindow === null, causingassertIsDefined(newFrame.contentWindow)inhookupOnLoadHandlersto throw:Fix
onFrameLoaded's deferredsetTimeoutcallback andDOMContentLoadedlistener so that if!newFrame.parentElement(frame is no longer mounted), we stop early without writing content or hooking up handlers. This mirrors the existing unmounted check in the Safari polling branch (// If the frame is no longer mounted, loading has stopped).hookupOnLoadHandlersand its 200ms fallback timeout if!newFrame.parentElement, preventing attempts to accessnewFrame.contentWindowor clobber timers for newer pending frames.