Skip to content

fix(network): keep redirect chain order consistent between text and JSON#2221

Merged
nroscino merged 1 commit into
ChromeDevTools:mainfrom
nyxst4ck:fix/network-redirect-chain-order
Jun 18, 2026
Merged

fix(network): keep redirect chain order consistent between text and JSON#2221
nroscino merged 1 commit into
ChromeDevTools:mainfrom
nyxst4ck:fix/network-redirect-chain-order

Conversation

@nyxst4ck

Copy link
Copy Markdown
Contributor

Problem

get_network_request returns, from the same call, both a human-readable
text block (toStringDetailed()) and a structuredContent.networkRequest
object (toJSONDetailed()) — emitted together in McpResponse.ts. For a
request that went through HTTP redirects, the redirect chain comes out in
opposite orders in the two representations:

  • toJSONDetailed() (NetworkFormatter.ts) reverses redirectChain() once →
    newest→oldest in the JSON.
  • the text formatter then reverses it a second time → oldest→newest in the
    text.

Because each path calls redirectChain() separately and Puppeteer returns a
fresh copy on every call (HTTPRequest#redirectChain() does
this._redirectChain.slice()), the two reverses operate on different arrays and
don't cancel. So a consumer reading the text and a consumer parsing the
structured JSON from the same response see contradictory redirect orders.

Solution

Drop the redundant .reverse() in the text formatter so the rendered text uses
the order already produced by toJSONDetailed(). Both representations are now
consistent (newest→oldest), and structuredContent is unchanged.

Why the existing tests didn't catch it

  • The existing "handles redirect chain" test uses a single-element chain,
    where reversing is a no-op.
  • getMockRequest().redirectChain() returned the same array reference on
    every call, unlike real Puppeteer — so the two reverses accidentally agreed in
    tests. This PR makes the mock return a fresh copy per call (matching Puppeteer)
    and adds a regression test with a multi-element chain that asserts the text and
    JSON orders match.

Testing

  • npm test for the formatter suite passes. New test
    renders the redirect chain in the same order in text and JSON is red
    before the fix (text [first, second] vs JSON [second, first]) and green
    after, with no change to existing snapshots.
  • npm run typecheck and Prettier/ESLint are clean.

No existing issue tracked this; found via code inspection and confirmed
empirically.

get_network_request returns both a human-readable text block and a
structuredContent.networkRequest object from the same call. For a request with
HTTP redirects the chain came out in opposite orders: toJSONDetailed() reverses
redirectChain() once (newest->oldest) while the text formatter reversed it a
second time (oldest->newest). Each path calls redirectChain() separately and
Puppeteer returns a fresh copy per call, so the two reverses act on different
arrays and don't cancel -- text and JSON always disagreed.

Drop the redundant reverse in the text formatter so both representations use the
order produced by toJSONDetailed(). Also make the test helper's redirectChain()
return a fresh copy per call (as Puppeteer does) and add a multi-element
regression test.

@nroscino nroscino left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thank you!

@nroscino nroscino enabled auto-merge June 18, 2026 17:14
@nroscino nroscino added this pull request to the merge queue Jun 18, 2026
Merged via the queue into ChromeDevTools:main with commit 5a9d6af Jun 18, 2026
26 of 28 checks passed
pull Bot pushed a commit to Spencerx/chrome-devtools-mcp that referenced this pull request Jun 23, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.4.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v1.3.0...chrome-devtools-mcp-v1.4.0)
(2026-06-23)


### 🎉 Features

* publish the skills folder
([ChromeDevTools#2229](ChromeDevTools#2229))
([5367f7e](ChromeDevTools@5367f7e))


### 🛠️ Fixes

* hide Windows update check consoles
([ChromeDevTools#2231](ChromeDevTools#2231))
([6225ffb](ChromeDevTools@6225ffb))
* **network:** keep redirect chain order consistent between text and
JSON
([ChromeDevTools#2221](ChromeDevTools#2221))
([5a9d6af](ChromeDevTools@5a9d6af))


### 📄 Documentation

* fix showing defaults in configuration
([ChromeDevTools#2234](ChromeDevTools#2234))
([38dd346](ChromeDevTools@38dd346))
* **readme:** explicitly call out that CD4A can power your browser agent
([ChromeDevTools#2227](ChromeDevTools#2227))
([705d0e1](ChromeDevTools@705d0e1))
* update security.md
([ChromeDevTools#2248](ChromeDevTools#2248))
([e559765](ChromeDevTools@e559765))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants