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
now newlines are executed well with send keys
mertunsallc4bb68105865
diff --git a/browser_use/browser/events.py b/browser_use/browser/events.pyindex fdae0815f..4c40cb428 100644--- a/browser_use/browser/events.py+++ b/browser_use/browser/events.py@@ -153,7 +153,7 @@ class TypeTextEvent(ElementSelectedEvent[dict | None]):is_sensitive: bool = False # Flag to indicate if text contains sensitive datasensitive_key_name: str | None = None # Name of the sensitive key being typed (e.g., 'username', 'password')- event_timeout: float | None = Field(default_factory=lambda: _get_timeout('TIMEOUT_TypeTextEvent', 15.0)) # seconds+ event_timeout: float | None = Field(default_factory=lambda: _get_timeout('TIMEOUT_TypeTextEvent', 60.0)) # secondsclass ScrollEvent(ElementSelectedEvent[None]):@@ -242,7 +242,7 @@ class SendKeysEvent(BaseEvent[None]):keys: str # e.g., "ctrl+a", "cmd+c", "Enter"- event_timeout: float | None = Field(default_factory=lambda: _get_timeout('TIMEOUT_SendKeysEvent', 15.0)) # seconds+ event_timeout: float | None = Field(default_factory=lambda: _get_timeout('TIMEOUT_SendKeysEvent', 60.0)) # secondsclass UploadFileEvent(ElementSelectedEvent[None]):diff --git a/browser_use/browser/watchdogs/default_action_watchdog.py b/browser_use/browser/watchdogs/default_action_watchdog.pyindex 2f492f344..a87664fe8 100644--- a/browser_use/browser/watchdogs/default_action_watchdog.py+++ b/browser_use/browser/watchdogs/default_action_watchdog.py@@ -920,9 +920,6 @@ class DefaultActionWatchdog(BaseWatchdog):},session_id=cdp_session.session_id,)- # Add 18ms delay between keystrokes- await asyncio.sleep(0.018)-except Exception as e:raise Exception(f'Failed to type to page: {str(e)}')@@ -2158,8 +2155,33 @@ class DefaultActionWatchdog(BaseWatchdog):for char in normalized_keys:# Special-case newline characters to dispatch as Enterif char in ('\n', '\r'):- await self._dispatch_key_event(cdp_session, 'keyDown', 'Enter')- await self._dispatch_key_event(cdp_session, 'keyUp', 'Enter')+ await cdp_session.cdp_client.send.Input.dispatchKeyEvent(+ params={+ 'type': 'rawKeyDown',+ 'windowsVirtualKeyCode': 13,+ 'unmodifiedText': '\r',+ 'text': '\r',+ },+ session_id=cdp_session.session_id,+ )+ await cdp_session.cdp_client.send.Input.dispatchKeyEvent(+ params={+ 'type': 'char',+ 'windowsVirtualKeyCode': 13,+ 'unmodifiedText': '\r',+ 'text': '\r',+ },+ session_id=cdp_session.session_id,+ )+ await cdp_session.cdp_client.send.Input.dispatchKeyEvent(+ params={+ 'type': 'keyUp',+ 'windowsVirtualKeyCode': 13,+ 'unmodifiedText': '\r',+ 'text': '\r',+ },+ session_id=cdp_session.session_id,+ )continue# Get proper modifiers and key info for the character@@ -2200,9 +2222,6 @@ class DefaultActionWatchdog(BaseWatchdog):session_id=cdp_session.session_id,)- # Small delay between characters (18ms like _type_to_page)- await asyncio.sleep(0.018)-self.logger.info(f'⌨️ Sent keys: {event.keys}')# Note: We don't clear cached state on Enter; multi_act will detect DOM changes