Skip to content

Chrome DevTools for coding agents

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

Zayan Khan552c870d3cb8
diff --git a/src/formatters/NetworkFormatter.ts b/src/formatters/NetworkFormatter.ts
index a7647d22..3b751074 100644
--- a/src/formatters/NetworkFormatter.ts
+++ b/src/formatters/NetworkFormatter.ts
@@ -13,6 +13,7 @@ import {
} from '../third_party/index.js';
const BODY_CONTEXT_SIZE_LIMIT = 10000;
+const URL_CONTEXT_SIZE_LIMIT = 255;
export interface NetworkFormatterOptions {
requestId?: number | string;
@@ -263,8 +264,10 @@ function getSizeLimitedString(text: string, sizeLimit: number) {
function convertNetworkRequestConciseToString(
data: NetworkRequestConcise,
): string {
- // TODO truncate the URL
- return `reqid=${data.requestId} ${data.method} ${data.url} [${data.status}]${data.selectedInDevToolsUI ? ` [selected in the DevTools Network panel]` : ''}`;
+ // Long URLs (e.g., data: URLs) bloat the concise list output. The full URL
+ // remains available via the detailed view and the structured content.
+ const url = getSizeLimitedString(data.url, URL_CONTEXT_SIZE_LIMIT);
+ return `reqid=${data.requestId} ${data.method} ${url} [${data.status}]${data.selectedInDevToolsUI ? ` [selected in the DevTools Network panel]` : ''}`;
}
function formatHeaders(headers: Record<string, string>): string[] {
diff --git a/tests/formatters/NetworkFormatter.test.ts b/tests/formatters/NetworkFormatter.test.ts
index 7a75fd35..364b6aa6 100644
--- a/tests/formatters/NetworkFormatter.test.ts
+++ b/tests/formatters/NetworkFormatter.test.ts
@@ -132,6 +132,51 @@ describe('NetworkFormatter', () => {
'reqid=1 GET http://example.com [pending] [selected in the DevTools Network panel]',
);
});
+
+ it('truncates long urls', async () => {
+ const longUrl = `http://example.com/${'a'.repeat(500)}`;
+ const request = getMockRequest({url: longUrl});
+ const formatter = await NetworkFormatter.from(request, {
+ requestId: 1,
+ saveFile: async () => ({filename: ''}),
+ redactNetworkHeaders: false,
+ });
+
+ assert.equal(
+ formatter.toString(),
+ `reqid=1 GET ${longUrl.substring(0, 255)}... <truncated> [pending]`,
+ );
+ // The structured data keeps the full URL.
+ assert.equal(formatter.toJSON().url, longUrl);
+ });
+
+ it('truncates data: urls', async () => {
+ const dataUrl = `data:image/png;base64,${'A'.repeat(5000)}`;
+ const request = getMockRequest({url: dataUrl});
+ const formatter = await NetworkFormatter.from(request, {
+ requestId: 1,
+ saveFile: async () => ({filename: ''}),
+ redactNetworkHeaders: false,
+ });
+
+ assert.equal(
+ formatter.toString(),
+ `reqid=1 GET ${dataUrl.substring(0, 255)}... <truncated> [pending]`,
+ );
+ });
+
+ it('does not truncate urls within the size limit', async () => {
+ // Exactly at the 150 character limit.
+ const url = `http://example.com/${'a'.repeat(131)}`;
+ const request = getMockRequest({url});
+ const formatter = await NetworkFormatter.from(request, {
+ requestId: 1,
+ saveFile: async () => ({filename: ''}),
+ redactNetworkHeaders: false,
+ });
+
+ assert.equal(formatter.toString(), `reqid=1 GET ${url} [pending]`);
+ });
});
describe('toStringDetailed', () => {