browser_press_key
Simulate keyboard input by pressing a specified key, enabling browser automation and interaction with web pages through the Playwright MCP server.
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:37-45 (handler)The handler function that implements the 'browser_press_key' tool. It adds code comments and executes page.keyboard.press(params.key) within the tab's waitForCompletion.handle: async (tab, params, response) => { response.setIncludeSnapshot(); response.addCode(`// Press ${params.key}`); response.addCode(`await page.keyboard.press('${params.key}');`); await tab.waitForCompletion(async () => { await tab.page.keyboard.press(params.key); }); },
- src/tools/keyboard.ts:27-35 (schema)Defines the schema for the 'browser_press_key' tool, including name, description, input schema for the 'key' parameter, and 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:36-52 (registration)Registers the 'browser_press_key' tool (imported from keyboard.js) by including it in the allTools array via spread operator.export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ];