click
Simulate mouse clicks at specific coordinates in Chrome for browser automation and testing. Use this tool to interact with web elements programmatically through the Chrome Debug MCP Server.
Instructions
在指定坐标位置点击
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coordinate | Yes | 点击位置的坐标,格式为 'x,y' |
Implementation Reference
- src/browserSession.ts:469-476 (handler)The core handler implementation for the 'click' tool. It uses doAction wrapper and handleMouseInteraction helper to perform the mouse click at the given coordinate via Puppeteer page.mouse.click.*/ async click(coordinate: string): Promise<BrowserActionResult> { return this.doAction(async (page) => { await this.handleMouseInteraction(page, coordinate, async (x, y) => { await page.mouse.click(x, y); }); }); }
- src/index.ts:83-95 (schema)The input schema for the 'click' tool, defining the required 'coordinate' parameter as a string in 'x,y' format.name: "click", description: "在指定坐标位置点击", inputSchema: { type: "object", properties: { coordinate: { type: "string", description: "点击位置的坐标,格式为 'x,y'", }, }, required: ["coordinate"], }, },
- src/index.ts:189-194 (registration)The dispatching logic in the MCP tool call handler that validates the input and calls the browserSession.click method.case "click": if (!args?.coordinate) { throw new Error("coordinate参数是必需的"); } result = await this.browserSession.click(args.coordinate as string); break;
- src/browserSession.ts:421-465 (helper)Helper method used by 'click' (and hover) to handle mouse interactions, including network activity monitoring and post-click navigation waiting.private async handleMouseInteraction( page: Page, coordinate: string, action: (x: number, y: number) => Promise<void>, ): Promise<void> { const [x, y] = coordinate.split(",").map(Number); // 设置网络请求监控 let hasNetworkActivity = false; const requestListener = () => { hasNetworkActivity = true; }; page.on("request", requestListener); // 执行鼠标操作 await action(x, y); this.currentMousePosition = coordinate; // 小延迟检查操作是否触发了任何网络活动 await delay(100); if (hasNetworkActivity) { // 如果检测到网络活动,等待导航/加载 await page .waitForNavigation({ waitUntil: ["domcontentloaded", "networkidle2"], timeout: 15000, }) .catch(async () => { // 如果networkidle2失败,尝试仅等待domcontentloaded console.log("鼠标交互后网络静默等待失败,尝试仅等待DOM"); await page.waitForNavigation({ waitUntil: ["domcontentloaded"], timeout: 15000, }).catch(() => { // 如果还是失败,就忽略,继续执行 console.log("鼠标交互后导航等待失败,继续执行"); }); }); await this.waitTillHTMLStable(page); } // 清理监听器 page.off("request", requestListener); }
- src/index.ts:309-310 (registration)Success message generation for the 'click' tool in the response builder.case "click": return `✅ 点击操作完成${result.currentMousePosition ? ` (位置: ${result.currentMousePosition})` : ""}`;