Skip to content

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

Fix tab info retrieval to preserve real URLs and improve LLM context

Cursor Agentbd776c6e60fe
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.py
index fa4cfceab..f5f5e9931 100644
--- a/browser_use/browser/session.py
+++ b/browser_use/browser/session.py
@@ -1834,9 +1834,16 @@ class BrowserSession(BaseModel):
tab_info = TabInfo(page_id=page_id, url=page.url, title=title)
except Exception:
# page.title() can hang forever on tabs that are crashed/disappeared/about:blank
- # we dont want to try automating those tabs because they will hang the whole script
- self.logger.debug(f'⚠️ Failed to get tab info for tab #{page_id}: {_log_pretty_url(page.url)} (ignoring)')
- tab_info = TabInfo(page_id=page_id, url='about:blank', title='ignore this tab and do not use it')
+ # but we should preserve the real URL and not mislead the LLM about tab availability
+ self.logger.debug(f'⚠️ Failed to get tab info for tab #{page_id}: {_log_pretty_url(page.url)} (using fallback title)')
+
+ # Only mark as unusable if it's actually about:blank, otherwise preserve the real URL
+ if page.url == 'about:blank':
+ tab_info = TabInfo(page_id=page_id, url='about:blank', title='ignore this tab and do not use it')
+ else:
+ # Preserve the real URL and use a descriptive fallback title
+ fallback_title = f'Loading... (title unavailable)'
+ tab_info = TabInfo(page_id=page_id, url=page.url, title=fallback_title)
tabs_info.append(tab_info)
return tabs_info
diff --git a/bug_analysis.md b/bug_analysis.md
new file mode 100644
index 000000000..984f644b3
--- /dev/null
+++ b/bug_analysis.md
@@ -0,0 +1,83 @@
+# Bug Analysis: False "about:blank" Tab Reports
+
+## Issue Description
+
+The browser-use system sometimes incorrectly reports tabs as `Tab 0: about:blank - ignore this tab and do not use` in the LLM context, even when there are actual websites loaded in those tabs.
+
+## Root Cause
+
+The issue is located in the `get_tabs_info()` method in `browser_use/browser/session.py` at lines 1823-1840:
+
+```python
+@require_initialization
+@time_execution_async('--get_tabs_info')
+async def get_tabs_info(self) -> list[TabInfo]:
+ """Get information about all tabs"""
+ assert self.browser_context is not None, 'BrowserContext is not set up'
+ tabs_info = []
+ for page_id, page in enumerate(self.browser_context.pages):
+ try:
+ title = await self._get_page_title(page)
+ tab_info = TabInfo(page_id=page_id, url=page.url, title=title)
+ except Exception:
+ # page.title() can hang forever on tabs that are crashed/disappeared/about:blank
+ # we dont want to try automating those tabs because they will hang the whole script
+ self.logger.debug(f'⚠️ Failed to get tab info for tab #{page_id}: {_log_pretty_url(page.url)} (ignoring)')
+ tab_info = TabInfo(page_id=page_id, url='about:blank', title='ignore this tab and do not use it')
+ tabs_info.append(tab_info)
+
+ return tabs_info
+```
+
+### The Problem
+
+When `self._get_page_title(page)` fails (which can happen for various legitimate reasons), the code incorrectly:
+
+1. **Overwrites the real URL** with `'about:blank'` even though `page.url` contains the actual URL
+2. **Sets a misleading title** `'ignore this tab and do not use it'`
+
+### When `_get_page_title()` Can Fail
+
+The `_get_page_title()` method has a 1-second timeout:
+
+```python
+@retry(timeout=1, retries=0) # Single attempt with 1s timeout, no retries
+async def _get_page_title(self, page: Page) -> str:
+ """Get page title with timeout protection."""
+ return await page.title()
+```
+
+This can fail when:
+- Page is still loading and takes more than 1 second to get the title
+- Page has JavaScript that modifies the title dynamically
+- Network is slow
+- Page is in a crashed/unresponsive state
+- Page has complex rendering that delays title availability
+
+### Impact
+
+This bug causes:
+1. **LLM confusion**: The LLM receives incorrect information about available tabs
+2. **Lost navigation opportunities**: Real websites are marked as "ignore this tab"
+3. **Inconsistent behavior**: The same website might sometimes appear correctly and sometimes as "about:blank"
+
+## Example from Slack Context
+
+In the reported case:
+- User has a tab with "Laminar" website at `https://www.lmnr.ai/project/...`
+- System reports: `Tab 0: about:blank - ignore this tab and do not use`
+- The actual URL was available but got masked by the fallback logic
+
+## Proposed Solution
+
+Instead of masking the real URL when title retrieval fails, we should:
+
+1. **Preserve the real URL** from `page.url`
+2. **Use a descriptive fallback title** that indicates the title couldn't be retrieved
+3. **Allow the LLM to still use the tab** since the URL is valid
+
+This maintains accurate tab information while gracefully handling title retrieval failures.
+
+## Fix Implementation
+
+The fix should modify the exception handling in `get_tabs_info()` to preserve the actual URL and use a more descriptive fallback title that doesn't mislead the LLM into ignoring valid tabs.
\ No newline at end of file
diff --git a/fix_summary.md b/fix_summary.md
new file mode 100644
index 000000000..448e792cc
--- /dev/null
+++ b/fix_summary.md
@@ -0,0 +1,69 @@
+# Fix Summary: Tab Information Bug Resolution
+
+## Issue Fixed
+Fixed the bug where browser-use incorrectly reports tabs as `Tab 0: about:blank - ignore this tab and do not use` even when real websites are loaded.
+
+## Root Cause
+Located in `browser_use/browser/session.py` in the `get_tabs_info()` method (lines 1825-1847). When `page.title()` failed due to timeouts or page loading issues, the code incorrectly:
+1. Masked the real URL by setting it to `'about:blank'`
+2. Used a misleading title `'ignore this tab and do not use it'`
+
+## Solution Implemented
+Modified the exception handling logic to:
+
+```python
+except Exception:
+ # page.title() can hang forever on tabs that are crashed/disappeared/about:blank
+ # but we should preserve the real URL and not mislead the LLM about tab availability
+ self.logger.debug(f'⚠️ Failed to get tab info for tab #{page_id}: {_log_pretty_url(page.url)} (using fallback title)')
+
+ # Only mark as unusable if it's actually about:blank, otherwise preserve the real URL
+ if page.url == 'about:blank':
+ tab_info = TabInfo(page_id=page_id, url='about:blank', title='ignore this tab and do not use it')
+ else:
+ # Preserve the real URL and use a descriptive fallback title
+ fallback_title = f'Loading... (title unavailable)'
+ tab_info = TabInfo(page_id=page_id, url=page.url, title=fallback_title)
+```
+
+## Key Improvements
+
+### 1. Preserves Real URLs
+- **Before**: `TabInfo(page_id=0, url='about:blank', title='ignore this tab and do not use it')`
+- **After**: `TabInfo(page_id=0, url='https://www.lmnr.ai/project/...', title='Loading... (title unavailable)')`
+
+### 2. Better LLM Context
+- LLM now receives accurate tab information even when title retrieval fails
+- Can still navigate to and use tabs with real URLs
+- Only actual `about:blank` tabs are marked as unusable
+
+### 3. Backward Compatibility
+- Existing tests continue to work
+- Same `TabInfo` structure returned
+- Only changes the fallback behavior for failed title retrieval
+
+## Test Verification
+Verified the fix logic with a simple test:
+```
+Tab 0: https://example.com - Loading... (title unavailable) # Real URL preserved
+Tab 1: about:blank - ignore this tab and do not use it # Actual about:blank handled correctly
+Tab 2: https://github.com - Test Page Title # Normal operation unchanged
+```
+
+## Impact
+- **Fixes LLM confusion** about available tabs
+- **Preserves navigation opportunities** to real websites
+- **Maintains system stability** by keeping timeout protection
+- **Improves user experience** by providing accurate tab information
+
+## Files Modified
+- `browser_use/browser/session.py`: Updated `get_tabs_info()` method exception handling (lines 1835-1845)
+
+## When `page.title()` Can Fail
+- Page still loading (>1 second timeout)
+- JavaScript-heavy pages with dynamic titles
+- Network latency issues
+- Crashed or unresponsive pages
+- Complex rendering delays
+
+The fix ensures these legitimate scenarios don't result in misleading tab information being sent to the LLM.
\ No newline at end of file