Unable to select files via file manager for upload.
Bug Description
I am uploading files on the cloud, and it seems it cannot handle the opened file manager where you select the file.
Reproduction Steps
Ask it to upload something without drag and drop. (should use opened file manager.)
Solution: Try to implement this kind of function when a filepath is given, as the agent cannot understand elements outside the browser.
There needs to be an action in controller.service.py for file/files uploads.
async with page.expect_file_chooser() as fc_info:
await page.get_by_text("Upload file").click()
file_chooser = await fc_info.value
await file_chooser.set_files("myfile.pdf")
Code Sample
task = 'upload this file /home/u/panda.jpg to somesite that doesn't support drag and drop'
Version
0.1.29
LLM Model
Gemini 1.5 Pro
Operating System
Ubuntu 24.04.1 LTS x86_64
Relevant Log Output
No, log, a file manager is opened, and it is looping in the browser.
Found this custom controller function: file upload action
make this built-in action, upload is a common action. 👍
Hey folks,
I was working with file uploads using the example from the repo here:
https://github.com/browser-use/browser-use/blob/main/examples/custom-functions/file_upload.py
But that example seems broken with the newer version of browser-use.
Instead, I got it working using the older approach discussed here:
https://github.com/browser-use/browser-use/issues/578
That method works fine for simple test URLs like:
https://kzmpmkh2zfk1ojnpxfn1.lite.vusercontent.net/
I also tested it by spinning up basic HTML servers on my own, and it worked there too.
However, the problem arises with more modern web apps—many sites built using frameworks like React or Next.js render the entire site inside an <iframe> like this:
<html>
<body>
<iframe>
To replicate this scenario, I built a minimal test server that mimics this behavior. You can run it via Docker:
docker run --rm -it -p 8000:8000 rushichaudhari/button-iframe-demo
If you need a html folder and not a docker link please tag me I can upload the zip here.
Once it’s running, head to http://localhost:8000, and you’ll see the test page.
When I try to use browser-use to upload a file on this page, the browser opens the file picker, but then it gets stuck—it doesn’t proceed with the upload. This only seems to happen when the file input is inside an iframe.
Just wanted to share this as a reproducible case in case it's useful for debugging or fixing the file upload issue.
If anyone has suggestions or workarounds that might help with this, I’d really appreciate it!
Thanks!
Good to know, thanks, we'll make sure to test uploads from an iframe. Cc @gregpr07
Another observation: the below controller is working fine for my Docker image rushichaudhari/button-iframe-demo. I’m now looking for more uploads where it might fail.
@controller.action('Upload file ')
async def upload_file_iframe(browser: BrowserContext):
path = str(CV.absolute())
page = await browser.get_current_page()
# First, try to find a file input on the main page.
file_input = await page.query_selector('input[type="file"]')
context_to_use = page
# If not found, check if an iframe exists.
if file_input is None:
iframe_element = await page.query_selector("iframe")
if iframe_element:
frame = await iframe_element.content_frame()
if frame:
file_input = await frame.query_selector('input[type="file"]')
context_to_use = frame
# If still not found, try clicking a button in the context (main or iframe)
if file_input is None:
upload_button = await context_to_use.query_selector('div[role="button"], button')
if upload_button:
await upload_button.click()
# Wait for the file input to appear in the same context.
file_input = await context_to_use.wait_for_selector('input[type="file"]', timeout=10000)
if file_input is None:
return ActionResult(error="No file input element found after checking main page and iframe.")
# Force the file input to be visible.
await page.evaluate('(el) => el.style.display = "block"', file_input)
try:
await file_input.set_input_files(path)
msg = 'Successfully uploaded file using iframe detection'
logger.info(msg)
pyautogui.press('esc')
return ActionResult(extracted_content=msg)
except Exception as e:
logger.debug(f'Error in set_input_files: {str(e)}')
return ActionResult(error=f'Failed to upload file: {e}')
How do we use it for websites that open the computer's file chooser? This ain't working on those.
How do we use it for websites that open the computer's file chooser? This ain't working on those.
Yes im still facing the same issue
it seems to be working for me when i specify the file path in the prompt, like in the example, even in the iframe example posed by @0xrushi rushichaudhari/button-iframe-demo
code snippet that i used to test:
async def main():
task = "Go to http://0.0.0.0:8000/, upload the file temp.png into the field Click me to Upload File"
model = ChatGoogle(model='gemini-2.0-flash-001')
filePath = Path.cwd() / f'temp.png'
agent = Agent(
task=task,
llm=model,
controller=controller,
available_file_paths=[str(filePath)],
)
await agent.run()
input('Press Enter to close...')
https://github.com/browser-use/browser-use/blob/main/examples/custom-functions/file_upload.py