Skip to content

computer: Add a ws:browser host module - #248

Draft
mattzcarey wants to merge 3 commits into
computer/host-module-lifecyclefrom
computer/browser-module
Draft

mattzcarey wants to merge 3 commits into
computer/host-module-lifecyclefrom
computer/browser-module

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Adds an experimental ws:browser host module, createBrowserModule() from @cloudflare/computer/modules/browser. Code that exec runs can drive a persistent Chrome browser over the Chrome DevTools Protocol with send, attachToTarget, spec, getDebugLog and clearDebugLog.

import { Browser, browserRun } from "agents/browser";
import { createBrowserModule } from "@cloudflare/computer/modules/browser";

modules: { "ws:browser": createBrowserModule({ browser: this.browser }) }
import { send } from "ws:browser";
export default () => send({ method: "Page.navigate", params: { url }, sessionId: "active" });

The agents SDK's browser tools are moving off @cloudflare/codemode, which is being deprecated, and the browser itself stays in agents:

  • the module takes anything with a name and a session({ scope, maxResultBytes }). Browser from agents/browser has that shape (browser: run createBrowserTool without codemode, on a BrowserSession聽agents#2612), so neither package imports the other
  • the CDP rules (the "active" tab, attach handles that last between runs, refusing Browser.close, hints for common mistakes) live in that session, so ws:browser and agents' direct createBrowserTool behave the same way
  • each run starts one session on its first call. A deferred function closes it and writes the report (a restart, a closed or shared tab, tabs the page opened) to standard error

npm test in packages/computer and npm run check ran. Unit tests cover the routing to one session per run, the options passed through and the report lines. A workerd test imports ws:browser from exec code and sees a restart on standard error. A scratch type check against agents' built types confirmed Browser is assignable to BrowserSource, and that a connect()-only source isn't.

Stacked on #247, which adds executionId, log and defer.

createBrowserModule() from @cloudflare/computer/modules/browser lets
isolate JavaScript drive a persistent Chrome browser over the Chrome
DevTools Protocol: send, attachToTarget, spec, getDebugLog and
clearDebugLog.

The browser belongs to the host. The module takes anything with the
BrowserSource shape, a name and a connect({ scope }) that returns a
CDP connection and the scope's active tab. Browser from agents/browser
has that shape, so neither package depends on the other.

Each run gets its own CDP connection, keyed by the call context's
executionId. A deferred function saves the scope's active tab, closes
the connection, and writes restarts, closed or shared tabs and tabs
the page opened to the run's standard error. sessionId "active", the
attach handles that work across runs, scopes, refusing Browser.close
and the hints for common CDP mistakes follow the browser tool in
agents. The module is experimental.
@changeset-bot

changeset-bot Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

馃 Changeset detected

Latest commit: e1e67d3

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

This PR includes changesets to release 4 packages
Name Type
@cloudflare/computer Minor
@cloudflare/dofs Minor
@cloudflare/computer-rpc Minor
@cloudflare/computerd 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

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

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@248

commit: e1e67d3

ws:browser kept its own copy of the CDP logic agents/browser already
has: the active tab, attach handles, error hints and the end-of-run
report. It now takes anything with a name and session(), such as
Browser from agents/browser, starts one session per run, and on the
run's end closes it and writes the report to standard error. The
package still doesn't depend on agents.
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.

1 participant