browser_file_upload
Upload one or multiple files to a web page by providing absolute file paths. Cancel the file chooser by omitting the paths parameter.
Instructions
Upload one or multiple files
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| paths | No | The absolute paths to the files to upload. Can be single file or multiple files. If omitted, file chooser is cancelled. |
Implementation Reference
- src/tools/files.ts:20-55 (handler)The handler function for 'browser_file_upload'. It finds a file chooser modal state, sets the files via Playwright's setFiles, clears the modal state, and returns the action.
const uploadFile: ToolFactory = captureSnapshot => defineTool({ capability: 'files', schema: { name: 'browser_file_upload', title: 'Upload files', description: 'Upload one or multiple files', inputSchema: z.object({ paths: z.array(z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'), }), type: 'destructive', }, handle: async (context, params) => { const modalState = context.modalStates().find(state => state.type === 'fileChooser'); if (!modalState) throw new Error('No file chooser visible'); const code = [ `// <internal code to chose files ${params.paths.join(', ')}`, ]; const action = async () => { await modalState.fileChooser.setFiles(params.paths); context.clearModalState(modalState); }; return { code, action, captureSnapshot, waitForNetwork: true, }; }, clearsModalState: 'fileChooser', }); - src/tools/files.ts:23-31 (schema)Input schema for 'browser_file_upload': requires 'paths' (array of absolute file path strings).
schema: { name: 'browser_file_upload', title: 'Upload files', description: 'Upload one or multiple files', inputSchema: z.object({ paths: z.array(z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'), }), type: 'destructive', }, - src/tools.ts:35-66 (registration)Registration: 'browser_file_upload' is exported via files(true)/files(false) in snapshotTools and visionTools arrays.
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), ]; export const visionTools: Tool<any>[] = [ ...common(false), ...console, ...dialogs(false), ...files(false), ...install, ...keyboard(false), ...navigate(false), ...network, ...pdf, ...tabs(false), ...testing, ...vision, ...wait(false), ]; - src/tools/files.ts:17-18 (registration)Imports defineTool and ToolFactory from './tool.js' and zod for schema validation.
import { z } from 'zod'; import { defineTool, type ToolFactory } from './tool.js'; - src/tab.ts:40-53 (helper)Helper: when a filechooser event fires on a page, it sets a FileUploadModalState on the context, which the handler then resolves.
page.on('filechooser', chooser => { this.context.setModalState({ type: 'fileChooser', description: 'File chooser', fileChooser: chooser, }, this); }); page.on('dialog', dialog => this.context.dialogShown(this, dialog)); page.on('download', download => { void this.context.downloadStarted(this, download); }); page.setDefaultNavigationTimeout(60000); page.setDefaultTimeout(5000); }