Skip to content

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

Draft
mattzcarey wants to merge 1 commit into
computer/host-module-lifecyclefrom
computer/browser-module
Draft

mattzcarey wants to merge 1 commit into
computer/host-module-lifecyclefrom
computer/browser-module

Conversation

@mattzcarey

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 run on @cloudflare/codemode, which is being deprecated, and running code is moving to exec on a Workspace. The browser itself (sessions, Browser Run, Live View) stays in agents. So this module takes anything with the BrowserSource shape: a name and a connect({ scope }) that returns a CDP connection plus the scope's active tab. Browser from agents/browser has that shape, so neither package imports the other. A scratch type check confirmed Browser is assignable to BrowserSource.

Behavior follows the agents browser tool:

  • sessionId: "active" is the scope's tab, remembered between runs;
  • attachToTarget returns handles that work across runs;
  • Browser.close is refused;
  • the common CDP mistakes get hints.

Each run gets its own connection, keyed by executionId. A deferred function saves the active tab, closes the connection, and writes restarts and tabs the page opened to standard error. The module's description covers the calls and those rules for the model.

npm test in packages/computer and npm run check ran. Unit tests use an in-memory browser that keeps tabs and active tabs across connections. A workerd test imports ws:browser from exec code and sees a restart on standard error. docs/17_isolate_javascript.md and the package README's status table cover the module.

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: f11d1ad

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: f11d1ad

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