Repository navigation
refactor(agents): collapse named browser sessions into one Browser class - #2411
Merged
Merged
Conversation
|
ben-reitz
added this pull request to stack #2412
September 29, 2026 13:36
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
ben-reitz
force-pushed
the
refactor/browser-class
branch
from
September 30, 2026 09:25
81c84d7 to
bf4bc99
Compare
Contributor
|
✅ agents import sizes: no significant changes ( |
ben-reitz
marked this pull request as ready for review
September 30, 2026 09:37
Replace the internal BrowserSessions capability and NamedBrowserSessions engine with a single Browser class: one object per named browser, a browserRun() provider, and Lifecycle capability id browser:<name>. Rename session-manager.ts to session-store.ts and move openOneShotBrowserSession into browser-run.ts.
ben-reitz
force-pushed
the
refactor/browser-class
branch
from
October 1, 2026 10:08
bf4bc99 to
498d9cf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR: replaces the two browser session classes with one
Browserclass: one object, one browser.Before, a named browser went through two classes that were hard to tell apart:
BrowserSessions(the Lifecycle capability) andNamedBrowserSessions(the engine under it). Every call took a name. Now there's oneBrowserper browser, named once:resolve(),connect(),close(),liveView()lose their name argument.sessions()is gone; hosts that want more than one browser keep more than oneBrowser.browserRun(binding, options)holds the Browser Run settings (keepAliveMs,recording,guardrails). It's a plain config object for now, so bring-your-own-browser can be another provider later without changingBrowser.browser:<name>, so several browsers can be installed on one object. Passing astorestill works without Lifecycle.browser:session:<name>,browser:retired:<name>).ConnectedBrowserSession→BrowserConnection,ResolvedBrowserSession→ResolvedBrowser,session-manager.ts→session-store.ts(it holds the store). The store-lessopenOneShotBrowserSessionmoves intobrowser-run.ts.Nothing here is exported yet, so no changeset.
Browseris exported in #2372. Tests are ported from the old classes (browser-session-core.test.ts→browser.test.ts), plus tests for the capability id and multiple browsers on one Lifecycle.Architecture diff
Outlined boxes are components this PR changes (green added, red removed). Grey boxes are unchanged.
flowchart TB classDef ctx fill:none,stroke:#8c959f,color:#8c959f classDef changes fill:#dafbe1,stroke:#1a7f37,color:#1f2328 classDef removed fill:#ffebe9,stroke:#cf222e,color:#1f2328 Agent["Agent (host Durable Object)"]:::ctx subgraph Old["removed"] direction TB O1["− BrowserSessions · capability.ts (one capability, every call takes a name)"]:::removed O2["− NamedBrowserSessions · session-core.ts (engine)"]:::removed O1 ~~~ O2 end subgraph B["Browser · browser.ts (new)"] direction TB B1["+ one object per browser, Lifecycle id browser:<name>"]:::changes B2["+ resolve · connect · close · liveView"]:::changes B1 ~~~ B2 end subgraph P["browserRun() · browser.ts (new)"] P1["+ Browser Run settings: keepAliveMs, recording, guardrails"]:::changes end Store["DurableBrowserSessionStore · session-store.ts (renamed)"]:::ctx BR["Browser Run"]:::ctx Agent -->|"lifecycle.use (one per browser)"| B B --> P B -->|"one record"| Store P --> BR style B fill:#dafbe1,stroke:#1a7f37,stroke-width:2px,color:#1f2328 style P fill:#dafbe1,stroke:#1a7f37,stroke-width:2px,color:#1f2328 style Old stroke:#cf222e,stroke-width:2px