Refactor browser creation flow, add ownership model#312166
Merged
Conversation
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Integrated Browser creation/opening flow to introduce an explicit ownership model and a main→workbench creation event, enabling browser pages to exist independently of editor tabs (per #311974).
Changes:
- Adds
IBrowserViewOwner, creation/open options, and aonDidCreateBrowserViewevent to formalize browser view lifecycle ownership. - Refactors workbench-side browser view model creation to be event-driven and synchronously queryable (
getBrowserViewModel), and updates tool/context tracking accordingly. - Moves “new page” handling (e.g.,
window.open) to be orchestrated via main-service creation events rather than editor-pane logic.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/browserView/electron-browser/tools/screenshotBrowserTool.ts | Handles missing page models gracefully (no longer assumes async throw). |
| src/vs/workbench/contrib/browserView/electron-browser/tools/openBrowserToolNonAgentic.ts | Uses workbench browser service when checking for existing pages. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/openBrowserTool.ts | Uses workbench browser service for “already open” checks in agentic flow. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/browserTools.contribution.ts | Tracks browser pages via IBrowserViewWorkbenchService change events. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/browserToolHelpers.ts | Reworks formatting/existing-page detection around “known browser views”. |
| src/vs/workbench/contrib/browserView/electron-browser/features/browserTabManagementFeatures.ts | Switches editor-open detection/reuse logic to use the workbench browser service. |
| src/vs/workbench/contrib/browserView/electron-browser/browserViewWorkbenchService.ts | Implements ownership-aware model registry + editor-opening on create events. |
| src/vs/workbench/contrib/browserView/electron-browser/browserView.contribution.ts | Adjusts editor resolver option merge order for pinned behavior. |
| src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts | Removes per-editor new-page handling; adds reload shutdown visibility safeguard. |
| src/vs/workbench/contrib/browserView/common/browserView.ts | Updates workbench service/model APIs (ownership, sync lookup, init state). |
| src/vs/workbench/contrib/browserView/common/browserEditorInput.ts | Binds editor input lifecycle to models created/managed by workbench service. |
| src/vs/workbench/contrib/browserView/browser/browserView.contribution.ts | Updates web stubs for new workbench service API surface. |
| src/vs/workbench/api/browser/mainThreadBrowsers.ts | Tracks open browser tabs via the workbench browser service rather than editor events. |
| src/vs/platform/browserView/electron-main/browserViewMainService.ts | Introduces owner/scope/create options, emits create events, lists views. |
| src/vs/platform/browserView/electron-main/browserViewGroup.ts | Updates CDP target creation to pass owner window ID via new signature. |
| src/vs/platform/browserView/electron-main/browserView.ts | Adds owner handling and emits create events for window.open-spawned views. |
| src/vs/platform/browserView/common/browserView.ts | Adds ownership/open/create event types and updates the service interface. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/vs/platform/browserView/electron-main/browserViewMainService.ts:380
openNew()firesonDidCreateBrowserViewimmediately after callingview.loadURL(url)without awaiting it. The state snapshot sent to the workbench is therefore likely stillabout:blank, and any navigation failures could become unhandled promise rejections. Consider awaiting navigation (or handling errors) and/or propagating the intended initial URL separately so the editor/model can initialize with the correct URL/title.
const targetId = generateUuid();
const view = this.createBrowserView(targetId, owner, session || BrowserSession.getOrCreateEphemeral(targetId));
if (url) {
view.loadURL(url);
}
logBrowserOpen(this.telemetryService, source);
// Fire creation event so the workbench can open an editor tab
this._onDidCreateBrowserView.fire({
info: this._getViewInfo(view),
openOptions
});
- Files reviewed: 17/17 changed files
- Comments generated: 6
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @jrualesMatched files:
|
Yoyokrazy
approved these changes
Apr 23, 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.
Part of #311974