Skip to content

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

Open
ZayanKhan-12 wants to merge 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:fix/truncate-network-urls
Open

fix: truncate long urls in concise network request output#2513
ZayanKhan-12 wants to merge 1 commit 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.

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.
@ZayanKhan-12
ZayanKhan-12 force-pushed the fix/truncate-network-urls branch from 1837d22 to 0cb60cf Compare August 8, 2026 21:46
} from '../third_party/index.js';

const BODY_CONTEXT_SIZE_LIMIT = 10000;
const URL_CONTEXT_SIZE_LIMIT = 150;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const URL_CONTEXT_SIZE_LIMIT = 150;
const URL_CONTEXT_SIZE_LIMIT = 255;

Let's use a longer limit to make sure more URLs are fully visible.

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