Skip to main content
Glama
cloudflare

Cloudflare Playwright MCP

Official
by cloudflare

browser_press_key

Simulate keyboard key presses in automated browser testing scenarios. Integrate with Cloudflare Playwright MCP to control web browsers for precise interaction testing.

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 for the browser_press_key tool. It presses the specified key on the current tab's page using Playwright's keyboard.press method, generates corresponding code snippet, and returns an action object.
    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
      };
    },
  • Schema definition for the browser_press_key tool, including name, title, description, input schema with 'key' parameter validated by Zod, and type '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',
    },
  • Exports and registers the browser_press_key tool by including it in the array returned from the tool factory with captureSnapshot parameter.
    export default (captureSnapshot: boolean) => [
      pressKey(captureSnapshot),
    ];

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

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