browser_file_upload
Upload files to web pages during browser automation. Specify file paths to simulate user file selection in automated testing scenarios.
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:33-47 (handler)Handler function that manages file upload in the browser's file chooser modal by setting the files and waiting for completion.
handle: async (tab, params, response) => { response.setIncludeSnapshot(); const modalState = tab.modalStates().find(state => state.type === 'fileChooser'); if (!modalState) throw new Error('No file chooser visible'); response.addCode(`// Select files for upload`); response.addCode(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`); tab.clearModalState(modalState); await tab.waitForCompletion(async () => { await modalState.fileChooser.setFiles(params.paths); }); }, - src/tools/files.ts:23-31 (schema)Schema definition for the browser_file_upload tool, specifying input as array of file paths and marking it as destructive.
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:36-52 (registration)Central registration of all tools, including browser_file_upload via the spread of the 'files' import.
export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ]; - src/tools.ts:21-21 (registration)Import of the files tool module which contains the browser_file_upload tool.
import files from './tools/files.js'; - src/tools/files.ts:20-49 (registration)Tool definition using defineTabTool, which creates and exports the browser_file_upload tool instance.
const uploadFile = defineTabTool({ capability: 'core', 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 (tab, params, response) => { response.setIncludeSnapshot(); const modalState = tab.modalStates().find(state => state.type === 'fileChooser'); if (!modalState) throw new Error('No file chooser visible'); response.addCode(`// Select files for upload`); response.addCode(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`); tab.clearModalState(modalState); await tab.waitForCompletion(async () => { await modalState.fileChooser.setFiles(params.paths); }); }, clearsModalState: 'fileChooser', });