Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
enable auto download pdfs
mertunsall5bce1b68982d
diff --git a/browser_use/browser/profile.py b/browser_use/browser/profile.pyindex 4fa41b1ad..8c00b1192 100644--- a/browser_use/browser/profile.py+++ b/browser_use/browser/profile.py@@ -413,10 +413,19 @@ class BrowserLaunchArgs(BaseModel):def set_default_downloads_path(self) -> Self:"""Set a unique default downloads path if none is provided."""if self.downloads_path is None:- import tempfile+ import uuid++ # Create unique directory in /tmp for downloads+ unique_id = str(uuid.uuid4())[:8] # 8 characters+ downloads_path = Path(f'/tmp/browser-use-downloads-{unique_id}')- # Create unique temporary directory for downloads- self.downloads_path = Path(tempfile.mkdtemp(prefix='browser-use-downloads-'))+ # Ensure path doesn't already exist (extremely unlikely but possible)+ while downloads_path.exists():+ unique_id = str(uuid.uuid4())[:8]+ downloads_path = Path(f'/tmp/browser-use-downloads-{unique_id}')++ self.downloads_path = downloads_path+ self.downloads_path.mkdir(parents=True, exist_ok=True)return self@staticmethod@@ -593,9 +602,7 @@ class BrowserProfile(BrowserConnectArgs, BrowserLaunchPersistentContextArgs, Bro)# --- Downloads ---- auto_download_pdfs: bool = Field(- default=False, description='Automatically download PDFs when navigating to PDF viewer pages.'- )+ auto_download_pdfs: bool = Field(default=True, description='Automatically download PDFs when navigating to PDF viewer pages.')profile_directory: str = 'Default' # e.g. 'Profile 1', 'Profile 2', 'Custom Profile', etc.diff --git a/examples/file_system/alphabet_earnings.py b/examples/file_system/alphabet_earnings.pyindex 52fe95a37..fcbfa82fe 100644--- a/examples/file_system/alphabet_earnings.py+++ b/examples/file_system/alphabet_earnings.py@@ -6,24 +6,13 @@ import shutilfrom dotenv import load_dotenvfrom browser_use import Agent, ChatOpenAI-from browser_use.browser import BrowserProfile, BrowserSessionload_dotenv()-''SCRIPT_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))agent_dir = SCRIPT_DIR / 'alphabet_earnings'agent_dir.mkdir(exist_ok=True)--llm = ChatOpenAI(- model='o4-mini',-)--browser_session = BrowserSession(- browser_profile=BrowserProfile(downloads_path=str(agent_dir / 'downloads')),-)-task = """Go to https://abc.xyz/assets/cc/27/3ada14014efbadd7a58472f1f3f4/2025q2-alphabet-earnings-release.pdf.Read the PDF and save 3 interesting data points in "alphabet_earnings.pdf" and share it with me!@@ -31,16 +20,15 @@ Read the PDF and save 3 interesting data points in "alphabet_earnings.pdf" and sagent = Agent(task=task,- llm=llm,- browser_session=browser_session,+ llm=ChatOpenAI(model='o4-mini'),file_system_path=str(agent_dir / 'fs'),flash_mode=True,)async def main():- agent_history = await agent.run()- input('Press Enter to clean the file system...')+ await agent.run()+ input(f'Press Enter to clean the file system at {agent_dir}...')# clean the file systemshutil.rmtree(str(agent_dir / 'fs'))