Skip to content

browser: run createBrowserTool without codemode, on a BrowserSession - #2612

Closed
mattzcarey wants to merge 1 commit into
browser-computer-modulefrom
browser-session
Closed

mattzcarey wants to merge 1 commit into
browser-computer-modulefrom
browser-session

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

createBrowserTool now runs the model's code in a fresh Dynamic Worker from the loader you pass, with no network access and a cdp object backed by the new browser.session(). It no longer runs on @cloudflare/codemode, so it needs neither ctx nor a CodemodeRuntime export.

const session = this.browser.session({ scope });
await session.send({ method: "Page.navigate", params: { url }, sessionId: "active" });
const report = await session.close(); // { restarted, newTabs, tabClosed, tabShared }

Stacked on #2610, as part of deprecating codemode (#2609):

  • BrowserSession holds the CDP logic that used to live in BrowserSessionConnector: the "active" tab, attach handles, error hints and the report. @cloudflare/computer's ws:browser (computer: Add a ws:browser host module computer#248) uses it through name and session() instead of its own copy, so neither package imports the other
  • the code is loaded as an expression and, if that doesn't parse, as a function body, which replaces codemode's acorn normalizer for this tool
  • deprecated pieces stay where they are and don't change: BrowserConnector, its option types and CodemodeRuntime are still exported from agents/browser (now marked deprecated), so agents/browser still imports codemode until they're removed

pnpm run check, the agents workers suite, the pi harness suite and the real-Chrome suite (test:browser) ran. browser-session.test.ts ports the connector's tests, and new tests cover the code shapes, parse errors, thrown errors, logs, timeouts and blocked fetch.

@changeset-bot

changeset-bot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4e1e7cc

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

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

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

@agent-think

agent-think Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🔴 agents import sizes: 1 entry point over threshold

Entry point Exports Largest gzip change Size now
🔴 agents/browser 1 resized, 2 new +6.5 KiB (+15.69%) 47.8 KiB
🟡 agents/browser/ai 2 resized +1.4 KiB (+0.97%) 148.9 KiB
🟢 agents/browser/pi 2 resized -43.2 KiB (-55.96%) 34 KiB
🟢 agents/browser/ai-sdk 2 resized up to -9 KiB (-6.3%) 133.4 KiB
🟢 agents/browser/tanstack-ai 2 resized -9 KiB (-5.67%) 149 KiB
Changed exports (11)
Import Gzip change Size now
🔴 agents/browser#Browser +6.5 KiB (+15.69%) 47.8 KiB
🟡 agents/browser/ai#createBrowserRuntime +1.4 KiB (+0.97%) 148.9 KiB
🟡 agents/browser/ai#createBrowserTools +1.4 KiB (+0.97%) 148.9 KiB
🆕 agents/browser#BrowserSession — 42.8 KiB
🆕 agents/browser#ACTIVE_PAGE_SESSION — 36 KiB
🟢 agents/browser/pi#createBrowserTool -43.2 KiB (-55.96%) 34 KiB
🟢 agents/browser/pi#browserTool -43.2 KiB (-55.96%) 34 KiB
🟢 agents/browser/ai-sdk#browserTool -9 KiB (-6.3%) 133.4 KiB
🟢 agents/browser/ai-sdk#createBrowserTool -9 KiB (-6.3%) 133.4 KiB
🟢 agents/browser/tanstack-ai#createBrowserTool -9 KiB (-5.67%) 149 KiB
🟢 agents/browser/tanstack-ai#browserTool -9 KiB (-5.67%) 149 KiB
How this works

Each runtime export is bundled on its own, minified, and gzipped. Changes smaller than 100 B, or smaller than 1% and 1 KiB, are ignored. Growth over 10% or 5 KiB is marked 🔴. This report is informational and does not fail CI. The workflow artifact contains every measurement.

Compared c84dc2c4 → 4e1e7ccc · workflow run · reported by agent-think[bot]

@mattzcarey mattzcarey changed the title browser: run createBrowserCDPTool without codemode, on a BrowserSession browser: run createBrowserTool without codemode, on a BrowserSession Oct 19, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 4e1e7cc

ben-reitz added a commit that referenced this pull request Oct 26, 2026
…2667)

* feat(browser): run browserTool on a BrowserSession, without codemode

browserTool's code now runs in a fresh Dynamic Worker from `loader`
(browser/sandbox.ts) with no network access and a frozen `cdp` object as
its only way out, instead of on a codemode facet. It no longer needs
`ctx` (now ignored) or a `CodemodeRuntime` export, and its output drops
the `calls` log.

The per-run CDP logic moves from session-connector.ts into
BrowserSession (browser/session.ts), returned by `browser.session()`:
the "active" tab, attach handles, error hints, refusing Browser.close,
and the end-of-run report. truncate.ts is a copy of codemode's
truncateResult. BrowserConnector is marked deprecated.

Ported from #2612, keeping the browserTool name.

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* fix(browser): address review on browserTool without codemode

- Statements with no return get a notice instead of a silent undefined.
- Rule and docs say only screenshots over 1 MB fail, and why the limit stays.
- Pi docs drop the CodemodeRuntime export.
- Design record: browserTool first, codemode connector under Deprecated.

Co-authored-by: Matt Carey <77928207+mattzcarey@users.noreply.github.com>

* docs(browser): move deprecated browser docs to the bottom, notice on every empty body run

A `return` inside a string no longer hides the statements notice.

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* docs(browser): rewrite browserTool's How It Works in the design doc

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* docs(browser): rewrite Browse the Web around browserTool, slim the deprecated part

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* docs(browser): lead with pi, drop Experimental from Browse the Web

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* docs(browser): no contractions in Browse the Web

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* docs(browser): say browserTool still needs @cloudflare/codemode installed

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* fix(browser): refuse Live View, handoff and tunnelling CDP commands

Model code could mint a Live View link with Cloudflare.getLiveView, or
wrap a refused command in Target.sendMessageToTarget.

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* fix(browser): a host-side deadline for browserTool runs

Model code could cancel the sandbox's timer and hold the scope's queue.

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* fix(browser): keep only real screenshots whole

A returned browser_screenshot must be a png, jpeg or webp of base64 data
within the 1 MB limit; anything else is cut down like any other result.

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* fix(browser): run an arrow function that ends in a semicolon and comment

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* fix(browser): bound browserTool's console logs

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* docs(agents): browser rows in AGENTS.md mark the deprecated codemode APIs

* chore(browser): the browserTool changeset says to keep codemode installed

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

* fix(browser): cut a huge thrown error down like a result

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>

---------

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>
@ben-reitz

Copy link
Copy Markdown
Contributor

All done in #2667

@ben-reitz ben-reitz closed this Oct 26, 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