browser_hover
Simulate hovering over a web element using a CSS selector to test UI interactions and identify potential vulnerabilities during web application penetration testing.
Instructions
Hover an element on the page using CSS selector
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for element to hover |
Implementation Reference
- index.ts:465-504 (handler)The handler function for the 'browser_hover' tool. Hovers over the element specified by the CSS selector using Playwright's locator.hover(), with fallback for strict mode violations by targeting the first matching element.case ToolName.BrowserHover: try { await page.locator(args.selector).hover(); return { content: [{ type: "text", text: `Hovered ${args.selector}`, }], isError: false, }; } catch (error) { if((error as Error).message.includes("strict mode violation")) { console.log("Strict mode violation, retrying on first element..."); try { await page.locator(args.selector).first().hover(); return { content: [{ type: "text", text: `Hovered ${args.selector}`, }], isError: false, }; } catch (error) { return { content: [{ type: "text", text: `Failed to hover ${args.selector}: ${(error as Error).message}`, }], isError: true, }; } } return { content: [{ type: "text", text: `Failed to hover ${args.selector}: ${(error as Error).message}`, }], isError: true, }; }
- index.ts:133-143 (registration)Registers the 'browser_hover' tool in the TOOLS array, which is provided to the MCP server via ListToolsRequestSchema handler. Includes description and input schema.{ name: ToolName.BrowserHover, description: "Hover an element on the page using CSS selector", inputSchema: { type: "object", properties: { selector: { type: "string", description: "CSS selector for element to hover" }, }, required: ["selector"], }, },
- index.ts:136-142 (schema)Defines the input schema for the 'browser_hover' tool, requiring a 'selector' property of type string.inputSchema: { type: "object", properties: { selector: { type: "string", description: "CSS selector for element to hover" }, }, required: ["selector"], },
- index.ts:30-30 (helper)Enum definition mapping ToolName.BrowserHover to the string 'browser_hover' used throughout the code for tool identification.BrowserHover = "browser_hover",
- index.ts:844-846 (registration)Registers the handleToolCall function as the handler for all CallToolRequests, which dispatches to specific tool handlers based on name.server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request.params.name as ToolName, request.params.arguments ?? {}) );