Skip to content

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

Rename Clear existing to clear

Magnus Müller6d941a5dccd3
diff --git a/browser_use/actor/element.py b/browser_use/actor/element.py
index 7d368586c..daaa9d3ee 100644
--- a/browser_use/actor/element.py
+++ b/browser_use/actor/element.py
@@ -349,7 +349,7 @@ class Element:
# Extract key element info for error message
raise RuntimeError(f'Failed to click element: {e}')
- async def fill(self, value: str, clear_existing: bool = True) -> None:
+ async def fill(self, value: str, clear: bool = True) -> None:
"""Fill the input element using proper CDP methods with improved focus handling."""
try:
# Use the existing CDP client and session
@@ -409,7 +409,7 @@ class Element:
)
# Step 2: Clear existing text if requested
- if clear_existing and focused_successfully:
+ if clear and focused_successfully:
cleared_successfully = await self._clear_text_field(
object_id=object_id, cdp_client=cdp_client, session_id=session_id
)
diff --git a/browser_use/browser/events.py b/browser_use/browser/events.py
index 397140f49..ae7b8b1e5 100644
--- a/browser_use/browser/events.py
+++ b/browser_use/browser/events.py
@@ -143,7 +143,7 @@ class TypeTextEvent(ElementSelectedEvent[dict | None]):
node: 'EnhancedDOMTreeNode'
text: str
- clear_existing: bool = True
+ clear: bool = True
is_sensitive: bool = False # Flag to indicate if text contains sensitive data
sensitive_key_name: str | None = None # Name of the sensitive key being typed (e.g., 'username', 'password')
diff --git a/browser_use/browser/watchdogs/default_action_watchdog.py b/browser_use/browser/watchdogs/default_action_watchdog.py
index 1463ac043..1ab26839b 100644
--- a/browser_use/browser/watchdogs/default_action_watchdog.py
+++ b/browser_use/browser/watchdogs/default_action_watchdog.py
@@ -144,7 +144,7 @@ class DefaultActionWatchdog(BaseWatchdog):
input_metadata = await self._input_text_element_node_impl(
element_node,
event.text,
- clear_existing=event.clear_existing or (not event.text),
+ clear=event.clear or (not event.text),
is_sensitive=event.is_sensitive,
)
# Log with sensitive data protection
@@ -994,7 +994,7 @@ class DefaultActionWatchdog(BaseWatchdog):
return False
async def _input_text_element_node_impl(
- self, element_node: EnhancedDOMTreeNode, text: str, clear_existing: bool = True, is_sensitive: bool = False
+ self, element_node: EnhancedDOMTreeNode, text: str, clear: bool = True, is_sensitive: bool = False
) -> dict | None:
"""
Input text into an element using pure CDP with improved focus fallbacks.
@@ -1057,7 +1057,7 @@ class DefaultActionWatchdog(BaseWatchdog):
)
# Step 2: Clear existing text if requested
- if clear_existing and focused_successfully:
+ if clear and focused_successfully:
cleared_successfully = await self._clear_text_field(object_id=object_id, cdp_session=cdp_session)
if not cleared_successfully:
self.logger.warning('⚠️ Text field clearing failed, typing may append to existing text')
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.py
index 05739dab7..60a0012e3 100644
--- a/browser_use/tools/service.py
+++ b/browser_use/tools/service.py
@@ -313,7 +313,7 @@ class Tools(Generic[Context]):
TypeTextEvent(
node=node,
text=params.text,
- clear_existing=params.clear,
+ clear=params.clear,
is_sensitive=has_sensitive_data,
sensitive_key_name=sensitive_key_name,
)