Skip to content

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

fix: Fix Draft.js space prepending to only apply when clear=True

zhongzhenyuf13d8246e950
diff --git a/browser_use/browser/watchdogs/default_action_watchdog.py b/browser_use/browser/watchdogs/default_action_watchdog.py
index c60fc2858..110562b68 100644
--- a/browser_use/browser/watchdogs/default_action_watchdog.py
+++ b/browser_use/browser/watchdogs/default_action_watchdog.py
@@ -1567,8 +1567,9 @@ class DefaultActionWatchdog(BaseWatchdog):
or 'data-offset-key' in _attrs # Draft.js offset key for content tracking
)
- if _is_draftjs and len(text) > 0:
- # Prepend a space as "sacrifice character" - it will be dropped by Draft.js
+ if _is_draftjs and len(text) > 0 and clear:
+ # Prepend a space as "sacrifice character" - it will be dropped by Draft.js
+ # Only when clear=True (cursor at leaf start), otherwise Draft.js won't drop it
text = ' ' + text
self.logger.debug('🎯 Draft.js detected, prepending sacrifice space')