Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/third_party/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export {
KnownDevices,
CDPSessionEvent,
ScreenRecorder,
TimeoutError,
} from 'puppeteer-core';
export {default as puppeteer} from 'puppeteer-core';
export type * from 'puppeteer-core';
Expand Down
10 changes: 8 additions & 2 deletions src/tools/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -35,8 +35,14 @@ const submitKeySchema = zod

function 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,
},
Expand Down
34 changes: 34 additions & 0 deletions tests/tools/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading