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
Preserve BrowserError's structured memory through execute_action
Saurav Pandaf30c3952c9a2
diff --git a/browser_use/tools/registry/service.py b/browser_use/tools/registry/service.pyindex 3fe5259b7..1fc4e7e50 100644--- a/browser_use/tools/registry/service.py+++ b/browser_use/tools/registry/service.py@@ -12,6 +12,7 @@ import pyotpfrom pydantic import BaseModel, Field, RootModel, create_modelfrom browser_use.browser import BrowserSession+from browser_use.browser.views import BrowserErrorfrom browser_use.filesystem.file_system import FileSystemfrom browser_use.llm.base import BaseChatModelfrom browser_use.observability import observe_debug@@ -395,6 +396,11 @@ class Registry(Generic[Context]):except Exception as e:raise+ except BrowserError:+ # BrowserError carries structured short/long-term memory for the LLM+ # (e.g. available dropdown options) — let Tools.act format it instead of+ # flattening it into a generic RuntimeError string.+ raiseexcept ValueError as e:# Preserve ValueError messages from validationif 'requires browser_session but none provided' in str(e) or 'requires page_extraction_llm but none provided' in str(diff --git a/tests/ci/test_browser_error_passthrough.py b/tests/ci/test_browser_error_passthrough.pynew file mode 100644index 000000000..e5bc1d013--- /dev/null+++ b/tests/ci/test_browser_error_passthrough.py@@ -0,0 +1,28 @@+"""Regression test: BrowserError raised inside an action must reach Tools.act with its+structured short/long-term memory intact, instead of being flattened into a generic+'Error executing action ...' RuntimeError by execute_action's catch-all handler."""++from browser_use.browser.views import BrowserError+from browser_use.tools.service import Tools+++async def test_browser_error_memory_survives_execute_action():+ tools = Tools()++ @tools.registry.action(description='Test action that raises a structured BrowserError')+ async def raise_structured_error():+ raise BrowserError(+ message='element is a select, not clickable',+ short_term_memory='Available options: alpha, beta, gamma',+ long_term_memory='Tried to click a dropdown; use select_dropdown instead',+ )++ ActionModel = tools.registry.create_action_model()+ action = ActionModel(**{'raise_structured_error': {}})++ result = await tools.act(action, browser_session=None) # type: ignore[arg-type] -- action doesn't touch the browser++ assert result.error == 'Tried to click a dropdown; use select_dropdown instead', (+ f'structured long_term_memory lost: {result.error!r}'+ )+ assert result.extracted_content == 'Available options: alpha, beta, gamma'