Skip to main content
Glama

Better Playwright MCP

by livoras

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

NameRequiredDescriptionDefault
pageIdYes页面ID
pathsYes要上传的文件路径数组
refYes文件输入元素的xp引用值
waitForTimeoutNo操作后等待获取快照的延迟时间(毫秒,默认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

  • 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, ];
  • 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); }); },
  • 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', },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/livoras/better-playwright-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server