Repository navigation
fix: guard webview find against disposed frame subtree (fixes #339314) - #339331
Merged
Dmitriy Vasyura (dmitrivMS) merged 6 commits intoOct 12, 2026
Conversation
…ft#339314) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused lifecycle guard fixes the reported crash while preserving live-frame error handling.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Prevents main-process crashes when webview find requests arrive after frame disposal.
Changes:
- Returns early when web contents or its frame subtree is unavailable.
- Preserves errors for unknown frames in live subtrees.
| File | Description |
|---|---|
src/vs/platform/webview/electron-main/webviewMainService.ts |
Guards find operations against disposed frame trees. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Updated comment to clarify frame subtree availability after disposal. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Handle unavailable hosts and frames without unhandled find errors. Avoid idle stop requests while preserving retained-selection clearing, and add regression coverage for microsoft#339314. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge (squash)
October 12, 2026 22:13
Dmitriy Vasyura (dmitrivMS)
approved these changes
Oct 12, 2026
roblourens
approved these changes
Oct 12, 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.

Summary
WebviewMainService.getFrameByName(electron-main) readsgetWebContents(id).mainFrame.framesInSubtree.find(...)unconditionally. When a find / stop-find IPC request is handled against a webContents whose render frame has already been torn down (window closed, navigated away, or detached editor window disposed),mainFrame.framesInSubtreeisundefined, so.find(...)throwsTypeError: Cannot read properties of undefined (reading 'find')in the main process. This new-in-1.140.0 bucket affects 566 users / 736 hits across Mac, Windows, and Linux.Fixes #339314
Recommended reviewer:
@dmitrivMSCulprit Commit
9cc2a44b@dmitrivMSgetFrameByNameto resolve the frame via the sharedgetWebContents(id)helper and routes stop-find/find requests through auxiliary web-contents IDs (detached editor windows) as well as main window IDs. This widened the set of webContents the find path runs against — including auxiliary/detached contents that can be disposed between request and handling — somainFrame.framesInSubtreecan now beundefinedat the dereference, which the prior window-only path did not expose. Verified ancestor of shipped commit07f806f9(first appears in1.140.0~389, matching the "new in 1.140.0" anomaly).Code Flow
sequenceDiagram participant Renderer as Webview (renderer) participant IPC as ipcMain / ChannelServer participant Service as WebviewMainService participant Electron as Electron WebContents Renderer->>IPC: stopFindInFrame(id, frameName) IPC->>Service: call stopFindInFrame Service->>Service: getFrameByName(id, frameName) Note over Electron: ⚠️ Root cause:<br/>render frame already disposed,<br/>framesInSubtree is undefined Service->>Electron: getWebContents(id).mainFrame.framesInSubtree Note over Service: 💥 TypeError: Cannot read<br/>properties of undefined (reading 'find')Affected Files
src/vs/platform/webview/electron-main/webviewMainService.tsgetWebContents(id).mainFrame.framesInSubtree.find(...)dereferencesundefinedwhen the webContents' render frame is disposedRepro Steps
The error is a timing-dependent race on the main process; it fires when a stop-find/find reply is handled after the target render frame is gone:
stopFindInFrame/findInFrameIPC call reachesgetFrameByName, whosewebContents.mainFrame.framesInSubtreeis nowundefined, throwing theTypeError.How the Fix Works
Chosen approach —
webviewMainService.ts→getFrameByName(): the producer of the invalid state is Electron's render-frame disposal, which lives outsidemicrosoft/vscodeand cannot be reordered or awaited, so a consumer-side guard at this external boundary is the correct fix.getFrameByNamenow returnsWebFrameMain | undefined: it checkscontents.isDestroyed()andcontents.mainFrame?.framesInSubtreebefore calling.find(...), returningundefinedwhen the frame subtree is gone. The two callers (findInFrame,stopFindInFrame) already treat a missing frame as a no-op, so they early-return onundefined. This mirrors the existing disposed-frame guards already in this codebase: thecontents.isDestroyed()check insetIgnoreMenuShortcuts(same file) and theframe.isDestroyed()guard inapp.ts'sisSafeFrame.The genuine
Unknown framethrow is deliberately preserved for the live-frame case (a real frame subtree that does not contain the named frame), so the error-telemetry pipeline still surfaces that distinct, actionable condition — only the disposed-webContents undefined read is suppressed.Alternatives considered: adding
?./try/catchdirectly at the crash-site.find(...)was rejected because it would also swallow the meaningfulUnknown framesignal and does not express why the value is absent; guarding explicitly onisDestroyed()/ missing subtree keeps the disposed-frame no-op distinct from the live-frame "frame not found" error.Recommended Owner
@dmitrivMS— author of the culprit commit #337403 and an activemicrosoft/vscodeteam member (238 commits in the last 90 days), who owns the webview find-in-frame routing changed by that PR.