browser_type
Enter text into web page input fields using CSS selectors for automated form filling and data entry in browser automation.
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)Executes the browser_type tool by validating input, connecting to Playwright if needed, and using page.fill() to type text into the specified selector.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:194-230 (registration)Registers the 'browser_type' tool with the MCP server, including title, description, input schema, and handler reference.'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 schema defining the input structure for the browser_type tool: selector (string) and text (string). Also has corresponding TypeScript type at line 63.export const BrowserTypeInputSchema = z.object({ selector: z.string(), text: z.string() });