Skip to main content
Glama
livoras

Better Playwright MCP

by livoras

browserPressKey

Simulate keyboard key presses on web pages using Playwright, with options to target specific elements and adjust wait times for efficient browser automation.

Instructions

按键盘按键

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes按键名称,如 'Enter', 'Tab', 'ArrowDown' 等
pageIdYes页面ID
refNo可选:元素的xp引用值,如果指定则在该元素上按键
waitForTimeoutNo操作后等待获取快照的延迟时间(毫秒,默认2000)

Implementation Reference

  • The handler function that presses the specified key using the page's keyboard.press method. This is the core implementation of the tool logic.
    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); }); },
  • Tool schema defining the name 'browser_press_key' (maps to client 'browserPressKey'), input schema requiring 'key' string, and metadata.
    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', },
  • lib/tools.js:32-49 (registration)
    Central registration of all browser tools by spreading exports from individual modules, including keyboard.js which provides browser_press_key.
    export const allTools = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...form, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ];
  • MCP backend registration: imports filteredTools, sets _tools, and exposes tool schemas via listTools() for the protocol.
    import { filteredTools } from './tools.js'; import { toMcpTool } from './mcp/tool.js'; export class BrowserServerBackend { _tools; _context; _sessionLog; _config; _browserContextFactory; constructor(config, factory) { this._config = config; this._browserContextFactory = factory; this._tools = filteredTools(config); } async initialize(server, clientVersion, roots) { let rootPath; if (roots.length > 0) { const firstRootUri = roots[0]?.uri; const url = firstRootUri ? new URL(firstRootUri) : undefined; rootPath = url ? fileURLToPath(url) : undefined; } this._sessionLog = this._config.saveSession ? await SessionLog.create(this._config, rootPath) : undefined; this._context = new Context({ tools: this._tools, config: this._config, browserContextFactory: this._browserContextFactory, sessionLog: this._sessionLog, clientInfo: { ...clientVersion, rootPath }, }); } async listTools() { return this._tools.map(tool => toMcpTool(tool.schema)); }

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

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