Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

fixed remote urls in tests

Saurav Panda86b12491dc8c
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.py
index 350ac1971..2b730a733 100644
--- a/browser_use/tools/service.py
+++ b/browser_use/tools/service.py
@@ -2023,7 +2023,7 @@ Validated Code (after quote fixing):
'Complete task with structured output.',
param_model=StructuredOutputAction[output_model],
)
- async def done(params: StructuredOutputAction, file_system: FileSystem, available_file_paths: list[str]):
+ async def done(params: StructuredOutputAction, file_system: FileSystem, browser_session: BrowserSession):
# Exclude success from the output JSON
# Use mode='json' to properly serialize enums at all nesting levels
output_dict = params.data.model_dump(mode='json')
@@ -2037,11 +2037,12 @@ Validated Code (after quote fixing):
if file_content:
attachments.append(str(file_system.get_dir() / file_name))
- # 2. Auto-attach any session downloads (browser-downloaded files)
- # that weren't already covered by files_to_display
- if available_file_paths:
+ # 2. Auto-attach actual session downloads (CDP-tracked browser downloads)
+ # but NOT user-supplied whitelist paths from available_file_paths
+ session_downloads = browser_session.downloaded_files
+ if session_downloads:
existing = set(attachments)
- for file_path in available_file_paths:
+ for file_path in session_downloads:
if file_path not in existing:
attachments.append(file_path)
diff --git a/tests/ci/test_tools.py b/tests/ci/test_tools.py
index be572af60..c3d8fb04e 100644
--- a/tests/ci/test_tools.py
+++ b/tests/ci/test_tools.py
@@ -515,7 +515,6 @@ class TestStructuredOutputDoneWithFiles:
success=True,
browser_session=browser_session,
file_system=file_system,
- available_file_paths=[],
)
assert isinstance(result, ActionResult)
@@ -544,7 +543,6 @@ class TestStructuredOutputDoneWithFiles:
files_to_display=['report.txt'],
browser_session=browser_session,
file_system=file_system,
- available_file_paths=[],
)
assert isinstance(result, ActionResult)
@@ -557,7 +555,7 @@ class TestStructuredOutputDoneWithFiles:
assert len(result.attachments) == 1
assert result.attachments[0].endswith('report.txt')
- async def test_structured_output_done_auto_attaches_downloads(self, browser_session):
+ async def test_structured_output_done_auto_attaches_downloads(self, browser_session, base_url):
"""Session downloads are auto-attached even without files_to_display."""
class MyOutput(BaseModel):
@@ -568,27 +566,31 @@ class TestStructuredOutputDoneWithFiles:
with tempfile.TemporaryDirectory() as temp_dir:
file_system = FileSystem(temp_dir)
- # Simulate a browser-downloaded file via available_file_paths
+ # Simulate a CDP-tracked browser download
fake_download = os.path.join(temp_dir, 'tax-bill.pdf')
await anyio.Path(fake_download).write_bytes(b'%PDF-1.4 fake pdf content')
- result = await tools.done(
- data={'url': 'https://example.com/bill.pdf'},
- success=True,
- browser_session=browser_session,
- file_system=file_system,
- available_file_paths=[fake_download],
- )
-
- assert isinstance(result, ActionResult)
- assert result.is_done is True
- assert result.extracted_content is not None
- output = json.loads(result.extracted_content)
- assert output == {'url': 'https://example.com/bill.pdf'}
- # The download should be auto-attached
- assert result.attachments is not None
- assert len(result.attachments) == 1
- assert result.attachments[0] == fake_download
+ saved_downloads = browser_session._downloaded_files.copy()
+ browser_session._downloaded_files.append(fake_download)
+ try:
+ result = await tools.done(
+ data={'url': f'{base_url}/bill.pdf'},
+ success=True,
+ browser_session=browser_session,
+ file_system=file_system,
+ )
+
+ assert isinstance(result, ActionResult)
+ assert result.is_done is True
+ assert result.extracted_content is not None
+ output = json.loads(result.extracted_content)
+ assert output == {'url': f'{base_url}/bill.pdf'}
+ # The download should be auto-attached
+ assert result.attachments is not None
+ assert len(result.attachments) == 1
+ assert result.attachments[0] == fake_download
+ finally:
+ browser_session._downloaded_files = saved_downloads
async def test_structured_output_done_deduplicates_attachments(self, browser_session):
"""Downloads already covered by files_to_display are not duplicated."""
@@ -602,23 +604,27 @@ class TestStructuredOutputDoneWithFiles:
file_system = FileSystem(temp_dir)
await file_system.write_file('report.txt', 'content here')
- # The same file appears in both files_to_display and available_file_paths
+ # The same file appears in both files_to_display and session downloads
fs_path = str(file_system.get_dir() / 'report.txt')
- result = await tools.done(
- data={'status': 'ok'},
- success=True,
- files_to_display=['report.txt'],
- browser_session=browser_session,
- file_system=file_system,
- available_file_paths=[fs_path],
- )
-
- assert isinstance(result, ActionResult)
- # Should have exactly 1 attachment, not 2
- assert result.attachments is not None
- assert len(result.attachments) == 1
- assert result.attachments[0] == fs_path
+ saved_downloads = browser_session._downloaded_files.copy()
+ browser_session._downloaded_files.append(fs_path)
+ try:
+ result = await tools.done(
+ data={'status': 'ok'},
+ success=True,
+ files_to_display=['report.txt'],
+ browser_session=browser_session,
+ file_system=file_system,
+ )
+
+ assert isinstance(result, ActionResult)
+ # Should have exactly 1 attachment, not 2
+ assert result.attachments is not None
+ assert len(result.attachments) == 1
+ assert result.attachments[0] == fs_path
+ finally:
+ browser_session._downloaded_files = saved_downloads
async def test_structured_output_done_nonexistent_file_ignored(self, browser_session):
"""Files that don't exist in FileSystem are not included via files_to_display."""
@@ -637,7 +643,6 @@ class TestStructuredOutputDoneWithFiles:
files_to_display=['nonexistent.txt'],
browser_session=browser_session,
file_system=file_system,
- available_file_paths=[],
)
assert isinstance(result, ActionResult)