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
fix(agent): preserve downloaded file path order
Myung Lemke3dd28b0d997f
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 3e0970ddd..ad59b4335 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -676,11 +676,16 @@ class Agent(Generic[Context, AgentStructuredOutput]):if not self.has_downloads_path:return- current_files = set(self.available_file_paths or [])- new_files = set(downloads) - current_files+ available_files = self.available_file_paths or []+ seen_files = set(available_files)+ new_files = []+ for download in downloads:+ if download not in seen_files:+ seen_files.add(download)+ new_files.append(download)if new_files:- self.available_file_paths = list(current_files | new_files)+ self.available_file_paths = [*available_files, *new_files]self.logger.info(f'π Added {len(new_files)} downloaded files to available_file_paths (total: {len(self.available_file_paths)} files)'@@ -688,7 +693,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):for file_path in new_files:self.logger.info(f'π New file available: {file_path}')else:- self.logger.debug(f'π No new downloads detected (tracking {len(current_files)} files)')+ self.logger.debug(f'π No new downloads detected (tracking {len(available_files)} files)')def _set_file_system(self, file_system_path: str | None = None) -> None:# Check for conflicting parametersdiff --git a/tests/ci/test_agent_download_paths.py b/tests/ci/test_agent_download_paths.pynew file mode 100644index 000000000..5cc082f9d--- /dev/null+++ b/tests/ci/test_agent_download_paths.py@@ -0,0 +1,22 @@+from browser_use.agent.service import Agent+from browser_use.browser import BrowserProfile, BrowserSession+from tests.ci.conftest import create_mock_llm+++def test_update_available_file_paths_preserves_input_and_download_order(tmp_path):+ session = BrowserSession(browser_profile=BrowserProfile(downloads_path=tmp_path))+ agent = Agent(+ task='Use downloaded files.',+ llm=create_mock_llm(),+ browser_session=session,+ available_file_paths=['/tmp/input-b.txt', '/tmp/input-a.txt'],+ )++ agent._update_available_file_paths(['/tmp/download-b.txt', '/tmp/input-a.txt', '/tmp/download-a.txt', '/tmp/download-b.txt'])++ assert agent.available_file_paths == [+ '/tmp/input-b.txt',+ '/tmp/input-a.txt',+ '/tmp/download-b.txt',+ '/tmp/download-a.txt',+ ]