Add a `CDPBrowser` Harness capability that drives Chrome with raw DevTools Protocol commands
- Closes #14258
Why we make these changes
Agents that scrape or automate pages from code have no lightweight browser in Pydantic AI Harness: PlaywrightBrowser gives the model 18 typed tools, and BrowserUse hands the goal to a sub-agent. CDPBrowser gives it one browser_cdp tool that sends raw Chrome DevTools Protocol commands to a throwaway Chrome, which suits CodeMode: the model's code calls the tool in loops. It started in core as Browser; it moves to the Harness beside the other two browser capabilities, and takes their egress policy.
New public surface
pydantic_ai_harness.CDPBrowser(lazy root export) andpydantic_ai_harness.cdp_browser.{CDPBrowser, CDPBrowserToolset, DEFAULT_ALLOWED_CDP_METHODS}pydantic_ai_harness.cdp_browseralso exportsEgressPolicy,EgressRequest,RequestKind,DEFAULT_ALLOWLIST_REACH,DEFAULT_RESOLVED_KINDS: the same objectspydantic_ai_harness.playwrightexports, now defined in a shared private module- the
cdp-browserextra (websockets,idna)
User-visible behavior
from pydantic_ai import Agent
from pydantic_ai_harness import CDPBrowser, CodeMode
agent = Agent('anthropic:claude-opus-5-5', capabilities=[CDPBrowser(allowed_domains=['example.com']), CodeMode()])
- Each run launches its own Chrome, with a throwaway profile, and tears it down: Chrome is asked to close, its process group is killed, then the profile is removed.
- Only
allowed_methodscan be sent. Every request any target makes (the tab, out-of-process frames, popups, workers) is paused under CDPFetchinterception until theEgressPolicyallows it. Private addresses are refused by default. DNS rebinding on HTTP requests is a documented limit. - Each command has a deadline, which the model can set with
timeout(greater than 0); a timeout, a protocol error or a refused navigation is a retry. Screenshots come back as image content, and one over 5 MB is refused from its encoded length before it is decoded. Dialogs are dismissed, downloads are denied, and durable execution is rejected at construction. - WebSockets go through a local proxy that applies the same policy.
- Chrome launches with a fixed set of flags.
- Under Limitations, the docs say the capability does not bound Chrome's memory or CPU use, and that Chrome's DevTools endpoint listens on a 127.0.0.1 port with no authentication for the whole run, so any local process can drive the browser outside
allowed_methods, the egress policy and the download denial.THREAT_MODEL.mdrecords the endpoint too, and https://github.com/pydantic/pydantic-ai/issues/14329 tracks the pipe transport.
On a 2026-11-23 benchmark (270 runs: 15 scraping tasks, 3 models, 2 repeats, LLM-judged), the raw-CDP approach under CodeMode scored 0.99 at $0.036 a run with 116k mean input tokens, against 0.99 / $0.050 / 207k for PlaywrightBrowser under CodeMode and 0.98 / $0.042 / 134k for browser-use's own loop. The docs page has the table and the methodology.
Verification
src/pydantic_ai_harness/scripts/cdp_browser_smoke.pychecks on a real Chrome that a WebSocket to a refused host never reaches it, with a control that connects and echoes.tests/harness/cdp_browser/test_cdp_browser.pydrives agents against an in-process fake of Chrome's DevTools endpoint and a faked process: per-run browsers, refusals, the guard on every target type, timeouts, dialogs, screenshots, launch failures and teardown.src/pydantic_ai_harness/scripts/cdp_browser_smoke.pyis the hand-run real-Chrome check. It passed against Chrome for Testing 158 (without the sandbox, which that host's AppArmor blocks): teardown under BlockBuster with no leftover process or profile, the private-address block on navigation, andblocked_domainson script navigation,fetch, a cross-site iframe, dedicated and shared workers and a popup. Navigation,fetch, the iframe and the workers each had a control that reached the server; script navigation and the popup did not. The private-DNS-name check was skipped on the final run because it needs a public DNS lookup.
What changes for existing users
PlaywrightBrowser's egress policy code moved to a module both browsers share. Its public API is unchanged.
PlaywrightBrowser now refuses every IP literal that URL downloads refuse, and IPv6 site-local addresses (fec0::/10). Newly refused for it: fec0::/10, 168.63.129.16, IPv6 transition forms of cloud metadata addresses, and ISATAP forms of private addresses.
PR decisions
- 2026-11-23 · capability moves to the Harness · David: browsing is Harness work (
docs/harness/index.md), and both other browser capabilities live there. - 2026-11-23 · name
CDPBrowser· David: same<driver>Browsershape asPlaywrightBrowser, so it reads as a sibling rather than an umbrella;ChromeDevToolsread as the DevTools UI. - 2026-11-23 ·
EgressPolicyshared, not mirrored · one vocabulary and verdict for both browsers without forcing theplaywrightextra onCDPBrowserusers. - 2026-11-23 · client tests in-process, real Chrome in a hand-run script ·
tests/AGENTS.md"Test cost";scripts/playwright_smoke.pyprecedent. - 2026-11-23 ·
chrome_sandboxoption · Chrome aborts with "No usable sandbox!" where AppArmor restricts user namespaces; mirrorsPlaywrightBrowser.chromium_sandbox. - 2026-11-23 · dedicated workers skip
Fetch.enable· Chrome has noFetchdomain on them and pauses their requests on the page's session; any other unguardable target stays paused. - 2026-11-23 · Chrome launches when the run starts, unlike
PlaywrightBrowser's first-call launch · the guard must be on the first tab before any command, and a badchrome_pathfails before the first model request. - 2026-11-23 · skipped: a Trio port (Harness suite is asyncio-only), listing the extra in
docs/install.md(Harness extras live on capability pages). - 2026-11-23 · WebSockets go through a local SOCKS proxy · CDP
Fetchdoes not pause their handshakes, so the policy is applied on the connection. - 2026-11-23 · deferred:
cdp_url=to attach to a running browser, https://github.com/pydantic/pydantic-ai/issues/14246. - 2026-11-23 · filed:
TemporalAgentskips the durable refusal in both browsers, https://github.com/pydantic/pydantic-ai/issues/14259; the CDP page names durability capabilities instead. - 2026-11-23 · allowlist reach kept at
PlaywrightBrowserparity.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it. (none)
- PR title is fit for the release changelog.