playwright_hover
Simulate mouse hover interactions on web elements using CSS selectors for automated testing or interaction workflows with browser automation.
Instructions
Hover an element on the page
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for element to hover |
Implementation Reference
- src/toolsHandler.ts:249-272 (handler)The main handler logic for the 'playwright_hover' tool. It waits for the selector to appear and then hovers over the element using Playwright's page.hover method, returning success or error message.
case "playwright_hover": try { await page!.waitForSelector(args.selector); await page!.hover(args.selector); return { toolResult: { content: [{ type: "text", text: `Hovered ${args.selector}`, }], isError: false, }, }; } catch (error) { return { toolResult: { content: [{ type: "text", text: `Failed to hover ${args.selector}: ${(error as Error).message}`, }], isError: true, }, }; } - src/tools.ts:68-78 (schema)The tool definition including name, description, and input schema for 'playwright_hover', used for registration and validation.
{ name: "playwright_hover", description: "Hover an element on the page", inputSchema: { type: "object", properties: { selector: { type: "string", description: "CSS selector for element to hover" }, }, required: ["selector"], }, }, - src/requestHandler.ts:59-62 (registration)Registers the MCP 'list_tools' request handler, which returns the list of tool definitions including 'playwright_hover'.
// List tools handler server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: tools, })); - src/requestHandler.ts:65-67 (registration)Registers the MCP 'call_tool' request handler, which dispatches tool calls to handleToolCall where 'playwright_hover' is implemented.
server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments ?? {}, server) ); - src/tools.ts:152-160 (helper)Helper constant listing browser-requiring tools, including 'playwright_hover', used to conditionally launch the browser.
export const BROWSER_TOOLS = [ "playwright_navigate", "playwright_screenshot", "playwright_click", "playwright_fill", "playwright_select", "playwright_hover", "playwright_evaluate" ];