feat(dblclick): add double click (#654)

Fixes https://github.com/microsoft/playwright-mcp/issues/652
This commit is contained in:
Pavel Feldman
2025-07-11 16:45:39 -07:00
committed by GitHub
parent 1600ba6645
commit 59f1d67a4e
3 changed files with 54 additions and 6 deletions

View File

@@ -46,13 +46,17 @@ const elementSchema = z.object({
ref: z.string().describe('Exact target element reference from the page snapshot'),
});
const clickSchema = elementSchema.extend({
doubleClick: z.boolean().optional().describe('Whether to perform a double click instead of a single click'),
});
const click = defineTool({
capability: 'core',
schema: {
name: 'browser_click',
title: 'Click',
description: 'Perform click on a web page',
inputSchema: elementSchema,
inputSchema: clickSchema,
type: 'destructive',
},
@@ -60,14 +64,18 @@ const click = defineTool({
const tab = context.currentTabOrDie();
const locator = tab.snapshotOrDie().refLocator(params);
const code = [
`// Click ${params.element}`,
`await page.${await generateLocator(locator)}.click();`
];
const code: string[] = [];
if (params.doubleClick) {
code.push(`// Double click ${params.element}`);
code.push(`await page.${await generateLocator(locator)}.dblclick();`);
} else {
code.push(`// Click ${params.element}`);
code.push(`await page.${await generateLocator(locator)}.click();`);
}
return {
code,
action: () => locator.click(),
action: () => params.doubleClick ? locator.dblclick() : locator.click(),
captureSnapshot: true,
waitForNetwork: true,
};