Skip to content

Add experimental browser CDP tools without a bundled spec#1163

Merged
threepointone merged 8 commits intomainfrom
browser
Apr 14, 2026
Merged

Add experimental browser CDP tools without a bundled spec#1163
threepointone merged 8 commits intomainfrom
browser

Conversation

@threepointone
Copy link
Copy Markdown
Contributor

@threepointone threepointone commented Mar 23, 2026

Summary

  • Add experimental browser CDP tools for the Agents SDK (agents/browser, agents/browser/ai, agents/browser/tanstack-ai).
  • Remove the bundled CDP spec and fetch the live protocol from Browser Rendering instead.
  • Make local development work through Browser Rendering in wrangler dev, without a separate Chrome process.
  • Add first-class browser tools to Think (@cloudflare/think/tools/browser), following the same pattern as workspace, execute, and extensions.

What Changed

Browser tools (agents package)

  • browser_search fetches the live protocol from the Browser Rendering devtools endpoints, normalizes it into a tool-facing search shape, and caches it briefly in memory.
  • browser_execute connects through the Browser Rendering devtools WebSocket endpoint and cleans up sessions with the corresponding DELETE endpoint.
  • Delete the generated CDP spec assets and the build-cdp-spec build step.
  • Add Wrangler-backed browser e2e tests that start a real wrangler dev instance and exercise simple search and execution scenarios.
  • Update the ai-chat example to use the Browser Rendering binding directly in local development.
  • Add a design doc (design/browser-tools.md) and usage doc (docs/browse-the-web.md).

Think integration

  • New export @cloudflare/think/tools/browser with createBrowserTools() — wraps agents/browser as a first-class Think tool alongside workspace, execute, and extensions.
  • Updated Think docs (docs/think/tools.md) and design doc (design/think.md) with browser tools section.
  • Unit tests for the tool factory.

Bug fixes (from Devin review)

  • Fix truncateResponse throwing TypeError when sandbox code returns undefined (no explicit return statement).
  • Fix connectUrl using wrong protocol when rewriting localhost URLs to an HTTPS base URL (tunnel/proxy case).

Testing

  • npm run test:browser (agents browser e2e)
  • npm run test -w @cloudflare/think (Think unit tests including browser tools)
  • npm run -w agents build and npm run -w @cloudflare/think build

Notes

  • Local browser development no longer requires CDP_BASE_URL or a separately managed Chrome process.
  • The new docs are in docs/browse-the-web.md and design/browser-tools.md.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 23, 2026

🦋 Changeset detected

Latest commit: 1dc6687

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@cloudflare/think Patch
agents Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 23, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1163

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1163

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1163

hono-agents

npm i https://pkg.pr.new/hono-agents@1163

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1163

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1163

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1163

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1163

commit: 1dc6687

jonnyparris added a commit to jonnyparris/dodo that referenced this pull request Apr 8, 2026
Replace the single browser_navigate tool (text extraction only) with two
code-mode tools that give sessions full CDP access:

- browser_search: query the ~1.7MB CDP spec server-side (56 domains,
  664 commands, 237 events). The spec never enters the context window.
- browser_execute: run CDP commands against a live headless Chrome via
  WebSocket. Screenshots, DOM manipulation, network interception, etc.

Uses Dodo's existing DynamicWorkerExecutor + BROWSER binding. The LLM
writes JS that executes in a sandbox with a cdp helper (send, attachToTarget,
getDebugLog). Adapted from cloudflare/agents#1163.

Also:
- Remove @cloudflare/puppeteer dependency (no longer needed)
- Update system prompt with CDP usage patterns
- Fix stale MCP catalog test (sentry entry was removed)
@whoiskatrin whoiskatrin changed the title DO NOT MERGE — Experimental browser CDP tools for Agents SDK Add experimental browser CDP tools without a bundled spec Apr 12, 2026
@whoiskatrin whoiskatrin marked this pull request as ready for review April 12, 2026 11:42
threepointone and others added 4 commits April 14, 2026 08:52
Introduce experimental "Browse the Web" browser tools that expose Chrome DevTools Protocol (CDP) access (browser_search and browser_execute). Adds documentation, an examples/ai-chat integration (env types, wrangler config, start script, server & UI updates), a CDP spec build script (scripts/build-cdp-spec.ts) that generates spec data, new browser package exports and build targets, and end-to-end browser tests with Vitest. Also updates .gitignore and package metadata to include new optional dependencies and test scripts. This enables agents to run sandboxed JS that queries the CDP spec and executes CDP commands against a host browser for scraping, inspection, and debugging.
Update and sync dependency versions across example and package package.json files: bump ai to ^6.0.159, @cloudflare/vite-plugin to ^1.32.2, @cloudflare/workers-types to ^4.20260414.1, wrangler to ^4.82.2, react/react-dom and types to ^19.2.5, bump @x402 packages to 2.10.0 and viem to ^2.47.17, and other minor patch updates. Also rename a codemode test file to a .backup.ts. These changes align examples and packages with recent upstream patch releases and keep dev tooling consistent.
devin-ai-integration[bot]

This comment was marked as resolved.

Add @tanstack/ai@^0.10.2 to packages/agents dependencies and bump its peerDependency to ^0.10.2. Remove the @ai-sdk/openai peer entry and update package-lock.json to reflect the new packages (including @tanstack/ai, @tanstack/ai-event-client and partial-json) and clean up duplicate entries, keeping manifest and lockfile consistent.
Introduce first-class browser tools (@cloudflare/think/tools/browser) that expose two tools: browser_search and browser_execute for CDP-based web automation. Implements createBrowserTools (packages/think/src/tools/browser.ts) which delegates to agents/browser createBrowserToolHandlers; exports SEARCH_DESCRIPTION and EXECUTE_DESCRIPTION from packages/agents/src/browser, and adds the new entry to package exports and the build script. Documentation and design are updated to describe the tools and usage, a changeset is added, and unit tests (packages/think/src/tests/browser-tools.test.ts) validate the toolset shape. Requires a Browser Rendering binding and a WorkerLoader (or a cdpUrl override) at runtime.
When a baseUrl is provided, preserve its protocol on the parsed URL instead of always mapping wss->https or ws->http; only apply the wss->https / ws->http mapping for the non-baseUrl (Workers) path that requires fetch+Upgrade. Also harden truncateResponse by coalescing JSON.stringify results to the string 'null' to avoid returning undefined for non-serializable inputs.
devin-ai-integration[bot]

This comment was marked as resolved.

Pass through any provided options.headers into the WebSocket upgrade fetch in cdp-session so custom headers (e.g. auth) are preserved. In shared.ts wrap the cleanup DELETE request in a try/catch so failures during cleanup don't mask the original result or error.
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 12 additional findings in Devin Review.

Open in Devin Review

Comment thread packages/agents/scripts/build.ts
@threepointone threepointone merged commit d3f757c into main Apr 14, 2026
5 checks passed
@threepointone threepointone deleted the browser branch April 14, 2026 08:54
@github-actions github-actions bot mentioned this pull request Apr 14, 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.

2 participants