Skip to content

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

Merge branch 'main' into duplicate_file_download

Magnus Müllerae547c4a0577
diff --cc browser_use/browser/context.py
index 48c5fa0b5,0e394dc62..32a1f0691
--- a/browser_use/browser/context.py
+++ b/browser_use/browser/context.py
@@@ -1145,13 -1158,4 +1166,15 @@@ class BrowserContext
screenshot=None,
tabs=[],
)
- # endregion
+
++
+ async def _get_unique_filename(self, directory, filename):
+ """Generate a unique filename by appending (1), (2), etc., if a file already exists."""
+ base, ext = os.path.splitext(filename)
+ counter = 1
+ new_filename = filename
+ while os.path.exists(os.path.join(directory, new_filename)):
+ new_filename = f'{base} ({counter}){ext}'
+ counter += 1
+ return new_filename
++