Chrome DevTools for coding agents
fix(pagination): return all items when pageSize is omitted and pageIdx is 0 (#2996) (#3134)
Yuri (IURII) Trukhin3ad91159fec4
diff --git a/docs/tool-reference.md b/docs/tool-reference.mdindex c435aa80..aedca776 100644--- a/docs/tool-reference.md+++ b/docs/tool-reference.md@@ -369,7 +369,7 @@- **pageId** (number) **(required)**: Targets a specific page by ID.- **includePreservedRequests** (boolean) _(optional)_: Set to true to return the preserved requests over the last 3 navigations.-- **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page.+- **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page. Ignored unless pageSize is set.- **pageSize** (integer) _(optional)_: Maximum number of requests to return. When omitted, returns all requests.- **resourceTypes** (array) _(optional)_: Filter requests to only return requests of the specified resource types. When omitted or empty, returns all requests.@@ -447,7 +447,7 @@ Results are paginated (10 rules per page by default); use pageIdx to page throug- **pageId** (number) **(required)**: Targets a specific page by ID.- **includePreservedMessages** (boolean) _(optional)_: Set to true to return the preserved messages over the last 3 navigations.- **includeStackTraces** (boolean) _(optional)_: Set to true to include the stack trace for each message when available. Increases the response size.-- **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page.+- **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page. Ignored unless pageSize is set.- **pageSize** (integer) _(optional)_: Maximum number of messages to return. When omitted, returns all messages.- **serviceWorkerId** (string) _(optional)_: Filter messages by the service worker ID shown by [`list_pages`](#list_pages) (sw-N).- **types** (array) _(optional)_: Filter messages to only return messages of the specified resource types. When omitted or empty, returns all messages.diff --git a/src/McpResponse.ts b/src/McpResponse.tsindex f272c29b..9d7fc2d0 100644--- a/src/McpResponse.ts+++ b/src/McpResponse.ts@@ -235,7 +235,7 @@ export class McpResponse implements Response {this.#networkRequestsOptions = {include: value,pagination:- options?.pageSize !== undefined || options?.pageIdx !== undefined+ options?.pageSize !== undefined? {pageSize: options.pageSize,pageIdx: options.pageIdx,@@ -264,7 +264,7 @@ export class McpResponse implements Response {this.#consoleDataOptions = {include: value,pagination:- options?.pageSize !== undefined || options?.pageIdx !== undefined+ options?.pageSize !== undefined? {pageSize: options.pageSize,pageIdx: options.pageIdx,diff --git a/src/config/cli-options.ts b/src/config/cli-options.tsindex 77ff34e8..d8177a60 100644--- a/src/config/cli-options.ts+++ b/src/config/cli-options.ts@@ -1301,7 +1301,7 @@ export const commands: Commands = {name: 'pageIdx',type: 'integer',description:- 'Page number to return (0-based). When omitted, returns the first page.',+ 'Page number to return (0-based). When omitted, returns the first page. Ignored unless pageSize is set.',required: false,positional: false,},@@ -1371,7 +1371,7 @@ export const commands: Commands = {name: 'pageIdx',type: 'integer',description:- 'Page number to return (0-based). When omitted, returns the first page.',+ 'Page number to return (0-based). When omitted, returns the first page. Ignored unless pageSize is set.',required: false,positional: false,},diff --git a/src/third_party/index.ts b/src/third_party/index.tsindex cf159cd8..fc56fdbb 100644--- a/src/third_party/index.ts+++ b/src/third_party/index.ts@@ -45,6 +45,7 @@ export type ShapeOutput<T extends zod.ZodRawShape> = zod.output<export {default as ajv} from 'ajv';export {Accessibility,+ ConsoleMessage,Dialog,ElementHandle,Locator,diff --git a/src/tools/console.ts b/src/tools/console.tsindex 99f5d1dc..f1b35db9 100644--- a/src/tools/console.ts+++ b/src/tools/console.ts@@ -64,7 +64,7 @@ export const listConsoleMessages = definePageTool(.min(0).optional().describe(- 'Page number to return (0-based). When omitted, returns the first page.',+ 'Page number to return (0-based). When omitted, returns the first page. Ignored unless pageSize is set.',),types: zod.array(zod.enum(FILTERABLE_MESSAGE_TYPES))diff --git a/src/tools/network.ts b/src/tools/network.tsindex fd124b9f..c8968932 100644--- a/src/tools/network.ts+++ b/src/tools/network.ts@@ -54,7 +54,7 @@ export const listNetworkRequests = definePageTool(() => ({.min(0).optional().describe(- 'Page number to return (0-based). When omitted, returns the first page.',+ 'Page number to return (0-based). When omitted, returns the first page. Ignored unless pageSize is set.',),resourceTypes: zod.array(zod.enum(FILTERABLE_RESOURCE_TYPES))diff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.tsindex 62a358a6..75a7cc70 100644--- a/tests/McpResponse.test.ts+++ b/tests/McpResponse.test.ts@@ -35,6 +35,7 @@ import {serverHooks} from './server.js';import {loadTraceAsBuffer} from './trace-processing/fixtures/load.js';import {createHandlerMocks,+ createMockConsoleMessage,createMockHeapSnapshotAggregate,createMockCSSMatchedStyles,createMockCSSProperty,@@ -892,19 +893,32 @@ describe('McpResponse network pagination', () => {});});- it('paginates the first page when pageIdx is 0 without pageSize', async () => {+ it('returns all items when pageIdx is 0 without pageSize', async () => {await withMcpContext(async (response, context) => {const requests = Array.from({length: 30}, (_, idx) =>getMockRequest({method: `GET-${idx}`}),);context.getSelectedMcpPage().getNetworkRequests = () => requests;- // pageIdx 0 is a valid page, not "no pagination" — it must apply the- // default page size like any other page.response.setIncludeNetworkRequests(true, {pageIdx: 0});const {content} = await response.handle(context);const text = getTextContent(content[0]);- assert.ok(text.includes('Showing 1-20 of 30 (Page 1 of 2).'));- assert.ok(text.includes('Next page: 1'));+ assert.ok(text.includes('Showing 1-30 of 30 (Page 1 of 1).'));+ assert.ok(!text.includes('Next page:'));+ assert.ok(!text.includes('Previous page:'));+ });+ });++ it('returns all console messages when pageIdx is 0 without pageSize', async () => {+ await withMcpContext(async (response, context) => {+ const messages = Array.from({length: 30}, (_, idx) =>+ createMockConsoleMessage({text: `msg-${idx}`}),+ );+ context.getSelectedMcpPage().getConsoleData = () => messages;+ response.setIncludeConsoleData(true, {pageIdx: 0});+ const {content} = await response.handle(context);+ const text = getTextContent(content[0]);+ assert.ok(text.includes('Showing 1-30 of 30 (Page 1 of 1).'));+ assert.ok(!text.includes('Next page:'));assert.ok(!text.includes('Previous page:'));});});diff --git a/tests/mocks.ts b/tests/mocks.tsindex f587b30c..45608a70 100644--- a/tests/mocks.ts+++ b/tests/mocks.ts@@ -54,6 +54,7 @@ import {CdpPage,CDPSession,Connection,+ ConsoleMessage,DevTools,Dialog,ElementHandle,@@ -68,7 +69,10 @@ import {import type {Browser,BrowserContext,+ ConsoleMessageLocation,+ ConsoleMessageType,Extension,+ JSHandle,Page,Protocol,Realm,@@ -1377,3 +1381,19 @@ export function createMockHeapSnapshotAggregate(retainedSize: options.retainedSize ?? 100,};}++export function createMockConsoleMessage(+ options: {+ type?: ConsoleMessageType;+ text?: string;+ args?: JSHandle[];+ location?: ConsoleMessageLocation;+ } = {},+): sinon.SinonStubbedInstance<ConsoleMessage> {+ const message = sinon.createStubInstance(ConsoleMessage);+ message.type.returns(options.type ?? 'log');+ message.text.returns(options.text ?? '');+ message.args.returns(options.args ?? []);+ message.location.returns(options.location ?? {});+ return message;+}diff --git a/tests/utils/pagination.test.ts b/tests/utils/pagination.test.tsnew file mode 100644index 00000000..517712d1--- /dev/null+++ b/tests/utils/pagination.test.ts@@ -0,0 +1,47 @@+/**+ * @license+ * Copyright 2026 Google LLC+ * SPDX-License-Identifier: Apache-2.0+ */++import assert from 'node:assert';+import {describe, it} from 'node:test';++import {paginate} from '../../src/utils/pagination.js';++describe('paginate', () => {+ it('returns all items when no pagination options are provided', () => {+ const items = Array.from({length: 25}, (_, i) => `item-${i}`);+ const result = paginate(items);+ assert.strictEqual(result.items.length, 25);+ assert.strictEqual(result.currentPage, 0);+ assert.strictEqual(result.totalPages, 1);+ assert.strictEqual(result.hasNextPage, false);+ assert.strictEqual(result.hasPreviousPage, false);+ assert.strictEqual(result.invalidPage, false);+ });++ it('uses default page size of 20 when pageIdx is provided without pageSize', () => {+ const items = Array.from({length: 25}, (_, i) => `item-${i}`);+ const result = paginate(items, {pageIdx: 1});+ assert.strictEqual(result.items.length, 5);+ assert.strictEqual(result.items[0], 'item-20');+ assert.strictEqual(result.currentPage, 1);+ assert.strictEqual(result.totalPages, 2);+ assert.strictEqual(result.hasNextPage, false);+ assert.strictEqual(result.hasPreviousPage, true);+ assert.strictEqual(result.invalidPage, false);+ });++ it('paginates normally when pageSize is provided', () => {+ const items = Array.from({length: 25}, (_, i) => `item-${i}`);+ const result = paginate(items, {pageSize: 10, pageIdx: 1});+ assert.strictEqual(result.items.length, 10);+ assert.strictEqual(result.items[0], 'item-10');+ assert.strictEqual(result.currentPage, 1);+ assert.strictEqual(result.totalPages, 3);+ assert.strictEqual(result.hasNextPage, true);+ assert.strictEqual(result.hasPreviousPage, true);+ assert.strictEqual(result.invalidPage, false);+ });+});