Chrome DevTools for coding agents
fix: preserve underlying error message in input tool actions (#2792)
Nikolay Vitkov6e47dbb56088
diff --git a/src/third_party/index.ts b/src/third_party/index.tsindex cbb6b993..44e95927 100644--- a/src/third_party/index.ts+++ b/src/third_party/index.ts@@ -51,6 +51,7 @@ export {KnownDevices,CDPSessionEvent,ScreenRecorder,+ TimeoutError,} from 'puppeteer-core';export {default as puppeteer} from 'puppeteer-core';export type * from 'puppeteer-core';diff --git a/src/tools/input.ts b/src/tools/input.tsindex 4c24bea7..34f38546 100644--- a/src/tools/input.ts+++ b/src/tools/input.ts@@ -5,7 +5,7 @@*/import type {McpContext} from '../McpContext.js';-import {zod} from '../third_party/index.js';+import {TimeoutError, zod} from '../third_party/index.js';import type {ElementHandle, KeyInput} from '../third_party/index.js';import type {TextSnapshotNode} from '../types.js';import {parseKey} from '../utils/keyboard.js';@@ -35,8 +35,14 @@ const submitKeySchema = zodfunction handleActionError(error: unknown, uid: string) {logger?.('failed to act using a locator', error);+ const reason =+ error instanceof TimeoutError+ ? 'The element did not become interactive within the configured timeout.'+ : error instanceof Error+ ? error.message+ : String(error);throw new Error(- `Failed to interact with the element with uid ${uid}. The element did not become interactive within the configured timeout.`,+ `Failed to interact with the element with uid ${uid}. ${reason}`,{cause: error,},diff --git a/tests/tools/input.test.ts b/tests/tools/input.test.tsindex 769fd019..0bee1831 100644--- a/tests/tools/input.test.ts+++ b/tests/tools/input.test.ts@@ -588,6 +588,40 @@ describe('input', () => {});});+ it('reports why filling out a select failed', async () => {+ await withMcpContext(async (response, context, args) => {+ const page = context.getSelectedMcpPage().pptrPage;+ await page.setContent(+ html`<select+ ><option value="v1">one</option+ ><option value="v2">two</option></select+ >`,+ );+ context.getSelectedMcpPage().textSnapshot = await TextSnapshot.create(+ context.getSelectedMcpPage(),+ );+ await assert.rejects(+ () =>+ fill(args).handler(+ {+ params: {+ // Options are matched by their text, not their value.+ uid: '1_1',+ value: 'v2',+ },+ page: context.getSelectedMcpPage(),+ },+ response,+ context,+ ),+ {+ message:+ 'Failed to interact with the element with uid 1_1. Could not find option with text "v2"',+ },+ );+ });+ });+it('fills out a select option with an empty value by text', async () => {await withMcpContext(async (response, context, args) => {const page = context.getSelectedMcpPage().pptrPage;