fix(network): keep redirect chain order consistent between text and JSON#2221
Merged
nroscino merged 1 commit intoJun 18, 2026
Merged
Conversation
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.
Merged
via the queue into
ChromeDevTools:main
with commit Jun 18, 2026
5a9d6af
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
get_network_requestreturns, from the same call, both a human-readabletext block (
toStringDetailed()) and astructuredContent.networkRequestobject (
toJSONDetailed()) — emitted together inMcpResponse.ts. For arequest that went through HTTP redirects, the redirect chain comes out in
opposite orders in the two representations:
toJSONDetailed()(NetworkFormatter.ts) reversesredirectChain()once →newest→oldest in the JSON.
text.
Because each path calls
redirectChain()separately and Puppeteer returns afresh copy on every call (
HTTPRequest#redirectChain()doesthis._redirectChain.slice()), the two reverses operate on different arrays anddon'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 usesthe order already produced by
toJSONDetailed(). Both representations are nowconsistent (newest→oldest), and
structuredContentis unchanged.Why the existing tests didn't catch it
where reversing is a no-op.
getMockRequest().redirectChain()returned the same array reference onevery 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 testfor the formatter suite passes. New testrenders the redirect chain in the same order in text and JSONis redbefore the fix (text
[first, second]vs JSON[second, first]) and greenafter, with no change to existing snapshots.
npm run typecheckand Prettier/ESLint are clean.No existing issue tracked this; found via code inspection and confirmed
empirically.