browserFileUpload
Upload files to a specified input element using page ID and XPath reference, with configurable wait time for snapshots in browser automation.
Instructions
上传文件到指定元素
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pageId | Yes | 页面ID | |
| paths | Yes | 要上传的文件路径数组 | |
| ref | Yes | 文件输入元素的xp引用值 | |
| waitForTimeout | No | 操作后等待获取快照的延迟时间(毫秒,默认2000) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"pageId": {
"description": "页面ID",
"type": "string"
},
"paths": {
"description": "要上传的文件路径数组",
"items": {
"type": "string"
},
"type": "array"
},
"ref": {
"description": "文件输入元素的xp引用值",
"type": "string"
},
"waitForTimeout": {
"description": "操作后等待获取快照的延迟时间(毫秒,默认2000)",
"type": "number"
}
},
"required": [
"pageId",
"ref",
"paths"
],
"type": "object"
}
Implementation Reference
- lib/tools/files.js:18-44 (registration)Defines and exports the browser_file_upload tool using defineTabTool, which likely registers it as a tab tool.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(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`); tab.clearModalState(modalState); await tab.waitForCompletion(async () => { await modalState.fileChooser.setFiles(params.paths); }); }, clearsModalState: 'fileChooser', }); export default [ uploadFile, ];
- lib/tools/files.js:29-39 (handler)The handler function that finds the file chooser modal and sets the files from params.paths, clears the modal state, and waits 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(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`); tab.clearModalState(modalState); await tab.waitForCompletion(async () => { await modalState.fileChooser.setFiles(params.paths); }); },
- lib/tools/files.js:20-28 (schema)Tool schema defining name 'browser_file_upload', input schema expecting array of file paths, marked 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', },