browser-use: Unable to download file from pdf viewer

Bug Description

I am using this repo with Langraph. When I try to open a pdf link from web page, and prompt to download either clicking download icon on top right of pressing cmd+S, it confirms that file is downloaded to default path (Download folder) but it does not.

Reproduction Steps

Here is the prompt - prompt = “”"Prompt to download financial report for Bank of America

Objective Visit [BofA Online] (https://investor.bankofamerica.com/annual-reports-and-proxy-statements) and search for 2023 annual report and download it

Step 1

Step 2

  • Find Annual Report for 2023 and click on it. You might have to scroll the page to find the link.

Step 3

  • You’ll see a pdf in a new tab. Download the pdf by clicking the download icon on top right. If you cannot perform this instruction, then try sending key command+S and then press enter to save at default location.

Important: Ensure efficiency and accuracy throughout the process. “”"

Code Sample

async def search_report(state: State):
    """First call to use Browser-Use and search"""
    browser = Browser(
	config=BrowserConfig(
		new_context_config=BrowserContextConfig(save_downloads_path=os.path.join(os.path.expanduser('~'), 'downloads'))
	))
    query = (
        f"Using a browser, perform the activities as stated here -  '{state['task']}'"
    )

    agent = Agent(
        task = query,
        llm = llm,
        browser = browser
    )

    history = await agent.run()
    msg = history.final_result()
    input("Press Enter to close the browser...")
    await browser.close()
    return {"output": msg}

Version

0.1.36

LLM Model

GPT-4o

Operating System

macOS Sequuoia 15.3

Relevant Log Output


About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 22 (3 by maintainers)

Most upvoted comments

@peetpro , I built a tool like this prototype, and added a request in the prompt for the agent to use this tool to download instead of clicking a download button. It’s a starting point, but works.

async def download_pdf(url: str, browser: Browser):
    print("Starting the PDF download process.")

    # it returns a BrowserContext which should have a Browser object
    playwright_browser = await browser.browser.get_playwright_browser()
    print("Type of browser:", type(playwright_browser))

    # get the first available browser context
    if not playwright_browser.contexts:
        return ActionResult(extracted_content="No active browser context found.")
    
    context = playwright_browser.contexts[0]  # Get the first available context

    # there should be at least one open page
    if not context.pages:
        return ActionResult(extracted_content="No active pages found in the browser.")
    
    # get the current page
    page = next(
        (page for page in context.pages if urlparse(url).netloc in page.url),
        None
    )

    download_button_selector = '#download'  # TODO: implement fallbacks for different download buttons, potentially LLM as well

    try:
        download_button = page.get_by_title("download")
    except Exception as e:
        print("Download button not found:", str(e))
        return ActionResult(extracted_content="Download button not found.")

    # start a download event listener
    async with page.expect_download() as download_info:
        await page.click(download_button_selector)

    # wait for the download to complete
    download = await download_info.value

    # define the path where the file should be saved
    download_path = os.path.join(os.getcwd(), "download", download.suggested_filename)
    await download.save_as(download_path)  # save the downloaded file to the specified path

    return ActionResult(extracted_content=f"PDF downloaded as {download.suggested_filename}")```

Ok, thanks for the clarification.

On Thu, 27 Mar 2025 at 09:26, Nick Sweeting @.***> wrote:

we would not rely on URL alone, the vision model can recognize when there is a pdf viewer open still, and we can always detect by mimetype too.

— Reply to this email directly, view it on GitHub https://github.com/browser-use/browser-use/issues/729#issuecomment-2757165387, or unsubscribe https://github.com/notifications/unsubscribe-auth/BMJO2JMVCCNSKGPUEHKR6JT2WOY2PAVCNFSM6AAAAABXFARIRGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONJXGE3DKMZYG4 . You are receiving this because you were mentioned.Message ID: @.***> [image: pirate]pirate left a comment (browser-use/browser-use#729) https://github.com/browser-use/browser-use/issues/729#issuecomment-2757165387

we would not rely on URL alone, the vision model can recognize when there is a pdf viewer open still, and we can always detect by mimetype too.

— Reply to this email directly, view it on GitHub https://github.com/browser-use/browser-use/issues/729#issuecomment-2757165387, or unsubscribe https://github.com/notifications/unsubscribe-auth/BMJO2JMVCCNSKGPUEHKR6JT2WOY2PAVCNFSM6AAAAABXFARIRGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONJXGE3DKMZYG4 . You are receiving this because you were mentioned.Message ID: @.***>

–

Regards, Manoj Tutika https://www.linkedin.com/in/manoj-tutika-09b16220/, CEO & Cofounder, Sunday AI https://getsunday.ai/

yeah I get it, thanks. But if the underlying playwright can’t get a hold of the identifier inside the pdf viewer, it can’t click on it at the end.

Wondering how to get that identifier. Does it make sense?