From fb1cae1f23448e6dfd70e5f5feb1160535cca304 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov Date: Mon, 20 Oct 2025 17:05:42 +0200 Subject: [PATCH 1/3] fix: pageerror for non-error types --- src/McpContext.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/McpContext.ts b/src/McpContext.ts index 70f401c2..29170568 100644 --- a/src/McpContext.ts +++ b/src/McpContext.ts @@ -103,7 +103,13 @@ export class McpContext implements Context { collect(event); }, pageerror: event => { - collect(event); + if (event instanceof Error) { + collect(event); + } else { + const error = new Error(`${event}`); + error.stack = undefined; + collect(error); + } }, } as ListenerMap; }); From 09de3336f4fc6f78d1d119cb514e1092bfe83f98 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov Date: Mon, 20 Oct 2025 17:21:41 +0200 Subject: [PATCH 2/3] test --- tests/tools/console.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/tools/console.test.ts b/tests/tools/console.test.ts index c67b1084..46894532 100644 --- a/tests/tools/console.test.ts +++ b/tests/tools/console.test.ts @@ -35,6 +35,19 @@ describe('console', () => { ); }); }); + + it.only('work with primitive unhandled errors', async () => { + await withBrowser(async (response, context) => { + const page = await context.newPage(); + await page.setContent(''); + await listConsoleMessages.handler({params: {}}, response, context); + const formattedResponse = await response.handle('test', context); + const textContent = formattedResponse[0] as {text: string}; + assert.ok( + textContent.text.includes('msgid=1 [error] undefined (0 args)'), + ); + }); + }); }); describe('get_console_message', () => { From a01efb2ea938534261b68af2b13fbb25b85e2aaa Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov Date: Mon, 20 Oct 2025 17:22:30 +0200 Subject: [PATCH 3/3] remove only --- tests/tools/console.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tools/console.test.ts b/tests/tools/console.test.ts index 46894532..e94713e0 100644 --- a/tests/tools/console.test.ts +++ b/tests/tools/console.test.ts @@ -36,7 +36,7 @@ describe('console', () => { }); }); - it.only('work with primitive unhandled errors', async () => { + it('work with primitive unhandled errors', async () => { await withBrowser(async (response, context) => { const page = await context.newPage(); await page.setContent('');