Skip to content

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

Refactor dropdown option logging and error messages in DefaultActionWatchdog and Tools classes

Magnus Müllerad505378df9c
diff --git a/browser_use/browser/watchdogs/default_action_watchdog.py b/browser_use/browser/watchdogs/default_action_watchdog.py
index 9bd1aff1f..d81285863 100644
--- a/browser_use/browser/watchdogs/default_action_watchdog.py
+++ b/browser_use/browser/watchdogs/default_action_watchdog.py
@@ -2510,10 +2510,10 @@ class DefaultActionWatchdog(BaseWatchdog):
short_term_options.append(f'- {opt}')
if short_term_options:
- short_term_memory = f'Available dropdown options at index {index_for_logging} are:\n' + '\n'.join(
- short_term_options
+ short_term_memory = 'Available dropdown options are:\n' + '\n'.join(short_term_options)
+ long_term_memory = (
+ f"Couldn't select the dropdown option as '{target_text}' is not one of the available options."
)
- long_term_memory = f"Couldn't select the dropdown option at index {index_for_logging} as '{target_text}' is not one of the available options."
# Return error result with structured memory instead of raising exception
return {
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.py
index 5d94bb53c..599716ce8 100644
--- a/browser_use/tools/service.py
+++ b/browser_use/tools/service.py
@@ -332,14 +332,14 @@ class Tools(Generic[Context]):
# Create message with sensitive data handling
if has_sensitive_data:
if sensitive_key_name:
- msg = f'Input {sensitive_key_name} into element {params.index}.'
- log_msg = f'Input <{sensitive_key_name}> into element {params.index}.'
+ msg = f'Typed {sensitive_key_name}'
+ log_msg = f'Typed <{sensitive_key_name}>'
else:
- msg = f'Input sensitive data into element {params.index}.'
- log_msg = f'Input <sensitive> into element {params.index}.'
+ msg = 'Typed sensitive data'
+ log_msg = 'Typed <sensitive>'
else:
- msg = f"Input '{params.text}' into element {params.index}."
- log_msg = msg
+ msg = f"Typed '{params.text}'"
+ log_msg = f"Typed '{params.text}'"
logger.debug(log_msg)
@@ -354,7 +354,7 @@ class Tools(Generic[Context]):
except Exception as e:
# Log the full error for debugging
logger.error(f'Failed to dispatch TypeTextEvent: {type(e).__name__}: {e}')
- error_msg = f'Failed to input text into element {params.index}: {e}'
+ error_msg = f'Failed to type text into element {params.index}: {e}'
return ActionResult(error=error_msg)
@self.registry.action(