type
Enter text into web page elements using CSS selectors to automate form filling, search queries, and data entry tasks in browser automation workflows.
Instructions
Type text into an element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | ||
| text | Yes |
Implementation Reference
- src/controllers/playwright.ts:137-149 (handler)Core implementation of the 'type' tool: types text into the specified selector using Playwright's page.type() method.async type(selector: string, text: string): Promise<void> { try { if (!this.isInitialized()) { throw new Error('Browser not initialized'); } this.log('Typing into element', { selector, text }); await this.state.page?.type(selector, text); this.log('Type complete'); } catch (error: any) { console.error('Type error:', error); throw new BrowserError('Failed to type text', 'Check if the input element exists and is editable'); } }
- src/server.ts:31-42 (schema)Input schema definition for the 'type' tool, specifying selector and text parameters.const TYPE_TOOL: Tool = { name: "type", description: "Type text into an element", inputSchema: { type: "object", properties: { selector: { type: "string" }, text: { type: "string" } }, required: ["selector", "text"] } };
- src/server.ts:517-517 (registration)Registration of the 'type' tool in the tools dictionary used by the MCP server.type: TYPE_TOOL,
- src/server.ts:599-610 (handler)Dispatch handler in callTool request handler that validates input and delegates to playwrightController.type.case 'type': { if (!args.selector || !args.text) { return { content: [{ type: "text", text: "Selector and text are required" }], isError: true }; } await playwrightController.type(args.selector as string, args.text as string); return { content: [{ type: "text", text: "Text entered successfully" }] }; }