Fix "Object has been destroyed" error when BrowserView is disposed after window close#312798
Merged
Merged
Conversation
… window close Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/68428537-094f-4b19-8960-68dd9f651e62 Co-authored-by: kycutler <67761731+kycutler@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix unhandled error when object has been destroyed
Fix "Object has been destroyed" error when BrowserView is disposed after window close
Apr 27, 2026
kycutler
approved these changes
Apr 27, 2026
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @jrualesMatched files:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an Electron main-process crash/exception caused by disposing a BrowserView after its hosting BrowserWindow has already been destroyed (a known state by the time the 'closed' event listeners run). The change makes BrowserView.dispose() resilient to destroyed-window references.
Changes:
- Add an
isDestroyed()guard before callingBrowserWindow.contentView.removeChildView(...)duringBrowserView.dispose(). - Keep existing
webContents.isDestroyed()guard behavior intact forwebContents.close(...).
Show a summary per file
| File | Description |
|---|---|
| src/vs/platform/browserView/electron-main/browserView.ts | Prevents "Object has been destroyed" by skipping removeChildView when the hosting window is already destroyed during disposal. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
Yoyokrazy
approved these changes
Apr 27, 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.
When an Electron
BrowserWindowfires'closed', the window object is already destroyed before any listeners run.BrowserViewlistens toonDidCloseand callsdispose(), which calledcontentView.removeChildView()on the now-destroyedBrowserWindow— throwing "Object has been destroyed".Changes
browserView.ts—dispose(): GuardremoveChildViewwith!win.isDestroyed(), consistent with the existingisDestroyed()check already present forwebContents.close()a few lines below.The optional chaining
?.winonly guardsnull/undefined— it does not protect against a valid-but-destroyedBrowserWindowreference, which is the state after'closed'fires.