Skip to main content
Glama

playwright_press_key

Simulate keyboard key presses in a browser environment. Specify the key and optionally a CSS selector to focus on an element before pressing the key. Useful for automating web interactions.

Instructions

Press a keyboard key

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesKey to press (e.g. 'Enter', 'ArrowDown', 'a')
selectorNoOptional CSS selector to focus before pressing key

Implementation Reference

  • PressKeyTool class implementing the tool logic: optionally focuses a selector then presses the specified key using Playwright's keyboard API.
    export class PressKeyTool extends BrowserToolBase { /** * Execute the key press tool */ async execute(args: any, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (page) => { if (args.selector) { await page.waitForSelector(args.selector); await page.focus(args.selector); } await page.keyboard.press(args.key); return createSuccessResponse(`Pressed key: ${args.key}`); }); } }
  • Input schema definition for the playwright_press_key tool, specifying parameters 'key' (required) and 'selector' (optional).
    { name: "playwright_press_key", description: "Press a keyboard key", inputSchema: { type: "object", properties: { key: { type: "string", description: "Key to press (e.g. 'Enter', 'ArrowDown', 'a')" }, selector: { type: "string", description: "Optional CSS selector to focus before pressing key" } }, required: ["key"], }, },
  • Switch case registration in handleToolCall function dispatching execution to the PressKeyTool instance.
    case "playwright_press_key": return await pressKeyTool.execute(args, context);
  • Lazy initialization of the PressKeyTool instance in initializeTools function.
    if (!pressKeyTool) pressKeyTool = new PressKeyTool(server);

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/executeautomation/mcp-playwright'

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