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
Keep plain BrowserErrors recoverable: only structured ones bypass the generic handler
Saurav Panda782535c34fe8
diff --git a/browser_use/tools/registry/service.py b/browser_use/tools/registry/service.pyindex 1fc4e7e50..f45068b07 100644--- a/browser_use/tools/registry/service.py+++ b/browser_use/tools/registry/service.py@@ -396,11 +396,15 @@ class Registry(Generic[Context]):except Exception as e:raise- except BrowserError:- # BrowserError carries structured short/long-term memory for the LLM+ except BrowserError as e:+ # BrowserError can carry 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.- raise+ # flattening it into a generic RuntimeError string. Only errors with+ # long_term_memory bypass: handle_browser_error re-raises without it,+ # which would escape Tools.act instead of returning an ActionResult.+ if e.long_term_memory is not None:+ raise+ raise RuntimeError(f'Error executing action {action_name}: {str(e)}') from eexcept 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.pyindex e5bc1d013..5f75eb205 100644--- a/tests/ci/test_browser_error_passthrough.py+++ b/tests/ci/test_browser_error_passthrough.py@@ -26,3 +26,21 @@ async def test_browser_error_memory_survives_execute_action():f'structured long_term_memory lost: {result.error!r}')assert result.extracted_content == 'Available options: alpha, beta, gamma'+++async def test_plain_browser_error_still_returns_recoverable_action_result():+ """A BrowserError without long_term_memory must not escape Tools.act as an+ exception — it must still come back as a recoverable ActionResult (as it did+ when the generic execute_action handler flattened it)."""+ tools = Tools()++ @tools.registry.action(description='Test action that raises a plain BrowserError')+ async def raise_plain_error():+ raise BrowserError(message='element with index 5 does not exist')++ ActionModel = tools.registry.create_action_model()+ action = ActionModel(**{'raise_plain_error': {}})++ result = await tools.act(action, browser_session=None) # type: ignore[arg-type] -- action doesn't touch the browser++ assert result.error is not None and 'element with index 5 does not exist' in result.error