browser_press_key
Simulate key presses in a web browser to automate interactions, such as typing text or navigating with keyboard shortcuts, using Playwright MCP for structured accessibility tasks.
Instructions
Press a key on the keyboard
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Name of the key to press or a character to generate, such as `ArrowLeft` or `a` |
Implementation Reference
- src/tools/keyboard.ts:33-49 (handler)The handler function for the 'browser_press_key' tool. It presses the specified key on the current browser tab's page using Playwright's keyboard.press method, generates accompanying code snippet, and configures snapshot capture.handle: async (context, params) => { const tab = context.currentTabOrDie(); const code = [ `// Press ${params.key}`, `await page.keyboard.press('${params.key}');`, ]; const action = () => tab.page.keyboard.press(params.key); return { code, action, captureSnapshot, waitForNetwork: true }; },
- src/tools/keyboard.ts:23-31 (schema)The schema definition for the 'browser_press_key' tool, specifying name, title, description, input schema (key parameter), and destructive type.schema: { name: 'browser_press_key', title: 'Press a key', description: 'Press a key on the keyboard', inputSchema: z.object({ key: z.string().describe('Name of the key to press or a character to generate, such as `ArrowLeft` or `a`'), }), type: 'destructive', },
- src/tools.ts:41-41 (registration)Registration of keyboard tools (including 'browser_press_key') into the snapshotTools array....keyboard(true),
- src/tools.ts:58-58 (registration)Registration of keyboard tools (including 'browser_press_key') into the visionTools array....keyboard(false),
- src/connection.ts:30-30 (registration)Selects the appropriate tools array (including 'browser_press_key') based on config.vision for use in MCP server.const allTools = config.vision ? visionTools : snapshotTools;