Skip to content

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

refactor: Format excluded file extensions for better readability

Magnus Müller3fd7b1ab4717
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index ae70465db..e143d2f53 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -1388,21 +1388,73 @@ class Agent(Generic[Context, AgentStructuredOutput]):
# These are likely files rather than web pages to navigate to
excluded_extensions = {
# Documents
- 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp',
+ 'pdf',
+ 'doc',
+ 'docx',
+ 'xls',
+ 'xlsx',
+ 'ppt',
+ 'pptx',
+ 'odt',
+ 'ods',
+ 'odp',
# Text files
- 'txt', 'md', 'csv', 'json', 'xml', 'yaml', 'yml',
+ 'txt',
+ 'md',
+ 'csv',
+ 'json',
+ 'xml',
+ 'yaml',
+ 'yml',
# Archives
- 'zip', 'rar', '7z', 'tar', 'gz', 'bz2', 'xz',
+ 'zip',
+ 'rar',
+ '7z',
+ 'tar',
+ 'gz',
+ 'bz2',
+ 'xz',
# Images
- 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp', 'ico',
+ 'jpg',
+ 'jpeg',
+ 'png',
+ 'gif',
+ 'bmp',
+ 'svg',
+ 'webp',
+ 'ico',
# Audio/Video
- 'mp3', 'mp4', 'avi', 'mkv', 'mov', 'wav', 'flac', 'ogg',
+ 'mp3',
+ 'mp4',
+ 'avi',
+ 'mkv',
+ 'mov',
+ 'wav',
+ 'flac',
+ 'ogg',
# Code/Data
- 'py', 'js', 'css', 'html', 'htm', 'php', 'java', 'cpp', 'c', 'h',
+ 'py',
+ 'js',
+ 'css',
+ 'java',
+ 'cpp',
+ 'c',
+ 'h',
# Academic/Research
- 'bib', 'bibtex', 'tex', 'latex', 'cls', 'sty',
+ 'bib',
+ 'bibtex',
+ 'tex',
+ 'latex',
+ 'cls',
+ 'sty',
# Other common file types
- 'exe', 'msi', 'dmg', 'pkg', 'deb', 'rpm', 'iso',
+ 'exe',
+ 'msi',
+ 'dmg',
+ 'pkg',
+ 'deb',
+ 'rpm',
+ 'iso',
}
found_urls = []
@@ -1413,19 +1465,19 @@ class Agent(Generic[Context, AgentStructuredOutput]):
# Remove trailing punctuation that's not part of URLs
url = re.sub(r'[.,;:!?()\[\]]+$', '', url)
-
+
# Check if URL ends with a file extension that should be excluded
url_lower = url.lower()
should_exclude = False
for ext in excluded_extensions:
- if url_lower.endswith(f'.{ext}'):
+ if f'.{ext}' in url_lower:
should_exclude = True
break
-
+
if should_exclude:
self.logger.debug(f'Excluding URL with file extension from auto-navigation: {url}')
continue
-
+
# Add https:// if missing
if not url.startswith(('http://', 'https://')):
url = 'https://' + url