@@ -361,17 +361,30 @@ export const uploadFile = definePageTool({
361361 . describe (
362362 'The uid of the file input element or an element that will open file chooser on the page from the page content snapshot' ,
363363 ) ,
364- filePath : zod . string ( ) . describe ( 'The local path of the file to upload' ) ,
364+ filePath : zod
365+ . string ( )
366+ . describe ( 'The local path of a file to upload. Use filePaths for multiple files.' )
367+ . optional ( ) ,
368+ filePaths : zod
369+ . array ( zod . string ( ) )
370+ . describe ( 'One or more local file paths to upload in a single operation.' )
371+ . optional ( ) ,
365372 includeSnapshot : includeSnapshotSchema ,
366373 } ,
367374 handler : async ( request , response ) => {
368- const { uid, filePath} = request . params ;
375+ const { uid} = request . params ;
376+ const filePaths =
377+ request . params . filePaths ??
378+ ( request . params . filePath ? [ request . params . filePath ] : [ ] ) ;
379+ if ( ! filePaths . length ) {
380+ throw new Error ( 'Provide filePath or filePaths to upload.' ) ;
381+ }
369382 const handle = ( await request . page . getElementByUid (
370383 uid ,
371384 ) ) as ElementHandle < HTMLInputElement > ;
372385 try {
373386 try {
374- await handle . uploadFile ( filePath ) ;
387+ await handle . uploadFile ( ... filePaths ) ;
375388 } catch {
376389 // Some sites use a proxy element to trigger file upload instead of
377390 // a type=file element. In this case, we want to default to
@@ -381,7 +394,7 @@ export const uploadFile = definePageTool({
381394 request . page . pptrPage . waitForFileChooser ( { timeout : 3000 } ) ,
382395 handle . asLocator ( ) . click ( ) ,
383396 ] ) ;
384- await fileChooser . accept ( [ filePath ] ) ;
397+ await fileChooser . accept ( filePaths ) ;
385398 } catch {
386399 throw new Error (
387400 `Failed to upload file. The element could not accept the file directly, and clicking it did not trigger a file chooser.` ,
@@ -391,7 +404,11 @@ export const uploadFile = definePageTool({
391404 if ( request . params . includeSnapshot ) {
392405 response . includeSnapshot ( ) ;
393406 }
394- response . appendResponseLine ( `File uploaded from ${ filePath } .` ) ;
407+ response . appendResponseLine (
408+ filePaths . length === 1
409+ ? `File uploaded from ${ filePaths [ 0 ] } .`
410+ : `Files uploaded from ${ filePaths . join ( ', ' ) } .` ,
411+ ) ;
395412 } finally {
396413 void handle . dispose ( ) ;
397414 }
0 commit comments