browser_press_key
Simulate keyboard key presses in browser automation to interact with web elements, trigger actions, or navigate pages using Playwright MCP's structured accessibility approach.
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 asynchronous handler function that executes the tool logic by pressing the specified key on the current browser tab's page using Playwright's keyboard.press method. It returns code snippet, action, and configuration for snapshot and network wait.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)Tool schema defining the name 'browser_press_key', title, description, Zod input schema for the 'key' parameter, and type as 'destructive'.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:36-52 (registration)Registration of the keyboard tools (including browser_press_key) into the snapshotTools array with captureSnapshot enabled (true).export const snapshotTools: Tool<any>[] = [ ...common(true), ...console, ...dialogs(true), ...files(true), ...install, ...keyboard(true), ...navigate(true), ...network, ...pdf, ...screenshot, ...snapshot, ...tabs(true), ...testing, ...video, ...wait(true), ];
- src/tools.ts:54-69 (registration)Registration of the keyboard tools (including browser_press_key) into the visionTools array with captureSnapshot disabled (false).export const visionTools: Tool<any>[] = [ ...common(false), ...console, ...dialogs(false), ...files(false), ...install, ...keyboard(false), ...navigate(false), ...network, ...pdf, ...tabs(false), ...testing, ...video, ...vision, ...wait(false), ];