browser_type
Automate text input into specified web elements using Playwright MCP Server. Define a selector and text to interact with input fields for web automation tasks.
Instructions
Type text into an input field specified by selector
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | ||
| text | Yes |
Implementation Reference
- src/server.ts:203-229 (handler)The handler function for the 'browser_type' tool that types text into a page element using Playwright's page.fill method.async (params: any) => { try { const input = z.object({ selector: z.string(), text: z.string() }).parse(params); await this.playwright.ensureConnected(); const page = this.playwright.getPage(); await page.fill(input.selector, input.text); return { content: [{ type: 'text', text: `Successfully typed text into element: ${input.selector}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Type text failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
- src/server.ts:193-230 (registration)Registration of the 'browser_type' tool with the MCP server, including metadata, input schema, and inline handler function.this.server.registerTool( 'browser_type', { title: 'Type Text', description: 'Type text into an input field specified by selector', inputSchema: { selector: z.string(), text: z.string() } }, async (params: any) => { try { const input = z.object({ selector: z.string(), text: z.string() }).parse(params); await this.playwright.ensureConnected(); const page = this.playwright.getPage(); await page.fill(input.selector, input.text); return { content: [{ type: 'text', text: `Successfully typed text into element: ${input.selector}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Type text failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
- src/types.ts:31-34 (schema)Zod input schema definition for the browser_type tool inputs for TypeScript type inference.export const BrowserTypeInputSchema = z.object({ selector: z.string(), text: z.string() });