Chrome DevTools for coding agents
fix: pageerror for non-error types (#442)
Nikolay Vitkovb6b42ecb998d
diff --git a/src/McpContext.ts b/src/McpContext.tsindex 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;});diff --git a/tests/tools/console.test.ts b/tests/tools/console.test.tsindex c67b1084..e94713e0 100644--- a/tests/tools/console.test.ts+++ b/tests/tools/console.test.ts@@ -35,6 +35,19 @@ describe('console', () => {);});});++ it('work with primitive unhandled errors', async () => {+ await withBrowser(async (response, context) => {+ const page = await context.newPage();+ await page.setContent('<script>throw undefined;</script>');+ 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', () => {