Skip to content

Refactor browser creation flow, add ownership model#312166

Merged
kycutler merged 5 commits intomainfrom
kycutler/browserowner
Apr 23, 2026
Merged

Refactor browser creation flow, add ownership model#312166
kycutler merged 5 commits intomainfrom
kycutler/browserowner

Conversation

@kycutler
Copy link
Copy Markdown
Contributor

Part of #311974

kycutler and others added 2 commits April 23, 2026 08:43
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings April 23, 2026 16:29
@kycutler kycutler self-assigned this Apr 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a onDidCreateBrowserView event 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() fires onDidCreateBrowserView immediately after calling view.loadURL(url) without awaiting it. The state snapshot sent to the workbench is therefore likely still about: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

Comment thread src/vs/platform/browserView/common/browserView.ts Outdated
Comment thread src/vs/platform/browserView/electron-main/browserViewMainService.ts Outdated
Comment thread src/vs/workbench/contrib/browserView/common/browserView.ts
kycutler and others added 3 commits April 23, 2026 10:32
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@kycutler kycutler marked this pull request as ready for review April 23, 2026 20:35
@vs-code-engineering
Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@jruales

Matched files:

  • src/vs/platform/browserView/common/browserView.ts
  • src/vs/platform/browserView/electron-main/browserView.ts
  • src/vs/platform/browserView/electron-main/browserViewGroup.ts
  • src/vs/platform/browserView/electron-main/browserViewMainService.ts
  • src/vs/workbench/contrib/browserView/browser/browserView.contribution.ts
  • src/vs/workbench/contrib/browserView/common/browserEditorInput.ts
  • src/vs/workbench/contrib/browserView/common/browserView.ts
  • src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts
  • src/vs/workbench/contrib/browserView/electron-browser/browserView.contribution.ts
  • src/vs/workbench/contrib/browserView/electron-browser/browserViewWorkbenchService.ts
  • src/vs/workbench/contrib/browserView/electron-browser/features/browserTabManagementFeatures.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/browserToolHelpers.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/browserTools.contribution.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/openBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/openBrowserToolNonAgentic.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/screenshotBrowserTool.ts

@kycutler kycutler merged commit 853d2d9 into main Apr 23, 2026
26 checks passed
@kycutler kycutler deleted the kycutler/browserowner branch April 23, 2026 21:42
@vs-code-engineering vs-code-engineering Bot added this to the 1.118.0 milestone Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants