Skip to content

fix: truncate long urls in concise network request output - #2513

Merged
OrKoN merged 2 commits into
ChromeDevTools:mainfrom
ZayanKhan-12:fix/truncate-network-urls
Sep 1, 2026
Merged

fix: truncate long urls in concise network request output#2513
OrKoN merged 2 commits into
ChromeDevTools:mainfrom
ZayanKhan-12:fix/truncate-network-urls

Conversation

@ZayanKhan-12

Copy link
Copy Markdown
Contributor

What

Implements the existing // TODO truncate the URL in src/formatters/NetworkFormatter.ts: URLs in the concise one-line network request format are now capped at 150 characters, with the file's existing getSizeLimitedString helper appending the same ... <truncated> marker already used for request/response bodies.

Why

list_network_requests emits one concise line per request, so a single page with a few data: URLs (which can be tens of kilobytes each) can blow up the tool output by orders of magnitude. Truncating in the concise format keeps list output token-friendly while losing nothing that matters for identifying a request.

Scope is deliberately narrow — only convertNetworkRequestConciseToString changes:

  • the detailed view (## Request <url> heading) still shows the full URL, and
  • toJSON() / structured content still carries the full URL,

so nothing that needs the complete URL is affected. (Concise redirect-chain lines inside the detailed view use the same function and are truncated too, which keeps that list compact as well.)

Limit rationale

150 characters keeps origin + path + the start of the query string intact for virtually all real-world URLs (typical URLs are well under 100 characters), while capping pathological data:/blob payloads. It reuses the existing getSizeLimitedString pattern with a new URL_CONTEXT_SIZE_LIMIT constant next to BODY_CONTEXT_SIZE_LIMIT.

Before / after

Before:

reqid=12 GET data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA... (10,000+ more chars) ...5CYII= [200]

After:

reqid=12 GET data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...(150 chars total)... <truncated> [200]

Short URLs are unchanged.

Testing

  • npm run build — pass
  • npm run test:no-build — pass (all tests, exit 0)
  • npm run check-format — pass (eslint + prettier)

Added three cases to tests/formatters/NetworkFormatter.test.ts:

  • long URL is truncated at 150 chars with the ... <truncated> marker (and toJSON() keeps the full URL),
  • data: URL is truncated,
  • a URL exactly at the limit is left untouched.

No existing snapshots changed.

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Aug 8, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ZayanKhan-12
ZayanKhan-12 force-pushed the fix/truncate-network-urls branch from 1837d22 to 0cb60cf Compare August 8, 2026 21:46
Comment thread src/formatters/NetworkFormatter.ts Outdated
@OrKoN
OrKoN self-requested a review August 21, 2026 19:08
Resolves the existing TODO in NetworkFormatter. Long URLs (especially
data: URLs, which can be tens of kilobytes) bloated every line of the
token-heavy list_network_requests output. Reuse the file's existing
getSizeLimitedString helper to cap URLs at 150 characters in the
concise one-line format only; the detailed view and the structured
JSON content keep the full URL.
@OrKoN
OrKoN force-pushed the fix/truncate-network-urls branch from 78994b5 to e4eaf36 Compare September 1, 2026 12:35
@OrKoN
OrKoN enabled auto-merge September 1, 2026 12:36
@OrKoN
OrKoN force-pushed the fix/truncate-network-urls branch from e4eaf36 to 9fc2def Compare September 1, 2026 13:07
@OrKoN
OrKoN added this pull request to the merge queue Sep 1, 2026
Merged via the queue into ChromeDevTools:main with commit 552c870 Sep 1, 2026
36 of 40 checks passed
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.

3 participants