From 5c416e0deaa82a7e8f3d81e438cb6dcf8e50a968 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov Date: Tue, 21 Oct 2025 18:54:21 +0200 Subject: [PATCH 1/3] feat: support previous navigation for Console messages --- src/McpContext.ts | 6 ++++-- src/McpResponse.ts | 7 ++++++- src/tools/ToolDefinition.ts | 1 + src/tools/console.ts | 6 ++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/McpContext.ts b/src/McpContext.ts index fd5e7536..07f107e6 100644 --- a/src/McpContext.ts +++ b/src/McpContext.ts @@ -145,9 +145,11 @@ export class McpContext implements Context { return this.#networkCollector.getData(page, includePreviousNavigations); } - getConsoleData(): Array { + getConsoleData( + includePreviousNavigations?: boolean, + ): Array { const page = this.getSelectedPage(); - return this.#consoleCollector.getData(page); + return this.#consoleCollector.getData(page, includePreviousNavigations); } getConsoleMessageStableId(message: ConsoleMessage | Error): number { diff --git a/src/McpResponse.ts b/src/McpResponse.ts index f937519c..584a2d49 100644 --- a/src/McpResponse.ts +++ b/src/McpResponse.ts @@ -46,6 +46,7 @@ export class McpResponse implements Response { include: boolean; pagination?: PaginationOptions; types?: string[]; + includePreviousNavigations?: boolean; }; setIncludePages(value: boolean): void { @@ -87,6 +88,7 @@ export class McpResponse implements Response { value: boolean, options?: PaginationOptions & { types?: string[]; + includePreviousNavigations?: boolean; }, ): void { if (!value) { @@ -104,6 +106,7 @@ export class McpResponse implements Response { } : undefined, types: options?.types, + includePreviousNavigations: options?.includePreviousNavigations, }; } @@ -228,7 +231,9 @@ export class McpResponse implements Response { let consoleListData: ConsoleMessageData[] | undefined; if (this.#consoleDataOptions?.include) { - let messages = context.getConsoleData(); + let messages = context.getConsoleData( + this.#consoleDataOptions.includePreviousNavigations, + ); if (this.#consoleDataOptions.types?.length) { const normalizedTypes = new Set(this.#consoleDataOptions.types); diff --git a/src/tools/ToolDefinition.ts b/src/tools/ToolDefinition.ts index 0e0691be..d36d473d 100644 --- a/src/tools/ToolDefinition.ts +++ b/src/tools/ToolDefinition.ts @@ -56,6 +56,7 @@ export interface Response { value: boolean, options?: PaginationOptions & { types?: string[]; + includePreviousNavigations?: boolean; }, ): void; setIncludeSnapshot(value: boolean): void; diff --git a/src/tools/console.ts b/src/tools/console.ts index 2a56efb7..324e04a1 100644 --- a/src/tools/console.ts +++ b/src/tools/console.ts @@ -66,12 +66,18 @@ export const listConsoleMessages = defineTool({ .describe( 'Filter messages to only return messages of the specified resource types. When omitted or empty, returns all messages.', ), + includePreviousNavigations: zod + .boolean() + .default(false) + .optional() + .describe('Whether to include messages from previous navigations.'), }, handler: async (request, response) => { response.setIncludeConsoleData(true, { pageSize: request.params.pageSize, pageIdx: request.params.pageIdx, types: request.params.types, + includePreviousNavigations: request.params.includePreviousNavigations, }); }, }); From 513fe5ab0996c6738e11617a79e65c24066e6522 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov Date: Tue, 21 Oct 2025 18:55:46 +0200 Subject: [PATCH 2/3] docs --- docs/tool-reference.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/tool-reference.md b/docs/tool-reference.md index d7cbc2f4..3a9cdc34 100644 --- a/docs/tool-reference.md +++ b/docs/tool-reference.md @@ -287,15 +287,16 @@ so returned values have to JSON-serializable. - **args** (array) _(optional)_: An optional list of arguments to pass to the function. - **function** (string) **(required)**: A JavaScript function declaration to be executed by the tool in the currently selected page. - Example without arguments: `() => { +Example without arguments: `() => { return document.title }` or `async () => { return await fetch("example.com") }`. - Example with arguments: `(el) => { +Example with arguments: `(el) => { return el.innerText; }` + --- ### `get_console_message` @@ -314,6 +315,7 @@ so returned values have to JSON-serializable. **Parameters:** +- **includePreviousNavigations** (boolean) _(optional)_: Whether to include messages from previous navigations. - **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page. - **pageSize** (integer) _(optional)_: Maximum number of messages to return. When omitted, returns all requests. - **types** (array) _(optional)_: Filter messages to only return messages of the specified resource types. When omitted or empty, returns all messages. From b40cd4ec2d6c0e66cc1d3ca0ecd10677d532fca8 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov Date: Tue, 21 Oct 2025 18:55:51 +0200 Subject: [PATCH 3/3] docs --- docs/tool-reference.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/tool-reference.md b/docs/tool-reference.md index 3a9cdc34..c300c341 100644 --- a/docs/tool-reference.md +++ b/docs/tool-reference.md @@ -287,16 +287,15 @@ so returned values have to JSON-serializable. - **args** (array) _(optional)_: An optional list of arguments to pass to the function. - **function** (string) **(required)**: A JavaScript function declaration to be executed by the tool in the currently selected page. -Example without arguments: `() => { + Example without arguments: `() => { return document.title }` or `async () => { return await fetch("example.com") }`. -Example with arguments: `(el) => { + Example with arguments: `(el) => { return el.innerText; }` - --- ### `get_console_message`