Skip to content

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

refactor: enhance error handling in action execution

Magnus Müller680b7e7346e2
diff --git a/browser_use/controller/registry/service.py b/browser_use/controller/registry/service.py
index 474fa6fc2..bd05e510c 100644
--- a/browser_use/controller/registry/service.py
+++ b/browser_use/controller/registry/service.py
@@ -370,14 +370,13 @@ class Registry(Generic[Context]):
except Exception as e:
# Retry once if it's a page error
logger.warning(f'⚠️ Action {action_name}() failed: {type(e).__name__}: {e}, trying one more time...')
- # if page error
- # 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_error
+ 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_error
raise
except ValueError as e: