Skip to main content
Glama
Rainmen-xia

Chrome Debug MCP Server

by Rainmen-xia

type_text

Input specified text into a browser session using the Chrome Debug MCP Server, enabling automation of typing tasks with persistent login sessions.

Instructions

输入文本内容

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes要输入的文本内容

Implementation Reference

  • The core handler function that executes the type_text tool logic by typing the provided text using Puppeteer's page.keyboard.type() within the doAction wrapper for logging and screenshots.
    async type(text: string): Promise<BrowserActionResult> { return this.doAction(async (page) => { await page.keyboard.type(text); }); }
  • src/index.ts:96-109 (registration)
    Registration of the type_text tool in the ListTools response, including name, description, and input schema.
    { name: "type_text", description: "输入文本内容", inputSchema: { type: "object", properties: { text: { type: "string", description: "要输入的文本内容", }, }, required: ["text"], }, },
  • Dispatch handler in the CallToolRequestSchema switch statement that validates input and calls the browserSession.type() method.
    case "type_text": if (!args?.text) { throw new Error("text参数是必需的"); } result = await this.browserSession.type(args.text as string); break;
  • Helper method used by type() and other actions to execute the action, handle console logs/errors, wait for stability, capture screenshots, and format results.
    async doAction(action: (page: Page) => Promise<void>): Promise<BrowserActionResult> { if (!this.page) { return { success: false, error: "浏览器未启动。请先调用 launch_browser 工具。" }; } const logs: string[] = []; let lastLogTs = Date.now(); const consoleListener = (msg: any) => { if (msg.type() === "log") { logs.push(msg.text()); } else { logs.push(`[${msg.type()}] ${msg.text()}`); } lastLogTs = Date.now(); }; const errorListener = (err: Error) => { logs.push(`[页面错误] ${err.toString()}`); lastLogTs = Date.now(); }; // 添加监听器 this.page.on("console", consoleListener); this.page.on("pageerror", errorListener); try { await action(this.page); } catch (err) { if (!(err instanceof TimeoutError)) { logs.push(`[错误] ${err instanceof Error ? err.message : String(err)}`); } return { success: false, error: err instanceof Error ? err.message : String(err), logs: logs.join("\n") }; } // 等待控制台静默,设置超时 await pWaitFor(() => Date.now() - lastLogTs >= 500, { timeout: 3_000, interval: 100, }).catch(() => {}); // 截图配置 let options: ScreenshotOptions = { encoding: "base64", }; let screenshotBase64 = await this.page.screenshot({ ...options, type: "webp", quality: 75, }).catch(() => null); let screenshot = screenshotBase64 ? `data:image/webp;base64,${screenshotBase64}` : undefined; if (!screenshotBase64) { console.log("webp截图失败,尝试png"); screenshotBase64 = await this.page.screenshot({ ...options, type: "png", }).catch(() => null); screenshot = screenshotBase64 ? `data:image/png;base64,${screenshotBase64}` : undefined; } // 移除监听器 this.page.off("console", consoleListener); this.page.off("pageerror", errorListener); return { success: true, screenshot, logs: logs.join("\n"), currentUrl: this.page.url(), currentMousePosition: this.currentMousePosition, }; }

Other Tools

Related Tools

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/Rainmen-xia/chrome-debug-mcp'

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