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
improve logging of errors
Nick Sweetingc36ca35984cc
diff --git a/browser_use/controller/registry/service.py b/browser_use/controller/registry/service.pyindex 8e46467c8..b20e144cf 100644--- a/browser_use/controller/registry/service.py+++ b/browser_use/controller/registry/service.py@@ -357,15 +357,14 @@ class Registry(Generic[Context]):return await action.function(params=validated_params, **special_context)except Exception as e:# Retry once if it's a page error- if 'page' in str(e) and browser_session and 'page' in special_context:- logger.warning(f'Page error in {action_name}, retrying with fresh page')- special_context['page'] = await browser_session.get_current_page()- try:- return await action.function(params=validated_params, **special_context)- except Exception:- raise RuntimeError(- f'Action {action_name} failed: The page may have been closed or navigated away during execution'- ) from e+ logger.warning(f'⚠️ Action {action_name}() failed: {type(e).__name__}: {e}, trying one more time...')+ special_context['page'] = browser_session and await browser_session.get_current_page()+ try:+ return await action.function(params=validated_params, **special_context)+ except Exception as retry_error:+ raise RuntimeError(+ f'Action {action_name}() failed: {type(e).__name__}: {e} (page may have closed or navigated away mid-action)'+ ) from retry_errorraiseexcept ValueError as e:diff --git a/tests/ci/test_controller.py b/tests/ci/test_controller.pyindex 23316efe7..bb9f100e4 100644--- a/tests/ci/test_controller.py+++ b/tests/ci/test_controller.py@@ -1195,7 +1195,7 @@ class TestControllerIntegration:# This should fail if page_extraction_llm is not passed correctlywith pytest.raises(RuntimeError) as exc_info:- await controller.act(ExtractContentActionModel(**extract_action), browser_session)+ await controller.act(ExtractContentActionModel(**extract_action), browser_session, page_extraction_llm=None)# Should fail because page_extraction_llm is required but not providedassert 'page_extraction_llm' in str(exc_info.value)