feat: support direct CDP webview targets (/devtools/page/<id>)#1
Draft
feat: support direct CDP webview targets (/devtools/page/<id>)#1
Conversation
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.
Summary
This PR adds direct CDP target support for WebSocket endpoints like:
ws://127.0.0.1:9222/devtools/page/<targetId>This unblocks automating Electron
webviewtargets that are visible inhttp://127.0.0.1:9222/json/listbut are not exposed as normal PlaywrightPageobjects viachromium.connectOverCDP().Why this exists
Current
agent-browserassumes browser-level CDP endpoints (/devtools/browser/...) and requires Playwright contexts/pages after connect. For direct target endpoints (/devtools/page/...) that fails with:No page found. Make sure the app has loaded content.This PR introduces a second execution mode for direct targets.
What's in this PR (implemented)
1) New direct-target mode in
BrowserManager/devtools/page/<id>)Runtime.evaluate,Page.captureScreenshot, etc.)02) Action handler support for direct mode
The following actions now branch to direct-target implementations:
navigatesnapshotevaluateclickfilltypepressscreenshotwaitscrollurltitle3) Tab behavior in direct mode
tabworks and returns one targettab 0works4) Regression test
Added test coverage for direct
/devtools/page/...endpoint support insrc/browser.test.tsusing a local mock WebSocket CDP server.What's not in this PR (yet)
targets,webviews,target switch)Validation run
npx vitest run src/browser.test.ts✅npm run build✅Risks / tradeoffs
Recommended next steps (near-term)
click/fill/type/pressby selector and by snapshot refEnd game for parity (proposed architecture)
Recommendation: target abstraction, not a separate product surface
I recommend keeping the primary command surface (
open,click,snapshot, etc.) unchanged and implementing a backend adapter model:PlaywrightPageTargetAdapter(existing behavior)DirectCdpTargetAdapter(webview/direct-target behavior)Then optionally add target management commands (not a separate automation language), e.g.:
agent-browser target listagent-browser target use <id>agent-browser target list --type webviewThis gives users one mental model for interactions while making target selection explicit.
Should webviews be “just another page”?
Pageobject because Playwright does not always expose direct webview targets asPagein connected contexts.So, emulate page parity at command/API level using adapters.
Upstream interaction strategy (recommended)
Fork maintenance recommendation
Files changed
src/browser.tssrc/actions.tssrc/browser.test.tsAttached Investigation Note
Checked in for traceability:
.github/notes/agent-browser-electron-webview-cdp-issue-v1.mdPermalink in this PR branch: