browser_type
Type text into any editable element on a web page using automated browser control. Specify target and text, with options to submit the form or type character by character to trigger key handlers.
Instructions
Type text into editable element
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| element | No | Human-readable element description used to obtain permission to interact with the element | |
| target | Yes | Exact target element reference from the page snapshot, or a unique element selector | |
| 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/snapshot.ts:153-193 (handler)The 'browser_type' tool handler function that types text into an editable element. It supports slowly (pressSequentially) and submit (press Enter) options.
const type = defineTool({ capability: 'core', schema: { name: 'browser_type', title: 'Type text', description: 'Type text into editable element', inputSchema: typeSchema, type: 'destructive', }, handle: async (context, params) => { const snapshot = context.currentTabOrDie().snapshotOrDie(); const locator = snapshot.refLocator(params); const code: string[] = []; const steps: (() => Promise<void>)[] = []; if (params.slowly) { code.push(`// Press "${params.text}" sequentially into "${params.element}"`); code.push(`await page.${await generateLocator(locator)}.pressSequentially(${javascript.quote(params.text)});`); steps.push(() => locator.pressSequentially(params.text)); } else { code.push(`// Fill "${params.text}" into "${params.element}"`); code.push(`await page.${await generateLocator(locator)}.fill(${javascript.quote(params.text)});`); steps.push(() => locator.fill(params.text)); } if (params.submit) { code.push(`// Submit text`); code.push(`await page.${await generateLocator(locator)}.press('Enter');`); steps.push(() => locator.press('Enter')); } return { code, action: () => steps.reduce((acc, step) => acc.then(step), Promise.resolve()), captureSnapshot: true, waitForNetwork: true, }; }, }); - src/tools/snapshot.ts:147-151 (schema)Input schema for the 'browser_type' tool, extending elementSchema with text, submit, and slowly fields.
const typeSchema = elementSchema.extend({ text: z.string().describe('Text to type into the element'), submit: z.coerce.boolean().optional().describe('Whether to submit entered text (press Enter after)'), slowly: z.coerce.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.'), }); - src/tools/snapshot.ts:156-156 (registration)The tool is registered with name 'browser_type' via the defineTool schema name property.
name: 'browser_type',