browser_type
Types specified text into a web page element, optionally submitting it or typing character by character. Part of Playwright MCP for browser automation using structured accessibility snapshots.
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 | |
| 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. | |
| submit | No | Whether to submit entered text (press Enter after) | |
| text | Yes | Text to type into the element |
Implementation Reference
- src/tools/snapshot.ts:155-184 (handler)Handler function that executes the browser_type tool: resolves element locator from page snapshot, performs text input via fill or sequential press, optionally submits with Enter, generates corresponding code and actions.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-153 (schema)Schema definition for the browser_type tool, including name, title, description, input schema reference, and type.schema: { name: 'browser_type', title: 'Type text', description: 'Type text into editable element', inputSchema: typeSchema, type: 'destructive', },
- src/tools/snapshot.ts:139-143 (schema)Input schema for browser_type using Zod: extends elementSchema with text, optional submit and slowly flags.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.'), });
- src/tools.ts:35-50 (registration)Central registration of tools including ...snapshot which brings in the browser_type tool for snapshotTools export.export const snapshotTools: Tool<any>[] = [ ...common(true), ...console, ...dialogs(true), ...files(true), ...install, ...keyboard(true), ...navigate(true), ...network, ...pdf, ...screenshot, ...snapshot, ...tabs(true), ...testing, ...wait(true), ];
- src/tools/snapshot.ts:219-226 (registration)Local registration: browser_type tool (named 'type') is included in the default export array of snapshot tools.export default [ snapshot, click, drag, hover, type, selectOption, ];