Skip to content

feat: add browser-scoped session client#99

Open
rgarcia wants to merge 4 commits intonextfrom
raf/browser-scoped-client
Open

feat: add browser-scoped session client#99
rgarcia wants to merge 4 commits intonextfrom
raf/browser-scoped-client

Conversation

@rgarcia
Copy link
Copy Markdown
Contributor

@rgarcia rgarcia commented Apr 13, 2026

Summary

  • add kernel.forBrowser(...) to create a browser-scoped client from a browser session response
  • route browser subresource methods through the session base_url so callers stop repeating the browser id
  • expose raw HTTP through browser.fetch(...) while keeping the internal /curl/raw transport path hidden
  • add focused tests for metro routing, JWT propagation, and browser-scoped fetch behavior

Test plan

  • ./node_modules/.bin/tsc --noEmit
  • ./node_modules/.bin/jest tests/lib/browser-transport.test.ts tests/lib/kernel-browser-session.test.ts

Made with Cursor


Note

Medium Risk
Introduces a new request-routing mode that rewrites browser subresource paths and changes auth behavior (drops Authorization and relies on jwt query params), which could affect how browser-session requests are authenticated and routed.

Overview
Adds a browser-scoped session client via kernel.forBrowser(...), returning KernelBrowserSession that lets callers invoke browser subresources without repeating session_id and routes those calls through the browser session base_url.

Introduces browser.fetch(...) to proxy HTTP through the browser VM network stack by calling internal POST /curl/raw, and adds transport helpers to resolve base_url and jwt (from cdp_ws_url or explicit) and inject jwt into query params.

Adds a codegen script (scripts/generate-browser-session.ts) and committed generated bindings for browser subresources, wires generation into build/lint, exports the new APIs from src/index.ts, and adds tests plus an example demonstrating the new browser-scoped usage.

Reviewed by Cursor Bugbot for commit c5731cb. Bugbot is set up for automated code reviews on this repo. Configure here.

Bind browser subresource calls to a browser session's base_url and expose raw HTTP through fetch so metro-routed access feels like normal JavaScript networking.

Made-with: Cursor
@firetiger-agent
Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

Any PR that changes the kernel API. Monitor changes to API endpoints (packages/api/cmd/api/) and Temporal workflows (packages/api/lib/temporal) in the kernel repo

Reason: PR modifies client library code (browser session client) rather than API endpoints or Temporal workflows in packages/api/

To monitor this PR anyway, reply with @firetiger monitor this.

Comment thread src/lib/kernel-browser-session.ts
Fail fast when browser-scoped clients do not have a session base_url, route subresource calls through the browser session base directly, and clean up browser-vm wording.

Made-with: Cursor
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issues. You can view the agent here.

Reviewed by Cursor Bugbot for commit 7486cd4. Configure here.

if (options.path.startsWith(prefix)) {
const rest = options.path.slice(prefix.length);
options.path = rest.startsWith('/') ? rest : `/${rest}`;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Path prefix matching ignores SDK URL encoding

Low Severity

The prepareOptions override builds the prefix with raw string interpolation (`/browsers/${transport.sessionId}/`), but the SDK's path tagged template in resource methods (e.g., path`/browsers/${id}/...`) runs path parameters through encodeURIPath. If a session_id ever contains characters outside the URI-safe set, the encoded path won't match the raw prefix, so the path won't be rewritten and requests will hit the wrong endpoint.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7486cd4. Configure here.

Comment thread src/lib/browser-transport.ts
rgarcia added 2 commits April 13, 2026 14:19
Fail fast when browser-scoped clients are missing a browser session base_url, route subresource calls through the session base consistently, and keep lint output clean.

Made-with: Cursor
Replace the handwritten Node browser-scoped façade with deterministic generated bindings from the browser resource graph, and enforce regeneration during lint and build.

Made-with: Cursor
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