browser_click
Click on web page elements using selectors to interact with browser instances in parallel testing or automation workflows.
Instructions
Click on a page element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instanceId | Yes | Instance ID | |
| selector | Yes | Element selector | |
| button | No | Mouse button | left |
| clickCount | No | Number of clicks | |
| delay | No | Click delay in milliseconds | |
| timeout | No | Timeout in milliseconds |
Implementation Reference
- src/tools.ts:694-720 (handler)The primary handler function that executes the browser_click tool logic by retrieving the browser instance and performing the click operation using Playwright's page.click() method with specified options.private async click(instanceId: string, selector: string, options: ClickOptions): Promise<ToolResult> { const instance = this.browserManager.getInstance(instanceId); if (!instance) { return { success: false, error: `Instance ${instanceId} not found` }; } try { const clickOptions: any = { button: options.button }; if (options.clickCount) clickOptions.clickCount = options.clickCount; if (options.delay) clickOptions.delay = options.delay; if (options.timeout) clickOptions.timeout = options.timeout; await instance.page.click(selector, clickOptions); return { success: true, data: { selector, clicked: true }, instanceId }; } catch (error) { return { success: false, error: `Click failed: ${error instanceof Error ? error.message : error}`, instanceId }; } }
- src/tools.ts:166-204 (schema)The JSON input schema definition for the browser_click tool, specifying required parameters (instanceId, selector) and optional parameters (button, clickCount, delay, timeout).{ name: 'browser_click', description: 'Click on a page element', inputSchema: { type: 'object', properties: { instanceId: { type: 'string', description: 'Instance ID' }, selector: { type: 'string', description: 'Element selector', }, button: { type: 'string', enum: ['left', 'right', 'middle'], description: 'Mouse button', default: 'left' }, clickCount: { type: 'number', description: 'Number of clicks', default: 1 }, delay: { type: 'number', description: 'Click delay in milliseconds', default: 0 }, timeout: { type: 'number', description: 'Timeout in milliseconds', default: 30000 } }, required: ['instanceId', 'selector'] } },
- src/tools.ts:533-540 (registration)The dispatcher case in the executeTools method that handles browser_click tool calls and invokes the click handler with parsed arguments.case 'browser_click': return await this.click(args.instanceId, args.selector, { button: args.button || 'left', clickCount: args.clickCount || 1, delay: args.delay || 0, timeout: args.timeout || 30000 });
- src/server.ts:40-45 (registration)MCP server registration for listing tools; returns the browser_click tool definition via BrowserTools.getTools().this.server.setRequestHandler(ListToolsRequestSchema, async () => { const tools = this.browserTools.getTools(); return { tools: tools, }; });
- src/server.ts:48-75 (registration)MCP server registration for tool calls; dispatches browser_click calls to BrowserTools.executeTools() and returns the result.this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { const result = await this.browserTools.executeTools(name, args || {}); if (result.success) { return { content: [ { type: 'text', text: JSON.stringify(result.data, null, 2), }, ], }; } else { throw new McpError(ErrorCode.InternalError, result.error || 'Tool execution failed'); } } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : error}` ); } });