Skip to main content
Glama

Better Playwright MCP

by livoras

browserHover

Simulate mouse hover actions on specific web elements using Playwright, enabling precise interactions and snapshot captures for testing and automation workflows.

Instructions

悬停在页面元素上

Input Schema

NameRequiredDescriptionDefault
pageIdYes页面ID
refYes元素的xp引用值
waitForTimeoutNo操作后等待获取快照的延迟时间(毫秒,默认2000)

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "pageId": { "description": "页面ID", "type": "string" }, "ref": { "description": "元素的xp引用值", "type": "string" }, "waitForTimeout": { "description": "操作后等待获取快照的延迟时间(毫秒,默认2000)", "type": "number" } }, "required": [ "pageId", "ref" ], "type": "object" }

Implementation Reference

  • Full implementation of the browser_hover (browserHover) tool handler. It uses element ref to get locator and performs hover, generates code snippet for reproduction, and waits for completion.
    const hover = defineTabTool({ capability: 'core', schema: { name: 'browser_hover', title: 'Hover mouse', description: 'Hover over element on page', inputSchema: elementSchema, type: 'readOnly', }, handle: async (tab, params, response) => { response.setIncludeSnapshot(); const locator = await tab.refLocator(params); response.addCode(`await page.${await generateLocator(locator)}.hover();`); await tab.waitForCompletion(async () => { await locator.hover(); }); }, });
  • Zod schema for element input, used by browser_hover tool's inputSchema.
    export const elementSchema = z.object({ element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'), ref: z.string().describe('Exact target element reference from the page snapshot'), });
  • Exports the hover tool along with others for inclusion in the allTools list.
    export default [ snapshot, click, drag, hover, selectOption, ];
  • lib/tools.js:46-46 (registration)
    Includes snapshot tools (containing browser_hover) in the aggregated allTools export used by MCP backend.
    ...snapshot,
  • defineTabTool wrapper used to define the browser_hover tool, adding tab context and modal state checks.
    export function defineTabTool(tool) { return { ...tool, handle: async (context, params, response) => { const tab = context.currentTabOrDie(); const modalStates = tab.modalStates().map(state => state.type); if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState)) response.addError(`Error: The tool "${tool.schema.name}" can only be used when there is related modal state present.\n` + tab.modalStatesMarkdown().join('\n')); else if (!tool.clearsModalState && modalStates.length) response.addError(`Error: Tool "${tool.schema.name}" does not handle the modal state.\n` + tab.modalStatesMarkdown().join('\n')); else return tool.handle(tab, params, response); }, }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/livoras/better-playwright-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server