Browser: create Playwright per agent session#313779
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the integrated browser Playwright plumbing so that Playwright browser connections are created per agent/chat session, and are disposed when the corresponding chat session ends.
Changes:
- Add a
sessionIdparameter toIPlaywrightServiceoperations and thread it through all browser chat tools. - Refactor the shared-process Playwright implementation to manage per-session Playwright instances with inactivity-based disposal.
- Dispose Playwright sessions on chat session disposal, and keep tracked browser-page sharing state consistent during view disposal.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/browserView/electron-browser/tools/typeBrowserTool.ts | Passes session ID into Playwright invocations for typing/press actions. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/screenshotBrowserTool.ts | Passes session ID into raw Playwright invocation used for element bounding boxes. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/runPlaywrightCodeTool.ts | Routes deferred waits and code execution through session-scoped Playwright calls. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/readBrowserTool.ts | Reads page summary via session-scoped Playwright calls. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/openBrowserTool.ts | Opens/shares pages using session-scoped Playwright calls. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/navigateBrowserTool.ts | Routes navigation actions through session-scoped Playwright invocations. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/hoverElementTool.ts | Routes hover action through session-scoped Playwright invocations. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/handleDialogBrowserTool.ts | Routes dialog/file chooser replies through session-scoped Playwright calls. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/dragElementTool.ts | Routes drag-and-drop through session-scoped Playwright invocations. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/clickBrowserTool.ts | Routes click/double-click through session-scoped Playwright invocations. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/browserTools.contribution.ts | Disposes Playwright sessions when chat sessions are disposed. |
| src/vs/workbench/contrib/browserView/electron-browser/tools/browserToolHelpers.ts | Adds getSessionId helper; updates Playwright helper invocations to accept session ID. |
| src/vs/workbench/contrib/browserView/common/browserView.ts | Ensures tracked-pages set stays in sync by stopping tracking before view destruction. |
| src/vs/sessions/contrib/browserView/browser/sessionBrowserView.ts | Updates browser view lifecycle tracking for the Sessions window based on browserView service events. |
| src/vs/platform/browserView/node/playwrightService.ts | Major refactor: introduces per-session Playwright sessions, global page tracking replay, and inactivity disposal. |
| src/vs/platform/browserView/common/playwrightService.ts | Updates IPlaywrightService API to require session IDs and adds disposeSession. |
| src/vs/platform/browserView/common/browserView.ts | Extends IBrowserViewOwner with optional sessionId for attribution. |
Copilot's findings
Comments suppressed due to low confidence (2)
src/vs/platform/browserView/node/playwrightService.ts:208
startTrackingPageisasyncbut does not await the per-sessiongroup.addViewcalls. That means callers cannot rely on the page being present in all session groups when the promise resolves, and any rejection fromaddViewcan become unhandled. Suggest awaiting the operations (e.g.await Promise.all(...)) or explicitly handling errors for each session.
async startTrackingPage(viewId: string): Promise<void> {
// Update the canonical set directly so tracking works even when
// no sessions exist yet. The Set makes the double-add from
// the group's onDidAddView listener harmless.
if (!this._trackedPages.has(viewId)) {
this._trackedPages.add(viewId);
this._fireTrackedPages();
}
for (const session of this._sessions.values()) {
session.group.addView(viewId);
}
src/vs/platform/browserView/node/playwrightService.ts:217
stopTrackingPageisasyncbut does not awaitgroup.removeViewfor each session. Similar tostartTrackingPage, this makes the returned promise resolve before groups are actually updated and can lead to unhandled rejections ifremoveViewfails. Consider awaiting the removals (or explicitly handling failures) so the method'sPromise<void>accurately reflects completion.
async stopTrackingPage(viewId: string): Promise<void> {
if (this._trackedPages.delete(viewId)) {
this._fireTrackedPages();
}
for (const session of this._sessions.values()) {
session.group.removeView(viewId);
}
- Files reviewed: 17/17 changed files
- Comments generated: 4
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @jrualesMatched files:
|
alexr00
approved these changes
May 4, 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.
No description provided.