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 different way
mertunsall280b37d40e4b
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex c7c39757f..1068896e9 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -3562,14 +3562,14 @@ class BrowserSession(BaseModel):if is_new_tab_page(page.url):self.logger.warning(- f'▫️ Sending LLM no screenshot instead of real screenshot of: {_log_pretty_url(page.url)} (page empty)'+ f'▫️ Sending LLM 4px placeholder instead of real screenshot of: {_log_pretty_url(page.url)} (page empty)'+ )+ # not an exception because there's no point in retrying if we hit this, its always pointless to screenshot about:blank+ # raise ValueError('Refusing to take unneeded screenshot of empty new tab page')+ # return a 4px*4px white png to avoid wasting tokens - instead of 1px*1px white png that was not accepted by groq LLaMa models+ return (+ 'iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAFElEQVR4nGP8//8/AwwwMSAB3BwAlmMEAQBq1Aqg7XL3KQAAAABJRU5ErkJggg==')- # Not an exception because there's no point in retrying if we hit this, its always pointless to screenshot about:blank- # Originally returned a 1x1 white PNG to avoid wasting tokens, but groq LLaMa models do not accept this- # So we return None instead, which the LLM can handle more reliably- # TODO: this should be decided on an LLM level - now take_screenshot doesnt give you the screenshot if the page is empty- # this might be weird behavior for the library overall- return None# Always bring page to front before rendering, otherwise it crashes in some cases, not sure whytry:diff --git a/tests/ci/test_browser_session_ownership.py b/tests/ci/test_browser_session_ownership.pyindex 47c984d12..393f96b24 100644--- a/tests/ci/test_browser_session_ownership.py+++ b/tests/ci/test_browser_session_ownership.py@@ -178,6 +178,8 @@ class TestBrowserOwnership:# Try to use the copy - it should recoverawait copied_session.start() # Should reconnectscreenshot = await copied_session.take_screenshot()+ assert screenshot is not None+ assert len(screenshot) > 0# Clean upawait original_session.kill()diff --git a/tests/ci/test_browser_session_reuse.py b/tests/ci/test_browser_session_reuse.pyindex 4a4c3bc78..fd4b16ddd 100644--- a/tests/ci/test_browser_session_reuse.py+++ b/tests/ci/test_browser_session_reuse.py@@ -121,6 +121,7 @@ class TestBrowserSessionReuse:# Take a screenshot to verify it worksscreenshot1 = await session.take_screenshot()+ assert screenshot1 is not None# Store browser PIDinitial_pid = session.browser_pid@@ -145,6 +146,7 @@ class TestBrowserSessionReuse:try:screenshot2 = await session.take_screenshot()# If it succeeded, the browser should have been regenerated+ assert screenshot2 is not Noneexcept Exception:# If it failed, that's also OK - the browser state was resetpass@@ -162,6 +164,9 @@ class TestBrowserSessionReuse:# Verify we can still use the browser after regenerationawait session.start() # Ensure browser is started+ screenshot3 = await session.take_screenshot()+ assert screenshot3 is not None+ assert len(screenshot3) > 0finally:await session.stop()