Skip to main content
Glama

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
NameRequiredDescriptionDefault
keyYesName of the key to press or a character to generate, such as `ArrowLeft` or `a`

Implementation Reference

  • 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); }); },
  • 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', },
  • 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, ];

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/maywzh/playwright-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server