Skip to content

feat(stagehand): expose typed network capture events - #2832

Draft
shrey150 wants to merge 2 commits into
mainfrom
agent/browse-v4-2-network-capture
Draft

shrey150 wants to merge 2 commits into
mainfrom
agent/browse-v4-2-network-capture

Conversation

@shrey150

@shrey150 shrey150 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Expose a public, typed page-scoped network stream for Browse and other Stagehand V4 clients.

  • page.on("network", listener) emits request, completion, and failure events.
  • Completion events include response metadata, duration, and best-effort response bodies.
  • Request keys include the CDP session ID, so identical request IDs in OOPIFs cannot collide.
  • Capture follows current and future page-owned OOPIF sessions.
  • Unsubscribe removes only this observer; it deliberately does not call Network.disable, because Stagehand navigation and networkidle share that domain.

Landing status

This public network-event API draft is intentionally not part of the Browse V4 landing stack. It remains open because it has already been shared for framework/API design review.

The Browse CLI restores its V3 network command through a CLI-private CDP sidecar in #2849, without depending on this PR or committing Stagehand to these schemas.

Landing stack (#2872): #2833#2834#2869#2849#2835#2838#2839#2701

Review boundary

This is an independent core Stagehand API-design draft. No PR in the Browse V4 landing stack consumes it. The proposal extends the existing NetworkManager; TypeScript exports a discriminated PageNetworkEvent union, while Python and Go receive compatible generated additions. Review it on the merits of that long-lived public contract, not as migration plumbing.

Usage proven by E2E

The following standalone Stagehand script was typechecked and rerun against real Chromium on the cursor-free rewritten head c0de0a14c:

import {
  localBrowser,
  Stagehand,
  type PageNetworkEvent,
} from "@browserbasehq/stagehand";

const browser = await localBrowser.launch({ headless: true });
const stagehand = await Stagehand.create({ browser });
const pages = await stagehand.browser.context.pages();
const page = pages[0] ?? (await stagehand.browser.context.newPage());

const events: PageNetworkEvent[] = [];
const subscription = await page.on("network", (event) => {
  events.push(event);

  if (event.method === "Network.requestWillBeSent") {
    console.log(event.params.httpMethod, event.params.url, event.params.body);
  }
  if (event.method === "Network.loadingFinished") {
    console.log(event.params.status, event.params.mimeType, event.params.body);
  }
  if (event.method === "Network.loadingFailed") {
    console.error(event.params.errorText);
  }
});

await page.goto("https://example.com");
await subscription.unsubscribe();
await stagehand.close();
await browser.close();

E2E Test Matrix

Command / flow Observed output Confidence / sufficiency
Build the extension and TypeScript SDK, then typecheck and run the script above against real Chromium NETWORK_STREAM_PASS; document title Network E2E Proves the public SDK API is executable, not only mocked
Page load plus POST /api/data 3 Network.requestWillBeSent and 3 Network.loadingFinished events Proves the page-level stream exposes the network firehose used by Browse
Inspect the captured POST Method POST, path /api/data, body {"probe":"network-firehose"} Proves request bodies are available
Inspect the captured response Status 200, MIME application/json, body {"value":"network-body-ok"}, base64Encoded: false Proves response metadata and best-effort bodies are available
Call subscription.unsubscribe(), then issue more traffic No further delivery to the listener Proves observer cleanup without disrupting the shared Network domain
Protocol, extension, SDK, Python, and Go checks Unit/type/build/generator-drift checks passed, including OOPIF request-ID collision coverage Covers cross-language shape and OOPIF bookkeeping beyond the main-frame browser smoke
Exact cursor-free rewritten head 4 files / 135 network, protocol, extension, and SDK tests passed Proves removing the unrelated cursor API did not disturb the network event contract

The real-browser smoke covers a local main page. OOPIF collision handling, redirects/failures, and cross-language generation are covered by automated tests rather than a second live-browser fixture.

@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c0de0a1

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

This PR includes changesets to release 12 packages
Name Type
@browserbasehq/stagehand-protocol Patch
@browserbasehq/stagehand-python Patch
@browserbasehq/stagehand-extension Patch
@browserbasehq/stagehand-go Patch
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-integrations Patch
@browserbasehq/stagehand-integrations-example-eve-facade Patch
@browserbasehq/stagehand-integrations-example-pi-facade Patch
@browserbasehq/stagehand-integrations-example-claude-code-facade Patch
@browserbasehq/stagehand-integrations-example-codex-facade Patch
@browserbasehq/stagehand-integrations-example-mastra-facade Patch
@browserbasehq/stagehand-integrations-example-vercel-ai-facade 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

@shrey150
shrey150 force-pushed the agent/browse-v4-2-network-capture branch from bc25023 to c0de0a1 Compare August 28, 2026 02:52
@shrey150
shrey150 changed the base branch from agent/browse-v4-1-cursor-overlay to main August 28, 2026 03:00
shrey150 added a commit that referenced this pull request Sep 15, 2026
## Summary

Import `packages/cli/**` exactly from the published `browse@0.9.6` V3
release, without changing its source or runtime behavior.

This is intentionally a provenance checkpoint, not a line-by-line
feature review. The imported source is kept runnable by a root,
version-scoped pnpm override that resolves its unchanged Stagehand
dependency to `3.7.1`. #2834 removes that override and starts the V4
migration.

## Exact-source provenance

- Annotated tag: `browse@0.9.6`
(`548c56407431db27823a212f53475443c7e8358d`)
- Release commit: `1d49a95c0c230c346f8d50647e10303d6310fcd2`
- Authoritative CLI tree: `b4048badce921cf54f199f96033d9a014ef977ec`
- This PR's `HEAD:packages/cli` tree:
`b4048badce921cf54f199f96033d9a014ef977ec`

The tag's ignored README whitespace is retained too; formatting the
import would invalidate the tree proof.

## Verification

- Current remote head: `a77e1507b85e3c02553f36ead6ebd0237b0cccc6`, based
on current `main`.
- `HEAD:packages/cli` exactly equals the published V3 tree hash above.
- pnpm 11 frozen install and the repository supply-chain release-age
policy pass.
- Browse lint, typecheck, and build pass; the full baseline suite
passes: 25 files / 366 tests.
- A fresh extension build still exactly matches the Go-embedded archive:
SHA-256
`8efc7d171a625cca95c02d02d369b59435fae776cae6c7dd2f6fe72eb19785c0` on
both files. This specifically verifies that adding the V3 dependency
graph does not perturb the current V4 extension artifact.
- This layer intentionally exercises V3 through the scoped Stagehand
3.7.1 override. V4 behavior starts in #2834.

## Stack (#2872)

1. **#2833 — exact Browse V3 baseline import**
2. #2834 — Stagehand V4 runtime and standard command parity
3. #2869 — CLI-owned cursor overlay
4. #2849 — CLI-private CDP sidecar; V3 network parity
5. #2835 — remove `--return-xpath`; supported V3 parity/release
checkpoint
6. #2838 — eval and packaging integration
7. #2839 — managed Context names (fast-follow)
8. #2701 — shared Functions core consumer (fast-follow)

## Review and landing boundary

Review this PR by verifying the tree hashes, dependency pin, root
package wiring, and changeset—not by treating the imported V3 source as
newly authored code. This head deliberately imports V3 code into the V4
repository and is not independently publishable. It lands only as the
base of the complete stack.

The framework network-event schema proposal in #2832 is intentionally
outside this landing stack.
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