playwright_upload_file
Upload files to web pages by specifying the CSS selector of the input element and the file’s absolute path using browser automation with Playwright.
Instructions
Upload a file to an input[type='file'] element on the page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absolute path to the file to upload | |
| selector | Yes | CSS selector for the file input element |
Implementation Reference
- src/tools/browser/interaction.ts:143-149 (handler)The execute method of UploadFileTool class implements the tool logic: waits for the file input selector and uses Playwright's page.setInputFiles to upload the specified file.async execute(args: any, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (page) => { await page.waitForSelector(args.selector); await page.setInputFiles(args.selector, args.filePath); return createSuccessResponse(`Uploaded file '${args.filePath}' to '${args.selector}'`); }); }
- src/tools.ts:184-195 (schema)Defines the input schema, name, and description for the playwright_upload_file tool.{ name: "playwright_upload_file", description: "Upload a file to an input[type='file'] element on the page", inputSchema: { type: "object", properties: { selector: { type: "string", description: "CSS selector for the file input element" }, filePath: { type: "string", description: "Absolute path to the file to upload" } }, required: ["selector", "filePath"], }, },
- src/toolHandler.ts:502-503 (registration)In handleToolCall function, the switch case registers and dispatches calls to the UploadFileTool instance.case "playwright_upload_file": return await uploadFileTool.execute(args, context);
- src/toolHandler.ts:327-327 (registration)Instantiates the UploadFileTool class instance used for handling the tool calls.if (!uploadFileTool) uploadFileTool = new UploadFileTool(server);
- src/tools.ts:459-459 (registration)Includes the tool name in the BROWSER_TOOLS array for conditional browser launch checks."playwright_upload_file",