From a0d6782e3a3dff0c59f3d39c0aad9ce7c41872a8 Mon Sep 17 00:00:00 2001 From: Nicholas Roscino Date: Wed, 18 Nov 2026 12:24:12 +0100 Subject: [PATCH 1/3] fix: add service workers to get_console_message --- docs/tool-reference.md | 1 + src/McpContext.ts | 23 +++++-- src/McpResponse.ts | 27 +++++++-- src/collectors/ServiceWorkerCollector.ts | 8 ++- src/config/cli-options.ts | 8 +++ src/telemetry/tool_call_metrics.json | 4 ++ src/tools/ToolDefinition.ts | 5 +- src/tools/console.ts | 10 ++- tests/McpContext.test.ts | 77 ++++++++++++++++++++++++ tests/tools/console.test.ts | 22 ++++++- 10 files changed, 170 insertions(+), 15 deletions(-) diff --git a/docs/tool-reference.md b/docs/tool-reference.md index 2e37ddda0d..bf6ab79633 100644 --- a/docs/tool-reference.md +++ b/docs/tool-reference.md @@ -413,6 +413,7 @@ - **msgid** (number) **(required)**: The msgid of a console message on the page from the listed console messages - **pageId** (number) **(required)**: Targets a specific page by ID. +- **serviceWorkerId** (string) _(optional)_: Get the message from the service worker with this ID shown by [`list_pages`](#list_pages) (sw-N) instead of the page. Use the msgid listed for that service worker. --- diff --git a/src/McpContext.ts b/src/McpContext.ts index e6162204c9..f6b63cdfe2 100644 --- a/src/McpContext.ts +++ b/src/McpContext.ts @@ -841,17 +841,32 @@ export class McpContext implements Context, BrowserlessContext { return Array.from(this.#workers.values()); } - getServiceWorkerConsoleData( - serviceWorkerId: string, - ): Array { + #getServiceWorkerExtensionId(serviceWorkerId: string): string { const worker = this.getWorkerById(serviceWorkerId); if (worker?.type !== 'service_worker') { throw new Error('Service worker not found.'); } - const extensionId = new URL(worker.url).hostname; + return new URL(worker.url).hostname; + } + + getServiceWorkerConsoleData( + serviceWorkerId: string, + ): Array { + const extensionId = this.#getServiceWorkerExtensionId(serviceWorkerId); return this.#serviceWorkerConsoleCollector?.getData(extensionId) ?? []; } + getServiceWorkerConsoleMessageById( + serviceWorkerId: string, + msgid: number, + ): ConsoleMessage | UncaughtError { + const extensionId = this.#getServiceWorkerExtensionId(serviceWorkerId); + if (!this.#serviceWorkerConsoleCollector) { + throw new Error('Service worker console data is not available.'); + } + return this.#serviceWorkerConsoleCollector.getById(extensionId, msgid); + } + #getBrowserContextToNameMap(): Map { // Build a reverse lookup from BrowserContext instance → name. const contextToName = new Map(); diff --git a/src/McpResponse.ts b/src/McpResponse.ts index 2c6318eb48..519795f2ea 100644 --- a/src/McpResponse.ts +++ b/src/McpResponse.ts @@ -108,6 +108,7 @@ export class McpResponse implements Response { responseFilePath?: string; }; #attachedConsoleMessageId?: number; + #attachedConsoleMessageServiceWorkerId?: string; #attachedTraceSummary?: TraceResult; #attachedTraceInsight?: TraceInsightData; #attachedLighthouseResult?: LighthouseData; @@ -311,8 +312,12 @@ export class McpResponse implements Response { this.#attachedNetworkRequestOptions = options; } - attachConsoleMessage(msgid: number): void { + attachConsoleMessage( + msgid: number, + options?: {serviceWorkerId?: string}, + ): void { this.#attachedConsoleMessageId = msgid; + this.#attachedConsoleMessageServiceWorkerId = options?.serviceWorkerId; } attachWebAuthnAuthenticator( @@ -598,19 +603,29 @@ export class McpResponse implements Response { }); } - async #handleAttachedConsoleMessage(): Promise< - ConsoleFormatter | IssueFormatter | undefined - > { + async #handleAttachedConsoleMessage( + context: McpContext, + ): Promise { if (!this.#attachedConsoleMessageId) { return undefined; } + const consoleMessageStableId = this.#attachedConsoleMessageId; + if (this.#attachedConsoleMessageServiceWorkerId) { + // Service workers have no DevTools universe, like in the list tool. + return await ConsoleFormatter.from( + context.getServiceWorkerConsoleMessageById( + this.#attachedConsoleMessageServiceWorkerId, + consoleMessageStableId, + ), + {id: consoleMessageStableId, fetchDetailedData: true}, + ); + } if (!this.#page) { throw new Error(`Response must have an McpPage`); } const message = this.#page.getConsoleMessageById( this.#attachedConsoleMessageId, ); - const consoleMessageStableId = this.#attachedConsoleMessageId; if ('args' in message || message instanceof UncaughtError) { const consoleMessage = message as ConsoleMessage | UncaughtError; return await ConsoleFormatter.from(consoleMessage, { @@ -860,7 +875,7 @@ export class McpResponse implements Response { ] = await Promise.all([ this.#handleSnapshot(context), this.#handleAttachedNetworkRequest(context), - this.#handleAttachedConsoleMessage(), + this.#handleAttachedConsoleMessage(context), this.#handleThirdPartyDeveloperTools(), this.#handleWebMCP(), this.#handleConsoleList(context), diff --git a/src/collectors/ServiceWorkerCollector.ts b/src/collectors/ServiceWorkerCollector.ts index 3487f018ee..d2e4f3ef28 100644 --- a/src/collectors/ServiceWorkerCollector.ts +++ b/src/collectors/ServiceWorkerCollector.ts @@ -183,13 +183,17 @@ export class ServiceWorkerConsoleCollector { ): WithSymbolId { const logs = this.#storage.get(extensionId); if (!logs) { - throw new Error('No logs found for selected extension'); + throw new Error( + `No console messages found for extension ${extensionId}.`, + ); } const item = logs.find(item => item[stableIdSymbol] === stableId); if (item) { return item; } - throw new Error('Log not found for selected extension'); + throw new Error( + `Console message ${stableId} not found for extension ${extensionId}.`, + ); } find( diff --git a/src/config/cli-options.ts b/src/config/cli-options.ts index e113887601..63ce0ba467 100644 --- a/src/config/cli-options.ts +++ b/src/config/cli-options.ts @@ -641,6 +641,14 @@ export const commands: Commands = { required: true, positional: true, }, + serviceWorkerId: { + name: 'serviceWorkerId', + type: 'string', + description: + 'Get the message from the service worker with this ID shown by list_pages (sw-N) instead of the page. Use the msgid listed for that service worker.', + required: false, + positional: false, + }, }, }, get_css_styles: { diff --git a/src/telemetry/tool_call_metrics.json b/src/telemetry/tool_call_metrics.json index 5f0924540d..e822c355a6 100644 --- a/src/telemetry/tool_call_metrics.json +++ b/src/telemetry/tool_call_metrics.json @@ -220,6 +220,10 @@ { "name": "page_id", "argType": "number" + }, + { + "name": "service_worker_id_length", + "argType": "number" } ] }, diff --git a/src/tools/ToolDefinition.ts b/src/tools/ToolDefinition.ts index 8aafdb9464..03d045d9e0 100644 --- a/src/tools/ToolDefinition.ts +++ b/src/tools/ToolDefinition.ts @@ -320,7 +320,10 @@ export interface Response { reqId: number, options?: {requestFilePath?: string; responseFilePath?: string}, ): void; - attachConsoleMessage(msgid: number): void; + attachConsoleMessage( + msgid: number, + options?: {serviceWorkerId?: string}, + ): void; attachWebAuthnAuthenticator( authenticator: WebAuthnAuthenticatorState | undefined, ): void; diff --git a/src/tools/console.ts b/src/tools/console.ts index ef1488cbe4..0cf994615b 100644 --- a/src/tools/console.ts +++ b/src/tools/console.ts @@ -124,11 +124,19 @@ export const getConsoleMessage: PageToolFactory = definePageTool(() => ({ .describe( 'The msgid of a console message on the page from the listed console messages', ), + serviceWorkerId: zod + .string() + .optional() + .describe( + 'Get the message from the service worker with this ID shown by list_pages (sw-N) instead of the page. Use the msgid listed for that service worker.', + ), }, blockedByDialog: false, concurrency: 'page', verifyFilesSchema: {}, handler: async (request, response) => { - response.attachConsoleMessage(request.params.msgid); + response.attachConsoleMessage(request.params.msgid, { + serviceWorkerId: request.params.serviceWorkerId, + }); }, })); diff --git a/tests/McpContext.test.ts b/tests/McpContext.test.ts index b34199a72b..ce11e91f17 100644 --- a/tests/McpContext.test.ts +++ b/tests/McpContext.test.ts @@ -207,6 +207,83 @@ describe('McpContext', () => { }); } }); + + describe('getServiceWorkerConsoleMessageById', () => { + it('resolves the service worker ID to the collector extension ID', async () => { + const browser = createMockPuppeteerBrowser(); + browser.targets.returns([]); + const context = await createConnectedMcpContext( + browser, + { + config: createMockServerConfig({ + performanceCrux: false, + }), + heapSnapshotManager: new HeapSnapshotManager(new TaskRunner()), + }, + Locator, + ); + const worker = createMockMcpWorker({ + id: 'sw-3', + url: 'chrome-extension://extension-id/background.js', + }); + const getWorkerById = sinon + .stub(context, 'getWorkerById') + .returns(worker); + const message = Object.assign( + new UncaughtError( + { + exceptionId: 1, + text: 'Service worker error', + lineNumber: 0, + columnNumber: 0, + }, + 'extension-id', + ), + {[stableIdSymbol]: 2}, + ); + const getById = sinon + .stub(ServiceWorkerConsoleCollector.prototype, 'getById') + .returns(message); + + const result = context.getServiceWorkerConsoleMessageById('sw-3', 2); + + sinon.assert.calledOnceWithExactly(getWorkerById, 'sw-3'); + sinon.assert.calledOnceWithExactly(getById, 'extension-id', 2); + assert.strictEqual(result, message); + context.dispose(); + }); + + it('rejects a non service worker ID without reading console data', async () => { + const browser = createMockPuppeteerBrowser(); + browser.targets.returns([]); + const context = await createConnectedMcpContext( + browser, + { + config: createMockServerConfig({ + performanceCrux: false, + }), + heapSnapshotManager: new HeapSnapshotManager(new TaskRunner()), + }, + Locator, + ); + const getWorkerById = sinon + .stub(context, 'getWorkerById') + .returns(createMockMcpWorker({id: 'dw-1', type: 'dedicated_worker'})); + const getById = sinon.stub( + ServiceWorkerConsoleCollector.prototype, + 'getById', + ); + + assert.throws( + () => context.getServiceWorkerConsoleMessageById('dw-1', 2), + /Service worker not found\./, + ); + + sinon.assert.calledOnceWithExactly(getWorkerById, 'dw-1'); + sinon.assert.notCalled(getById); + context.dispose(); + }); + }); it('list pages', async () => { await withMcpContext(async (_response, context) => { const page = context.getSelectedMcpPage(); diff --git a/tests/tools/console.test.ts b/tests/tools/console.test.ts index e31699bf6e..976a3609bd 100644 --- a/tests/tools/console.test.ts +++ b/tests/tools/console.test.ts @@ -8,6 +8,8 @@ import assert from 'node:assert'; import path from 'node:path'; import {before, describe, it} from 'node:test'; +import sinon from 'sinon'; + import type {Dialog} from 'puppeteer-core'; import type {ParsedArguments} from '../../src/config/mcp-options.js'; @@ -20,7 +22,11 @@ import { listConsoleMessages, } from '../../src/tools/console.js'; import {installExtension} from '../../src/tools/extensions.js'; -import {createMockParsedArguments, createMockServerConfig} from '../mocks.js'; +import { + createHandlerMocks, + createMockParsedArguments, + createMockServerConfig, +} from '../mocks.js'; import {serverHooks} from '../server.js'; import { getTextContent, @@ -437,6 +443,20 @@ describe('console', () => { describe('get_console_message', () => { const server = serverHooks(); + it('forwards serviceWorkerId', async () => { + const {page, context, response, args} = createHandlerMocks(); + + await getConsoleMessage(args).handler( + {params: {msgid: 2, serviceWorkerId: 'sw-1'}, page}, + response, + context, + ); + + sinon.assert.calledOnceWithExactly(response.attachConsoleMessage, 2, { + serviceWorkerId: 'sw-1', + }); + }); + it('gets a specific console message', async () => { await withMcpContext(async (response, context, args) => { const page = context.getSelectedMcpPage(); From 470534a1df72204ea017eb6462445d2df301dc6f Mon Sep 17 00:00:00 2001 From: Nicholas Roscino Date: Wed, 18 Nov 2026 14:33:40 +0100 Subject: [PATCH 2/3] chore: self review --- docs/tool-reference.md | 4 ++-- src/McpContext.ts | 4 +++- src/McpResponse.ts | 6 ++---- src/config/cli-options.ts | 4 ++-- src/tools/console.ts | 4 ++-- tests/McpContext.test.ts | 35 +++-------------------------------- tests/McpResponse.test.ts | 25 +++++++++++++++++++++++++ 7 files changed, 39 insertions(+), 43 deletions(-) diff --git a/docs/tool-reference.md b/docs/tool-reference.md index bf6ab79633..9a9f01046f 100644 --- a/docs/tool-reference.md +++ b/docs/tool-reference.md @@ -411,9 +411,9 @@ **Parameters:** -- **msgid** (number) **(required)**: The msgid of a console message on the page from the listed console messages +- **msgid** (number) **(required)**: The msgid of a console message from [`list_console_messages`](#list_console_messages): for the page, or for the service worker when serviceWorkerId is set. - **pageId** (number) **(required)**: Targets a specific page by ID. -- **serviceWorkerId** (string) _(optional)_: Get the message from the service worker with this ID shown by [`list_pages`](#list_pages) (sw-N) instead of the page. Use the msgid listed for that service worker. +- **serviceWorkerId** (string) _(optional)_: Get the message from the service worker with this ID shown by [`list_pages`](#list_pages) (sw-N) instead of the page. pageId is ignored when set. Stack traces are not available for service worker messages. --- diff --git a/src/McpContext.ts b/src/McpContext.ts index f6b63cdfe2..6224608185 100644 --- a/src/McpContext.ts +++ b/src/McpContext.ts @@ -844,7 +844,9 @@ export class McpContext implements Context, BrowserlessContext { #getServiceWorkerExtensionId(serviceWorkerId: string): string { const worker = this.getWorkerById(serviceWorkerId); if (worker?.type !== 'service_worker') { - throw new Error('Service worker not found.'); + throw new Error( + `Service worker ${serviceWorkerId} not found. Call list_pages to get the current sw-N IDs.`, + ); } return new URL(worker.url).hostname; } diff --git a/src/McpResponse.ts b/src/McpResponse.ts index 519795f2ea..7aa96505ee 100644 --- a/src/McpResponse.ts +++ b/src/McpResponse.ts @@ -611,7 +611,7 @@ export class McpResponse implements Response { } const consoleMessageStableId = this.#attachedConsoleMessageId; if (this.#attachedConsoleMessageServiceWorkerId) { - // Service workers have no DevTools universe, like in the list tool. + // Service workers have no DevTools universe, so no stack trace is resolved. return await ConsoleFormatter.from( context.getServiceWorkerConsoleMessageById( this.#attachedConsoleMessageServiceWorkerId, @@ -623,9 +623,7 @@ export class McpResponse implements Response { if (!this.#page) { throw new Error(`Response must have an McpPage`); } - const message = this.#page.getConsoleMessageById( - this.#attachedConsoleMessageId, - ); + const message = this.#page.getConsoleMessageById(consoleMessageStableId); if ('args' in message || message instanceof UncaughtError) { const consoleMessage = message as ConsoleMessage | UncaughtError; return await ConsoleFormatter.from(consoleMessage, { diff --git a/src/config/cli-options.ts b/src/config/cli-options.ts index 63ce0ba467..696a64eab4 100644 --- a/src/config/cli-options.ts +++ b/src/config/cli-options.ts @@ -637,7 +637,7 @@ export const commands: Commands = { name: 'msgid', type: 'number', description: - 'The msgid of a console message on the page from the listed console messages', + 'The msgid of a console message from list_console_messages: for the page, or for the service worker when serviceWorkerId is set.', required: true, positional: true, }, @@ -645,7 +645,7 @@ export const commands: Commands = { name: 'serviceWorkerId', type: 'string', description: - 'Get the message from the service worker with this ID shown by list_pages (sw-N) instead of the page. Use the msgid listed for that service worker.', + 'Get the message from the service worker with this ID shown by list_pages (sw-N) instead of the page. pageId is ignored when set. Stack traces are not available for service worker messages.', required: false, positional: false, }, diff --git a/src/tools/console.ts b/src/tools/console.ts index 0cf994615b..85a083c29b 100644 --- a/src/tools/console.ts +++ b/src/tools/console.ts @@ -122,13 +122,13 @@ export const getConsoleMessage: PageToolFactory = definePageTool(() => ({ msgid: zod .number() .describe( - 'The msgid of a console message on the page from the listed console messages', + 'The msgid of a console message from list_console_messages: for the page, or for the service worker when serviceWorkerId is set.', ), serviceWorkerId: zod .string() .optional() .describe( - 'Get the message from the service worker with this ID shown by list_pages (sw-N) instead of the page. Use the msgid listed for that service worker.', + 'Get the message from the service worker with this ID shown by list_pages (sw-N) instead of the page. pageId is ignored when set. Stack traces are not available for service worker messages.', ), }, blockedByDialog: false, diff --git a/tests/McpContext.test.ts b/tests/McpContext.test.ts index ce11e91f17..2f7bdf3382 100644 --- a/tests/McpContext.test.ts +++ b/tests/McpContext.test.ts @@ -198,7 +198,9 @@ describe('McpContext', () => { assert.throws( () => context.getServiceWorkerConsoleData(serviceWorkerId), - /Service worker not found\./, + new RegExp( + `Service worker ${serviceWorkerId} not found\\. Call list_pages to get the current sw-N IDs\\.`, + ), ); sinon.assert.calledOnceWithExactly(getWorkerById, serviceWorkerId); @@ -252,37 +254,6 @@ describe('McpContext', () => { assert.strictEqual(result, message); context.dispose(); }); - - it('rejects a non service worker ID without reading console data', async () => { - const browser = createMockPuppeteerBrowser(); - browser.targets.returns([]); - const context = await createConnectedMcpContext( - browser, - { - config: createMockServerConfig({ - performanceCrux: false, - }), - heapSnapshotManager: new HeapSnapshotManager(new TaskRunner()), - }, - Locator, - ); - const getWorkerById = sinon - .stub(context, 'getWorkerById') - .returns(createMockMcpWorker({id: 'dw-1', type: 'dedicated_worker'})); - const getById = sinon.stub( - ServiceWorkerConsoleCollector.prototype, - 'getById', - ); - - assert.throws( - () => context.getServiceWorkerConsoleMessageById('dw-1', 2), - /Service worker not found\./, - ); - - sinon.assert.calledOnceWithExactly(getWorkerById, 'dw-1'); - sinon.assert.notCalled(getById); - context.dispose(); - }); }); it('list pages', async () => { await withMcpContext(async (_response, context) => { diff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.ts index 4b54f1415f..79af76fdd3 100644 --- a/tests/McpResponse.test.ts +++ b/tests/McpResponse.test.ts @@ -896,6 +896,31 @@ describe('McpResponse', () => { }); }); + it('reads an attached message from the service worker when serviceWorkerId is set', async () => { + const page = createMockMcpPage(); + const context = createMockMcpContext({selectedPage: page}); + const message = createMockConsoleMessage({ + type: 'log', + text: 'logged by the service worker', + }); + context.getServiceWorkerConsoleMessageById.returns(message); + const response = new McpResponse(createMockServerConfig()); + response.setPage(page); + response.attachConsoleMessage(2, {serviceWorkerId: 'sw-1'}); + + const {content} = await response.handle(context); + + sinon.assert.calledOnceWithExactly( + context.getServiceWorkerConsoleMessageById, + 'sw-1', + 2, + ); + sinon.assert.notCalled(page.getConsoleMessageById); + assert.ok( + getTextContent(content[0]).includes('logged by the service worker'), + ); + }); + it("doesn't list the issue message if mapping returns null", async t => { await withMcpContext(async (response, context) => { const mockAggregatedIssue = getMockAggregatedIssue(); From 95affc84cd4ab412a2a70bc78ec7c41c5b9eed18 Mon Sep 17 00:00:00 2001 From: Nicholas Roscino Date: Thu, 19 Nov 2026 10:01:53 +0100 Subject: [PATCH 3/3] chore: put serviceWorkerId behind --enableExtensions --- src/telemetry/tool_call_metrics.json | 7 +-- src/tools/console.ts | 82 ++++++++++++++++------------ tests/tools/console.test.ts | 34 +++++++++++- 3 files changed, 82 insertions(+), 41 deletions(-) diff --git a/src/telemetry/tool_call_metrics.json b/src/telemetry/tool_call_metrics.json index e822c355a6..a671b84a63 100644 --- a/src/telemetry/tool_call_metrics.json +++ b/src/telemetry/tool_call_metrics.json @@ -220,10 +220,6 @@ { "name": "page_id", "argType": "number" - }, - { - "name": "service_worker_id_length", - "argType": "number" } ] }, @@ -334,7 +330,8 @@ }, { "name": "service_worker_id_length", - "argType": "number" + "argType": "number", + "isDeprecated": true }, { "name": "include_stack_traces", diff --git a/src/tools/console.ts b/src/tools/console.ts index 85a083c29b..1ab2bf81a4 100644 --- a/src/tools/console.ts +++ b/src/tools/console.ts @@ -87,12 +87,16 @@ export const listConsoleMessages: PageToolFactory = definePageTool( .describe( 'Set to true to include the stack trace for each message when available. Increases the response size.', ), - serviceWorkerId: zod - .string() - .optional() - .describe( - 'Filter messages by the service worker ID shown by list_pages (sw-N).', - ), + ...(cliArgs.categoryExtensions + ? { + serviceWorkerId: zod + .string() + .optional() + .describe( + 'Filter messages by the service worker ID shown by list_pages (sw-N).', + ), + } + : {}), }, blockedByDialog: false, concurrency: 'page', @@ -111,32 +115,40 @@ export const listConsoleMessages: PageToolFactory = definePageTool( }, ); -export const getConsoleMessage: PageToolFactory = definePageTool(() => ({ - name: GET_CONSOLE_MESSAGE_TOOL_NAME, - description: `Gets a console message by its ID. You can get all messages by calling ${LIST_CONSOLE_MESSAGES_TOOL_NAME}.`, - annotations: { - category: ToolCategory.DEBUGGING, - readOnlyHint: true, - }, - schema: { - msgid: zod - .number() - .describe( - 'The msgid of a console message from list_console_messages: for the page, or for the service worker when serviceWorkerId is set.', - ), - serviceWorkerId: zod - .string() - .optional() - .describe( - 'Get the message from the service worker with this ID shown by list_pages (sw-N) instead of the page. pageId is ignored when set. Stack traces are not available for service worker messages.', - ), - }, - blockedByDialog: false, - concurrency: 'page', - verifyFilesSchema: {}, - handler: async (request, response) => { - response.attachConsoleMessage(request.params.msgid, { - serviceWorkerId: request.params.serviceWorkerId, - }); - }, -})); +export const getConsoleMessage: PageToolFactory = definePageTool( + (cliArgs: ParsedArguments) => ({ + name: GET_CONSOLE_MESSAGE_TOOL_NAME, + description: `Gets a console message by its ID. You can get all messages by calling ${LIST_CONSOLE_MESSAGES_TOOL_NAME}.`, + annotations: { + category: ToolCategory.DEBUGGING, + readOnlyHint: true, + }, + schema: { + msgid: zod + .number() + .describe( + cliArgs.categoryExtensions + ? 'The msgid of a console message from list_console_messages: for the page, or for the service worker when serviceWorkerId is set.' + : 'The msgid of a console message on the page from the listed console messages', + ), + ...(cliArgs.categoryExtensions + ? { + serviceWorkerId: zod + .string() + .optional() + .describe( + 'Get the message from the service worker with this ID shown by list_pages (sw-N) instead of the page. pageId is ignored when set. Stack traces are not available for service worker messages.', + ), + } + : {}), + }, + blockedByDialog: false, + concurrency: 'page', + verifyFilesSchema: {}, + handler: async (request, response) => { + response.attachConsoleMessage(request.params.msgid, { + serviceWorkerId: request.params.serviceWorkerId, + }); + }, + }), +); diff --git a/tests/tools/console.test.ts b/tests/tools/console.test.ts index 976a3609bd..27ccdf8265 100644 --- a/tests/tools/console.test.ts +++ b/tests/tools/console.test.ts @@ -147,6 +147,21 @@ describe('console', () => { }); describe('list_console_messages', () => { + it('exposes serviceWorkerId only with categoryExtensions', () => { + assert.ok( + 'serviceWorkerId' in + listConsoleMessages( + createMockParsedArguments({categoryExtensions: true}), + ).schema, + ); + assert.ok( + !( + 'serviceWorkerId' in + listConsoleMessages(createMockParsedArguments()).schema + ), + ); + }); + it('describes the default preserved navigation history', () => { const tool = listConsoleMessages(createMockParsedArguments()); assert.strictEqual( @@ -444,7 +459,9 @@ describe('console', () => { const server = serverHooks(); it('forwards serviceWorkerId', async () => { - const {page, context, response, args} = createHandlerMocks(); + const {page, context, response, args} = createHandlerMocks({ + categoryExtensions: true, + }); await getConsoleMessage(args).handler( {params: {msgid: 2, serviceWorkerId: 'sw-1'}, page}, @@ -457,6 +474,21 @@ describe('console', () => { }); }); + it('exposes serviceWorkerId only with categoryExtensions', () => { + assert.ok( + 'serviceWorkerId' in + getConsoleMessage( + createMockParsedArguments({categoryExtensions: true}), + ).schema, + ); + assert.ok( + !( + 'serviceWorkerId' in + getConsoleMessage(createMockParsedArguments()).schema + ), + ); + }); + it('gets a specific console message', async () => { await withMcpContext(async (response, context, args) => { const page = context.getSelectedMcpPage();