browser_press_key
Simulate key presses on a web page using structured accessibility snapshots. Ideal for testing or automating interactions without relying on visual models or screenshots.
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 core logic of pressing the specified key on the browser's page keyboard using Playwright API.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)Schema definition for the browser_press_key tool, specifying name, title, description, Zod input schema for '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/keyboard.ts:24-46 (registration)Registration of the browser_press_key tool using defineTabTool, combining schema, capability, and handler.const pressKey = defineTabTool({ capability: 'core', 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', }, 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.ts:36-52 (registration)Top-level registration of all tools, including the keyboard tools (which contain browser_press_key) via array spread into allTools export.export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ];