browser_type
Type text into web page elements for browser automation, supporting character-by-character input and form submission.
Instructions
Type text into editable element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| element | Yes | Human-readable element description used to obtain permission to interact with the element | |
| ref | Yes | Exact target element reference from the page snapshot | |
| text | Yes | Text to type into the element | |
| submit | No | Whether to submit entered text (press Enter after) | |
| slowly | No | Whether to type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once. |
Implementation Reference
- src/tools/keyboard.ts:64-85 (handler)The core handler function for the 'browser_type' tool. It locates the target element using the provided ref, then either fills the text instantly or types it sequentially if 'slowly' is true, and optionally presses Enter if 'submit' is true.
handle: async (tab, params, response) => { const locator = await tab.refLocator(params); await tab.waitForCompletion(async () => { if (params.slowly) { response.setIncludeSnapshot(); response.addCode(`// Press "${params.text}" sequentially into "${params.element}"`); response.addCode(`await page.${await generateLocator(locator)}.pressSequentially(${javascript.quote(params.text)});`); await locator.pressSequentially(params.text); } else { response.addCode(`// Fill "${params.text}" into "${params.element}"`); response.addCode(`await page.${await generateLocator(locator)}.fill(${javascript.quote(params.text)});`); await locator.fill(params.text); } if (params.submit) { response.setIncludeSnapshot(); response.addCode(`await page.${await generateLocator(locator)}.press('Enter');`); await locator.press('Enter'); } }); }, - src/tools/keyboard.ts:48-62 (schema)Defines the input schema for the 'browser_type' tool, extending elementSchema with text, submit, and slowly options.
const typeSchema = elementSchema.extend({ text: z.string().describe('Text to type into the element'), submit: z.boolean().optional().describe('Whether to submit entered text (press Enter after)'), slowly: z.boolean().optional().describe('Whether to type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once.'), }); const type = defineTabTool({ capability: 'core', schema: { name: 'browser_type', title: 'Type text', description: 'Type text into editable element', inputSchema: typeSchema, type: 'destructive', }, - src/tools/snapshot.ts:39-42 (schema)Shared base schema for element targeting (element description and snapshot ref), used as foundation for browser_type input schema.
export const elementSchema = z.object({ element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'), ref: z.string().describe('Exact target element reference from the page snapshot'), }); - src/tools.ts:36-52 (registration)Global registration of all MCP tools by aggregating exports from individual tool modules, including 'browser_type' via ...keyboard.
export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ]; - src/tools/keyboard.ts:88-91 (registration)Local registration: exports the keyboard tools array including the 'browser_type' tool (named 'type' internally).
export default [ pressKey, type, ];