browserClick
Automate web element clicks with precision using page ID and element reference. Optimizes browser interactions by reducing HTML token usage, enabling efficient and controlled automation workflows.
Instructions
点击页面元素
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pageId | Yes | 页面ID | |
| ref | Yes | 元素的xp引用值 | |
| waitForTimeout | No | 操作后等待获取快照的延迟时间(毫秒,默认2000) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"pageId": {
"description": "页面ID",
"type": "string"
},
"ref": {
"description": "元素的xp引用值",
"type": "string"
},
"waitForTimeout": {
"description": "操作后等待获取快照的延迟时间(毫秒,默认2000)",
"type": "number"
}
},
"required": [
"pageId",
"ref"
],
"type": "object"
}
Implementation Reference
- lib/tools/snapshot.js:34-41 (schema)Zod schemas (elementSchema and clickSchema) that define the input parameters for the browser_click tool, including element description, ref, optional doubleClick, and button.export const elementSchema = z.object({ element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'), 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'), button: z.enum(['left', 'right', 'middle']).optional().describe('Button to click, defaults to left'), });
- lib/tools/snapshot.js:51-66 (handler)The handler function that performs the click or double-click on the element using the resolved locator, adds corresponding Playwright code to response, and waits for completion.handle: async (tab, params, response) => { response.setIncludeSnapshot(); const locator = await tab.refLocator(params); const button = params.button; const buttonAttr = button ? `{ button: '${button}' }` : ''; if (params.doubleClick) response.addCode(`await page.${await generateLocator(locator)}.dblclick(${buttonAttr});`); else response.addCode(`await page.${await generateLocator(locator)}.click(${buttonAttr});`); await tab.waitForCompletion(async () => { if (params.doubleClick) await locator.dblclick({ button }); else await locator.click({ button }); }); },
- lib/tools/snapshot.js:42-50 (registration)The full definition and registration of the 'browser_click' tool using defineTabTool, including schema and handler. This is the core implementation location.const click = defineTabTool({ capability: 'core', schema: { name: 'browser_click', title: 'Click', description: 'Perform click on a web page', inputSchema: clickSchema, type: 'destructive', },
- lib/tools.js:32-49 (registration)Aggregates all individual tool modules, including snapshot.js which exports the browser_click tool, into the allTools array used by the backend.export const allTools = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...form, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ];
- lib/browserServerBackend.js:53-73 (registration)The MCP backend's callTool method that looks up the tool by name ('browser_click'), parses arguments, invokes the handler, and serializes the response.async callTool(name, rawArguments) { const tool = this._tools.find(tool => tool.schema.name === name); if (!tool) throw new Error(`Tool "${name}" not found`); const parsedArguments = tool.schema.inputSchema.parse(rawArguments || {}); const context = this._context; const response = new Response(context, name, parsedArguments); context.setRunningTool(name); try { await tool.handle(context, parsedArguments, response); await response.finish(); this._sessionLog?.logResponse(response); } catch (error) { response.addError(String(error)); } finally { context.setRunningTool(undefined); } return response.serialize(); }