mouseDrag
Simulate mouse drag actions in browser automation by specifying start and end coordinates for precise control during web scraping and testing.
Instructions
Drag from one coordinate to another
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| startX | Yes | ||
| startY | Yes | ||
| endX | Yes | ||
| endY | Yes |
Implementation Reference
- src/controllers/playwright.ts:884-900 (handler)The core implementation of the mouseDrag tool in the PlaywrightController class. It moves the mouse to start position, presses down, moves to end position, and releases.async mouseDrag(startX: number, startY: number, endX: number, endY: number): Promise<void> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } this.log('Mouse drag', { startX, startY, endX, endY }); await this.state.page.mouse.move(startX, startY); await this.state.page.mouse.down(); await this.state.page.mouse.move(endX, endY); await this.state.page.mouse.up(); this.currentMousePosition = { x: endX, y: endY }; this.log('Mouse drag complete'); } catch (error: any) { console.error('Mouse drag error:', error); throw new BrowserError('Failed to drag mouse', 'Check if coordinates are valid'); } }
- src/server.ts:489-502 (schema)The input schema and metadata for the mouseDrag tool, defining required numeric parameters for drag coordinates.const MOUSE_DRAG_TOOL: Tool = { name: "mouseDrag", description: "Drag from one coordinate to another", inputSchema: { type: "object", properties: { startX: { type: "number" }, startY: { type: "number" }, endX: { type: "number" }, endY: { type: "number" } }, required: ["startX", "startY", "endX", "endY"] } };
- src/server.ts:984-996 (registration)The dispatch case in the MCP callTool request handler that validates inputs and invokes the mouseDrag handler.case 'mouseDrag': { if (typeof args.startX !== 'number' || typeof args.startY !== 'number' || typeof args.endX !== 'number' || typeof args.endY !== 'number') { return { content: [{ type: "text", text: "Start and end coordinates are required" }], isError: true }; } await playwrightController.mouseDrag(args.startX, args.startY, args.endX, args.endY); return { content: [{ type: "text", text: "Mouse drag completed successfully" }] }; }
- src/server.ts:551-551 (registration)Registration of the mouseDrag tool in the tools capabilities object passed to the MCP Server.mouseDrag: MOUSE_DRAG_TOOL,