Browser view native "add to chat" features#305745
Merged
Conversation
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
This PR adds native “add to chat” support for the integrated Browser View by moving element inspection and console-log collection into the Browser View model/service layer (electron-main), and adjusting screenshot cropping to use page coordinates.
Changes:
- Replace Browser Elements service usage in the editor chat integration with new
IBrowserViewModelAPIs for element inspection and console logs. - Add electron-main implementations for capturing console output and inspecting elements via CDP.
- Update screenshot capture options to support
pageRect/screenRect(and migrate callsites).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/browserView/electron-browser/tools/screenshotBrowserTool.ts | Switches partial screenshot requests to pageRect cropping. |
| src/vs/workbench/contrib/browserView/electron-browser/features/browserEditorChatFeatures.ts | Uses IBrowserViewModel APIs for element selection and console log attachment. |
| src/vs/workbench/contrib/browserView/common/browserView.ts | Adds model-level APIs (getConsoleLogs, getElementData, getFocusedElementData) and cancellable request plumbing. |
| src/vs/platform/browserView/electron-main/browserViewMainService.ts | Exposes new IPC service methods and adds cancellation support for in-flight requests. |
| src/vs/platform/browserView/electron-main/browserViewElementInspector.ts | New CDP-based element inspector/serializer used by BrowserView. |
| src/vs/platform/browserView/electron-main/browserView.ts | Captures console messages, adds element inspection entrypoints, and converts pageRect → screenRect for screenshots. |
| src/vs/platform/browserView/common/browserView.ts | Extends the public BrowserView service contract (new APIs + new screenshot option shape). |
Comments suppressed due to low confidence (2)
src/vs/platform/browserView/electron-main/browserViewElementInspector.ts:236
DOMParseris used in electron-main code to parseouterHTML, butDOMParseris a browser API and is not available in the Electron main process at runtime. This will throw when element inspection runs. Consider omittinginnerTexthere, deriving it via CDP (e.g. DOM/CSS/AX APIs), or using a Node-safe HTML parser that is already available in the repo.
// IMPORTANT: this node itself is untrusted and must not be added to the DOM.
// Parsing is safe and allows us to easily extract contents.
const untrustedNodeParsed = new DOMParser().parseFromString(outerHTML, 'text/html').body.firstElementChild;
if (!untrustedNodeParsed) {
throw new Error('Failed to parse outerHTML.');
}
innerText = untrustedNodeParsed.textContent;
src/vs/platform/browserView/electron-main/browserViewElementInspector.ts:98
- The overlay cleanup is registered as an
async disposeon aDisposableStore, butDisposableStore.dispose()is synchronous and will not await these CDP commands. Since the caller disposes the CDP connection immediately aftergetElementDatareturns, the cleanup commands can race/fail, potentially leaving inspect mode/highlight active. Prefer explicittry/finallycleanup that is awaited before the connection is disposed (or provide an explicit async cleanup path).
store.add({
dispose: async () => {
try {
await connection.sendCommand('Overlay.setInspectMode', {
mode: 'none',
highlightConfig: {
showInfo: false,
showStyles: false
}
});
await connection.sendCommand('Overlay.hideHighlight');
await connection.sendCommand('Overlay.disable');
} catch {
// Best effort cleanup
}
}
src/vs/platform/browserView/electron-main/browserViewElementInspector.ts
Show resolved
Hide resolved
roblourens
previously approved these changes
Mar 27, 2026
Yoyokrazy
approved these changes
Mar 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.
No description provided.