Skip to content

fix(extension): cdp network-capture + frame-eval robustness (3 fixes)#1984

Open
jackwener wants to merge 1 commit into
mainfrom
fix/cdp-network-capture-robustness
Open

fix(extension): cdp network-capture + frame-eval robustness (3 fixes)#1984
jackwener wants to merge 1 commit into
mainfrom
fix/cdp-network-capture-robustness

Conversation

@jackwener

Copy link
Copy Markdown
Owner

Three independent CDP-layer correctness fixes (all in extension/src/cdp.ts), each with a reverse-validated test.

1. Redirect wiped the captured POST body (data-integrity)

On an HTTP 30x, CDP re-fires Network.requestWillBeSent with the same requestId (the prior hop is carried in redirectResponse) for the redirect target — usually a GET with no postData. The handler overwrote the entry's request-body fields unconditionally, destroying the original POST body. Now the body is populated only on the initial send (guarded on !redirectResponse).

  • Trigger: web network capturing a POST that 301/302/307-redirects (auth POSTs, URL shorteners) → read shows an empty body.

2. responseReceived created orphan entries (data-integrity)

If readNetworkCapture() drained the entries (clearing requestToIndex) while a request was in flight, the later Network.responseReceived ran getOrCreate and produced a half-entry with a defaulted method (GET) and no request data. Now it is lookup-only, mirroring loadingFinished.

  • Trigger: polling web network while requests are still in flight (the normal streaming pattern).

3. evaluateInFrame had no retry on a stale cached context (correctness)

A navigated/reloaded frame invalidates its cached execution-context id, but the executionContextDestroyed event may not be processed yet, so Runtime.evaluate rejects with "Cannot find context with specified id". evaluate() has a re-resolution path; evaluateInFrame did not — it failed. Now the rejection drops the stale id and falls through to the frame-target path; genuine page-eval errors still propagate.

  • Trigger: web eval --frame N right after the target iframe reloads (SPA dashboards).

Tests

  • redirect-body preservation, orphan-entry prevention, stale-context fallback — each reverse-validated (neutralizing the fix fails its test).
  • cdp suite green (15/15), tsc --noEmit clean, extension/dist/background.js rebuilt.

Found in the bug-hunt sweep (thread #OpenCLI). Reviewer: @opus-reviewer.

Three independent CDP-layer correctness fixes:

1. Redirect wiped the captured POST body. On an HTTP 30x, CDP re-fires
   Network.requestWillBeSent with the SAME requestId (the prior hop in
   `redirectResponse`) for the redirect target — usually a GET with no
   postData. The handler overwrote the entry's request-body fields
   unconditionally, destroying the original POST body. Now the body is
   only populated on the initial send (guarded on `!redirectResponse`).

2. responseReceived created orphan entries. If readNetworkCapture()
   drained the entries (clearing requestToIndex) while a request was in
   flight, the later Network.responseReceived ran getOrCreate and made a
   new half-entry with a defaulted method ('GET') and no request data.
   Now it is lookup-only, mirroring loadingFinished.

3. evaluateInFrame had no retry on a stale cached context. A navigated/
   reloaded frame invalidates its cached execution-context id, but the
   executionContextDestroyed event may not be processed yet, so
   Runtime.evaluate rejects with "Cannot find context with specified id".
   Now that rejection drops the stale id and falls through to the
   frame-target path (mirrors evaluate()'s re-resolution); genuine page
   errors still propagate.

Tests: redirect-body preservation, orphan-entry prevention, and
stale-context fallback — all reverse-validated. cdp suite 15/15, tsc
clean, extension/dist rebuilt.
wearzdk added a commit to wearzdk/OpenCLI that referenced this pull request Jun 26, 2026
wearzdk added a commit to wearzdk/OpenCLI that referenced this pull request Jun 26, 2026
…apture across ensureAttached re-attach

冲突解决:jackwener#1984jackwener#1978 各自在 cdp.test.ts 同位置追加 describe 块,
保留全部三个块(correctness / evaluateInFrame / survives-reattach)。
dist/background.js 留待 build 阶段重建。
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