Skip to content

feat(browser): include page workers in session HAR - #2048

Closed
Hyped01 wants to merge 5 commits into
morluto:mainfrom
Hyped01:feat/session-har-4-workers
Closed

Hyped01 wants to merge 5 commits into
morluto:mainfrom
Hyped01:feat/session-har-4-workers

Conversation

@Hyped01

@Hyped01 Hyped01 commented Oct 12, 2026

Copy link
Copy Markdown

Stacked on #2047 (and #2046, #2045). Only the top commit, f23dfac53, is new here.

Summary

Refs #774. The session HAR from #2045 now also covers the selected page's workers: dedicated workers, including workers started by workers, and in-scope shared and service workers.

Problem and expected behavior

Pages move network traffic into workers; realtime feeds, for example, often run in a SharedWorker. A page-only recorder misses that traffic and does not say so. Worker traffic should be recorded with its target and attribution, or reported as not observed.

Change and scope

  • Dedicated workers of the page, and of observed workers, are auto-attached and held at startup. The hold lasts only until REA enables their Network domain and worker auto-attach, each step bounded by 5 s; then the worker is resumed. REA never evaluates worker code. Out-of-scope workers, workers attached after recording stopped, and malformed attach payloads are released without observation.

  • Shared and service workers in scope, in the page's browser context, are discovered and attached while running. Their traffic has origin attribution, because they can also serve other documents of that origin.

  • Commands. Every worker command has a 5-second deadline. It ends early when the worker detaches or is destroyed, or when the observed target ends or disconnects. A worker that ends also ends its pending body reads.

  • Failures. Only these leave a worker unobserved instead of failing the observation:

    • a missing Target.* command (-32601);
    • a session that no longer exists (-32001);
    • Target.attachToTarget on a target that no longer exists (-32602);
    • the deadline;
    • the end of the worker or of the target.

    Any other rejection fails the observation.

  • Limitations. Per-worker limitations name the worker and quote the browser's reason, through the declared-value redactor from feat(browser): redact declared values in session HAR #2046.

  • HAR fields. Each HAR entry names its target through _rea_target_id, and network.targets gains worker types and an attribution field.

  • Service-worker pass-through bodies. For a service worker's fetch that the worker passes to the page (respondWith(fetch(request))), Chrome reads back an empty body even though encoded bytes arrived. That entry states the omission instead of claiming an empty body.

  • Cross-site iframes. The page's auto-attach filter also includes iframes, so Chrome announces only the selected page's own out-of-process iframes. REA never observes them and always resumes a held one. Each is named in a limitation, and network_requests and websocket_connections record an out_of_target_scope exclusion of unknown count. Iframes of other tabs are not reported.

  • Page-scoped transport. A page-scoped CDP transport cannot attach shared or service workers, so workers is then reported attach-limited.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/browser/CdpSessionWorkers.ts.
  • CLI and MCP/tool-catalog contract: an additive workers completeness section, plus target types and attribution in network.targets.
  • Provider, bridge, target-format, or platform compatibility: CDP only. Chromium does not let shared workers start dedicated workers.
  • Evidence, artifact, provenance, or reconstruction contract: none beyond the new fields.
  • Process execution, authorization, cleanup, or containment impact: workers are held only for the bounded setup steps above, then always resumed unless they ended or the caller cancelled. Worker sessions are released when REA closes its WebSocket.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated:
    • hold, enable, auto-attach and resume ordering;
    • a worker detach that does not end the page;
    • shared-worker and service-worker discovery;
    • unavailable setup commands, and other rejections retained;
    • per-worker failures with the browser's message;
    • workers attached after the timeline ended;
    • command deadlines;
    • a worker destroyed while attaching;
    • a page crash during a held worker's resume;
    • a browser-level page detach;
    • nested dedicated workers;
    • -32601/-32602 classification in both directions;
    • declared values in worker limitations;
    • malformed attach payloads;
    • a missing browser context;
    • the page-scoped transport;
    • service-worker pass-through bodies;
    • non-worker targets announced by auto-attach, which are only resumed;
    • a discovered iframe target.
  • Mutation checks: each of these fails a test.
    • The targetDestroyed end signal.
    • The terminated-target abort.
    • The page-session guard.
    • The resume classification.
    • The -32601-only-on-Target.* rule.
  • Live Chrome: tested with an isolated headless profile and a local fixture containing a navigation, a dedicated worker, a nested worker, a shared worker, a WebSocket and a POST carrying a planted value.
    • The run recorded 11 HAR entries, attributed to the page, the shared worker and both workers.
    • The planted value, the declared query value and the Set-Cookie value appear nowhere, whether raw, percent-encoded or base64.
    • inspect-web-network-capture decodes all 11 records.
  • Remaining proof gaps:
    • Chrome reports a worker's own script request on the page target and its response on the worker target, so that entry has no response. This is documented.
    • A held iframe that ends while being resumed is reported with the worker wording ("the worker ended").
    • A malformed iframe announcement is counted under workers.

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

  • Per-commit gate: pass.
  • npx vitest run on 12 browser, CLI, MCP and redactor test files: 147 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.
  • The live Chrome run above, on this commit.
  • Cold review with adversarial verification: the final round reported no findings.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; worker coverage applies only when network is selected.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: REA never evaluates worker code, every hold is bounded, and declared values are redacted in worker limitations.

🤖 Generated with Claude Code

Hyped01 and others added 5 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]>
Adds `sensitive_values` (CLI: --sensitive-value) and
`sensitive_query_parameters` (CLI: --sensitive-query-parameter) to
observe_web_session.

- Every retained field (URLs, query parameters, headers, timeline fields,
  target IDs, MIME types, methods and browser metadata) is checked as
  written and in its UTF-8 percent-decoded, form-decoded and JSON-unescaped
  forms, nested up to three levels; a value that survives replacement fails
  the field closed. The docs name the spellings that are not detected.
- URLs are redacted piece by piece: only the host, port, path segments,
  query pairs and fragment pieces that spell a value are rewritten (the
  pieces with percent-encoded markers), so the rest keeps its exact bytes and the URL stays a
  valid URI. A URL-valued header is redacted this way only when its whole
  value is one absolute URL; a relative Location or Content-Location and
  every Link and Refresh value are redacted as text, with markers that are
  not percent-encoded, and emptied when a declared value appears only in a
  decoded spelling. Each piece is redacted as written before it is decoded, so a
  raw '+', a lowercase escape or an unreserved escape cannot hide a value,
  and a piece whose result still spells one is emptied. A host that spells
  a value becomes redacted.invalid and keeps its port; a port that spells
  one loses its digits but keeps its host and the ':' before it; a value
  spanning pieces fails the whole URL closed; a HAR entry no placeholder URL can stand in for is
  omitted and counted under its own completeness section. The HAR
  queryString is derived from the redacted URL, so it never reveals what
  the URL hides.
- One Aho-Corasick matcher over every spelling is built per session, so
  redaction stays linear in the retained text however many query values
  are declared. Declared values with unpaired surrogates are accepted.
- The observed values of named query parameters in the query strings of
  retained URLs (target and timeline URLs, HAR request and WebSocket URLs,
  and in-scope URL-valued header targets of requests, responses and
  WebSocket handshakes) become declared literals; parameters inside a fragment
  are not read and must be declared as sensitive values.
- Evidence parameters keep the parameter names and the number of declared
  literals, never the literals; a request parameter or parameter name that
  spells one is left empty, and the result says so. Evidence never
  derives allowed_origins from a target URL whose host or port was
  redacted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds `request_bodies`, `response_bodies` (none, json or all) and
`websocket_payloads` to observe_web_session's network selection (CLI:
--request-bodies, --response-bodies, --websocket-payloads).

- Response bodies are read with Network.getResponseBody after loading
  finishes, each within a 5-second deadline. A read that misses it, a body
  the browser released (-32000), a browser without the method (-32601), a
  body still loading when recording stopped, and reads pending when the
  target ends or disconnects (including while settling after the window)
  are stated in their entry comments and reported unavailable. Caller
  cancellation and other protocol failures still fail the observation.
- The timeline ends with the window, so events after it are not observed.
- Retained bodies and payloads share one budget equal to
  inspect_web_network_capture's 32 MiB input budget; a read reserves its
  base64 worst case while in flight. A body whose reply could exceed the
  64 MiB CDP message limit (non-ASCII text is escaped six-fold) is not
  read, and selected request bodies are inlined only up to about 7.9 MiB
  so subresource request events fit too; Chrome inlines navigation (form
  submission) bodies whole regardless, as the docs say.
- Malformed content, including non-canonical base64, is not retained and
  is counted as invalid_protocol_value. Declared sensitive values are also
  replaced in bodies and payloads, with the same survival check across
  percent, form and JSON decodings; binary content is matched on its bytes.
  A body or payload that redaction would empty is withheld, never reported
  as empty: a body keeps its size, its entry comment says why and
  network_bodies counts it as provider_unavailable; a payload has data null,
  is counted under websocket_frames, and a limitation states how many.
- Checking content for declared values builds its percent, form and JSON
  decodings one at a time, depth first, keeping at most one decoding per
  level alive and stopping at the first match, which bounds memory for
  32 MiB fields; the same decodings are checked as before. Redacting very
  large content is still CPU-bound (seconds for a 32 MiB body), as the
  docs say.
- A HAR larger than inspect_web_network_capture's 32 MiB input budget says
  so in a limitation naming what to select less of.
- Request bodies come from CDP's postDataEntries bytes when present: a
  UTF-8 body is retained as text with its byte size, and any other body is
  reported by size only, since HAR postData carries text.
- One linear base64 decoder now serves the session recorder, the HAR
  decoder and storage fingerprints, so multi-megabyte base64 bodies and
  frames no longer exhaust the regex backtracking stack.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Network evidence now also covers the selected page's workers:

- New dedicated workers of the page, and of observed workers, are
  auto-attached and held at startup only until REA enables their Network
  domain and worker auto-attach, each step bounded by 5 s, then resumed. REA never evaluates worker code; out-of-scope
  workers, workers attached after recording stopped and malformed attach
  payloads are released without observation.
- In-scope shared and service workers in the page's browser context are
  discovered and attached while running. Their traffic has `origin`
  attribution because they can also serve other documents of that origin;
  nested dedicated workers share their parent's attribution.
- Worker setup goes through optionalCdpCommand. Every per-worker command
  has a 5-second deadline and ends early when the worker detaches or its
  target is destroyed; a worker that ends also ends its pending body
  reads. Unknown methods (-32601) and gone targets (-32001, -32602) are
  per-worker omissions with the browser's reason; other rejections are
  retained. A missing browser context skips discovery, and a worker
  announced without a session is counted; both as invalid_protocol_value.
- Each HAR entry names its target through _rea_target_id, and
  network.targets gains worker types and an attribution field. Each
  excluded worker target is counted once, and a worker announced before
  its script URL is known is not counted as excluded.
- Chrome reads back an empty body for a service worker's fetch whose
  response the worker passes to a page (respondWith(fetch(request)))
  although encoded bytes arrived; that entry states the omission and
  `network_bodies` is reported unavailable instead of claiming an empty
  body.
- The page's auto-attach filter also includes iframes, so Chrome announces
  only the selected page's own out-of-process iframes. REA never observes
  them and always resumes a held one. Each is named in a limitation, and
  `network_requests` and `websocket_connections` record an
  `out_of_target_scope` exclusion of unknown count; iframes of other tabs
  are not reported.
- A page-scoped CDP transport cannot attach shared or service workers;
  `workers` is then reported attach-limited.

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:24:13.067636Z f23dfac 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: f23dfac532

ℹ️ 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".

Comment on lines +92 to +93
if (browserContextId === undefined) {
completeness.exclude("workers", "invalid_protocol_value", null);

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 Treat omitted context IDs as the default browser context

On CDP implementations that omit TargetInfo.browserContextId to denote the default browser context, this branch classifies a valid page as malformed and returns before Target.setDiscoverTargets. As a result, an ordinary default-profile page loses all shared- and service-worker HAR traffic even though omitted context IDs on those worker targets identify the same default context; represent the default context explicitly rather than requiring a string.

AGENTS.md reference: AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

const retained = this.context.options.websocket_payloads
? this.#framePayload(payload, opcode)
: undefined;
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 a selected page has a high-rate WebSocket stream, every frame appends an object here even when websocket_payloads is false, while observation_ms has no upper bound and the 32 MiB content budget does not cover frame metadata. A busy or adversarial page can therefore exhaust heap during capture or make the completed MCP result fail its transport budget; apply a count/serialized-representation budget and report truncation.

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

Useful? React with 👍 / 👎.

: value
: Array.isArray(value)
? value.map(hide)
: value;

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 Recurse into nested Evidence parameter objects

When a caller selects network.response_bodies: "json" (similarly "all" or "none") and also declares that literal in sensitive_values, hide handles strings and arrays but returns the plain parameters.network object unchanged here. The serialized Evidence therefore contains the exact declared literal despite the contract saying declarations are never persisted; recurse through JSON objects as well.

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

Useful? React with 👍 / 👎.

isWorkerOmission(method, cause.code)
)
return { omitted: cause.userMessage ?? cause.message };
throw cause;

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 Redact declared literals from fatal worker errors

If a worker setup command receives an unexpected rejection whose browser-reported message contains a declared target ID, URL, or other marked literal, this rethrows the raw CdpCommandRejection; settle() then surfaces it and the provider returns its userMessage unchanged to CLI/MCP because the result redactor never runs on failures. Apply the declarations to typed failures before they cross the adapter boundary.

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

Useful? React with 👍 / 👎.

this.#remainingBytes += reserved;
}
const text = cdpStringValue(reply?.body);
const base64 = reply?.base64Encoded === true;

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 bodies with non-boolean encoding flags

If Network.getResponseBody omits base64Encoded or returns a non-boolean value, this expression silently classifies the malformed reply as false and retains the body as text. The body representation is actually unknown, and a base64-encoded marked value can bypass the byte redactor on this path; require an actual boolean and record an invalid-protocol omission otherwise.

AGENTS.md reference: AGENTS.md:L25-L25

Useful? React with 👍 / 👎.

const base64 = reply?.base64Encoded === true;
// Chrome reads back an empty body for a service worker's fetch whose
// response the worker passes to a page, although its bytes arrived.
if (text === "" && exchange.encodedBytes > 0) {

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 Avoid inferring a missing body from compressed bytes

For a legitimately empty compressed response, Network.dataReceived can report zero decoded bytes but nonzero encoded bytes for the compression framing, while getResponseBody correctly returns "". This condition then drops the observed empty body and marks network_bodies unavailable, so encoded byte count alone cannot distinguish the service-worker pass-through case from an empty compressed entity.

AGENTS.md reference: AGENTS.md:L5-L5

Useful? React with 👍 / 👎.

@Hyped01 Hyped01 closed this Oct 12, 2026
@Hyped01
Hyped01 deleted the feat/session-har-4-workers 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 23, 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