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
| Name | Required | Description | Default |
|---|---|---|---|
| pageId | Yes | 页面ID | |
| ref | Yes | 元素的xp引用值 | |
| waitForTimeout | No | 操作后等待获取快照的延迟时间(毫秒,默认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
- lib/tools/snapshot.js:94-111 (handler)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(); }); }, });
- lib/tools/snapshot.js:34-37 (schema)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'), });
- lib/tools/snapshot.js:133-139 (registration)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,
- lib/tools/tool.js:19-33 (helper)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); }, }; }