Skip to content

feat(browser): record observe_web_session traffic as HAR - #2045

Closed
Hyped01 wants to merge 2 commits into
morluto:mainfrom
Hyped01:feat/session-har-1-core
Closed

Hyped01 wants to merge 2 commits into
morluto:mainfrom
Hyped01:feat/session-har-1-core

Conversation

@Hyped01

@Hyped01 Hyped01 commented Oct 12, 2026 •

Copy link
Copy Markdown

Stacked on #2044. Only the top commit, fba05f5e1, is new here; review it alone, or after #2044 merges.

Summary

Refs #774 (batch 1, "Network transaction identity and selected content evidence"). observe_web_session can now record the selected page's in-scope HTTP requests and WebSocket connections as one HAR 1.2 log, across main-frame navigations. inspect_web_network_capture can then inspect that log offline.

Recording is opt-in through network (CLI --network, with --header-values). Without it, the result and the Evidence parameters are unchanged.

Problem and expected behavior

inspect_web_page fails closed with target_changed when the page navigates during its window, and observe_web_session keeps navigation metadata only. Login, checkout and other multi-page flows therefore had no network evidence. With network selected, the session result gains network.har: every in-scope request, redirect hop, failure, WebSocket handshake and frame, with completeness and limitations reported.

Change and scope

  • Recorder. CdpSessionNetwork records requests, redirect hops, failures, WebSocket handshakes and frames. CDP reports a hop's response together with the next request. Entries are keyed by target and request ID.
  • Scope. The recorder reuses the timeline's origin boundary. Recording stops right after the event that ends the timeline, so an out-of-scope document redirect still completes its in-scope hop.
  • Headers are retained only with header_values:
    • Authorization, Proxy-Authorization, Cookie and Set-Cookie never are, by the shared rules from fix(browser): admit browser-serialized HAR request URLs #2044.
    • URL-valued headers follow the request scope: Location, Content-Location, Referer, Origin, Link and Refresh. One that points outside the selected origins, or whose target cannot be parsed, is omitted and counted.
    • Link is read as RFC 8288 link-values, including anchor parameters. A Link is omitted when it does not parse, has a < inside a target, or has an anchor value REA cannot read.
    • Refresh follows the HTML declarative-refresh steps, with or without url=. Its delay is matched without backtracking. A quoted URL whose quote appears again after its closing quote is omitted, because Chromium reads to the last matching quote.
    • Userinfo in a retained header is judged on the target resolved against the request URL. It is located with src/domain/recordedTransportUrl.ts, the repository's transport-URL parser, and cut at its parsed offset only when the cut leaves exactly the same target. A spelling the parser reads as ambiguous, such as http:user:pass@host/, or a cut that would change the target, omits the header.
  • HAR 1.2 conformance:
    • send, wait and receive are non-negative, and time is their sum;
    • a response still loading says so;
    • a request whose body is not retained has bodySize -1.
  • Coverage. coverage_started_at is taken once the browser has processed Network.enable.
  • Size. har_bytes reports the log's size. This PR does not check it against inspect_web_network_capture's limits; feat(browser): retain selected bodies and payloads in session HAR #2047 adds the input-budget limitation. The decoder's 96 MiB reply limit is documented, not estimated: a log dominated by WebSocket frames can exceed it below 32 MiB.
  • Separate targets. Chrome runs the page's workers and cross-site iframes out of process, as separate targets. This PR does not attach them, so their traffic is not recorded; an always-present limitation, the tool description and the docs say so. feat(browser): include page workers in session HAR #2048 adds workers and flags each out-of-process iframe of the page. Without network, the navigation-only limitation says network was not selected.
  • Not included: declared-value redaction (feat(browser): redact declared values in session HAR #2046), bodies and payloads (feat(browser): retain selected bodies and payloads in session HAR #2047), and workers (feat(browser): include page workers in session HAR #2048).

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/browser/CdpSessionNetwork.ts (recorder) and src/browser/CdpSessionHar.ts (projection).
  • CLI and MCP/tool-catalog contract: an additive optional network input and a network output, plus one new contract example.
  • Provider, bridge, target-format, or platform compatibility: CDP only; the HAR is admissible to inspect_web_network_capture.
  • Evidence, artifact, provenance, or reconstruction contract: observe_web_session Evidence parameters gain network only when it is selected.
  • Process execution, authorization, cleanup, or containment impact: none beyond Network.enable on the page session, which was already sent.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated:
    • tests/boundary/browser/cdpObservationSessionNetwork.test.ts covers:
      • navigation tolerance with an offline decode round trip;
      • out-of-scope requests, sockets and redirect targets;
      • a document redirect leaving scope;
      • recording stopping at the timeline's end;
      • URL-valued header spellings: foreign Referer and Origin, bare and malformed Link, quoted < and quoted-pairs, anchor params, a Refresh with and without url=, scheme-relative and backslash userinfo, a backslash retarget, two credentialed targets in one header, and a 200,000-digit Refresh delay;
      • browser-serialized URLs, including a bare % and a query backslash, accepted by the decoder;
      • HAR 1.2 timings;
      • a quoted Refresh URL that Chromium reads to a later quote;
      • navigation-only sessions staying unchanged.
    • CLI flag mapping, including --network alone keeping every header out, and MCP Evidence: browserCli.test.ts and browserMcp.test.ts.
  • Mutation checks: reverting each header rule, the last-first splice order, the Link tokenizer's fail-closed branches, the Refresh delay pattern, the repeated-quote rule or the iframe limitation fails a test.
  • Remaining proof gaps:
    • cross-site iframe traffic is not recorded, as stated above;
    • Chrome reports an out-of-process iframe's document request on the page session but its loadingFinished on the iframe's own target, so with the iframe's origin selected that entry says it had not finished loading.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Host: macOS 27.0.1, Node 24.20.0, Chrome 154 (headless, isolated profile).

  • Per-commit gate: turbo run typecheck lint format:check knip metadata:check docs:check:built mcp-catalog:check:built, npm run verify:architecture-guards, npm run verify:test-discovery and npx jscpd src/ tests/ all pass.
  • npx vitest run on 11 browser, CLI, MCP and process boundary files: 74 passed, 2 skipped.
  • exposes CLI-equivalent Evidence results and session tools, an existing MCP test, times out only under heavy machine load. It fails the same way on unmodified main.
  • Cold review with adversarial verification: the final round reported no findings.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; recording is opt-in.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: credentials and out-of-scope URL targets fail closed and are counted. The HAR is sensitive local evidence, as the docs say.

🤖 Generated with Claude Code

Hyped01 and others added 2 commits October 11, 2026 23:39
inspect_web_network_capture validates request.url with ajv-formats' RFC 3986
`uri` format. Browsers serialize request URLs per WHATWG URL and leave
[ ] { } | ^ and backtick, a `%` that starts no escape, and a backslash in the
query or fragment unescaped, so a HAR that Chrome itself exports for such a
page was rejected whole as a format error.

- A request URL is admitted when the pinned RFC 3986 check accepts it as
  written or with only those characters percent-encoded: each [ ] { } | ^ and
  backtick, each `%` not followed by two hex digits, and each backslash after
  the first `?` or `#`. Spellings that only WHATWG parsing accepts, such as a
  backslash before the first `?` or `#` or a tab, stay rejected: browsers
  never serialize them, and WHATWG alone reads an authority through them.
- The transport-credential header set moves unchanged from CaptureRedaction
  to src/browser/network/TransportCredentials.ts; capture_browser_scenario's
  network headers now use it instead of a private copy, and the session
  HAR recorder in the next change applies the same set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
observe_web_session can now record the selected page's in-scope HTTP
requests and WebSocket connections across main-frame navigations as one
HAR 1.2 log, so a user-driven multi-page flow can be inspected offline with
inspect_web_network_capture. Recording is opt-in through a `network`
selection (CLI: --network); without it the result and Evidence parameters
are unchanged.

- Requests, redirects and WebSocket handshakes use the timeline's origin
  boundary. Excluded traffic is counted in completeness. Recording stops
  right after the event that ends the timeline, so an out-of-scope
  document redirect still completes its in-scope hop.
- Cross-site iframes that the browser runs out of process, and the page's
  dedicated, shared and service workers, are separate targets that are not
  attached, so their traffic is not recorded, and a dedicated worker's
  script request can appear without its response; a limitation, the tool
  description and the docs say so.
- Without a network selection, the navigation-only limitation now says
  that network was not selected, rather than that the tool cannot capture
  headers, bodies or payloads.
- Headers are retained only with `header_values`. Authorization,
  Proxy-Authorization, Cookie and Set-Cookie never are. URL-valued headers
  (Location, Content-Location, Referer, Origin, Link, Refresh) pointing
  outside the selected origins, or without a parseable target, are
  omitted, and userinfo in retained ones is removed; all are counted.
  Link targets, including `anchor` parameters, are read as RFC 8288
  link-values; a Link that does not parse as one, has a `<` inside a target
  or an anchor value it cannot read is omitted. The Refresh delay is matched
  without backtracking, so a page-controlled digit run stays linear. A
  quoted Refresh URL whose quote appears again after its closing quote is
  omitted, since Chromium reads it to the last matching quote.
- har_bytes reports the log's serialized size. REA does not check it
  against inspect_web_network_capture's 32 MiB input budget or 96 MiB reply
  limit, which a log dominated by WebSocket frames can exceed below 32 MiB;
  the tool description and docs say so.
- Timings follow HAR 1.2 (non-negative send/wait/receive, time is their
  sum); a response still loading when recording stopped says so. A request
  that carried an unretained body reports bodySize -1.
- coverage_started_at is taken once the browser has processed
  Network.enable, the earliest instant coverage is guaranteed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T04:19:00.347409Z fba05f5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fba05f5e12

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const payload = cdpStringValue(response?.payloadData) ?? "";
const opcode = Math.max(0, Math.trunc(numberValue(response?.opcode) ?? 0));
const timestamp = numberValue(params?.timestamp);
socket.messages.push({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bound retained WebSocket frame metadata

When observe_web_session runs with network capture on a page that emits many WebSocket frames, especially with the uncapped observation_ms input, every event is appended here with no aggregate item or byte limit. A high-rate or long-lived socket can therefore grow memory without bound and the later HAR/Evidence serialization expands it again, potentially failing the observation instead of returning explicit truncated or resource-constraint completeness; enforce an aggregate budget before retaining each frame.

AGENTS.md reference: AGENTS.md:L46-L46

Useful? React with 👍 / 👎.

return (
rfc3986(
value.replace(
/[[\]{}|^`\\]|%(?![0-9A-Fa-f]{2})/gu,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve IPv6 delimiters in the URI fallback

For a recorded request to a supported IPv6 origin with any character that triggers this fallback, such as http://[::1]/?q=% or http://[::1]/?filter[x]=1, the initial RFC check fails and this replacement percent-encodes the authority's structural [ and ] as well as the query character. The validator then checks an invalid host spelling such as http://%5B::1%5D/..., so a HAR that observe_web_session just produced cannot round-trip through inspect_web_network_capture; restrict bracket encoding so IP-literal delimiters are preserved.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

return raws?.map(({ raw, start }) => ({
raw,
start,
url: URL.canParse(raw, requestUrl) ? new URL(raw, requestUrl).href : raw,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject relative Origin header values

With header_values enabled, a server response can contain a malformed value such as Origin: not-a-url; resolving every URL-valued header against the request turns that into an in-scope path, so the raw malformed text is retained and the out-of-scope counter is unchanged even though unparseable Origin targets are supposed to be omitted. Origin permits an absolute serialized origin or null, so validate it as absolute instead of treating unresolved applicability as aligned with the request origin.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@Hyped01 Hyped01 closed this Oct 12, 2026
@Hyped01
Hyped01 deleted the feat/session-har-1-core branch October 12, 2026 04:36
@morluto morluto added the enhancement New feature or request label Oct 14, 2026
@morluto morluto added the area: runtime Process capture and runtime observation label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants