Skip to content

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

input clear: use native prototype value setter so React controlled inputs actually clear

MagMueller4ebc0f5d0d29
diff --git a/browser_use/browser/watchdogs/default_action_watchdog.py b/browser_use/browser/watchdogs/default_action_watchdog.py
index 33c243da5..de7750ae2 100644
--- a/browser_use/browser/watchdogs/default_action_watchdog.py
+++ b/browser_use/browser/watchdogs/default_action_watchdog.py
@@ -1383,7 +1383,19 @@ class DefaultActionWatchdog(BaseWatchdog):
} catch (e) {
// ignore
}
- this.value = "";
+ // Use the prototype's native value setter: React patches the instance
+ // setter to track values, so a direct `this.value = ""` makes React's
+ // tracker think nothing changed and the input event gets ignored,
+ // leaving controlled components with the old value.
+ const proto = this.tagName === 'TEXTAREA'
+ ? window.HTMLTextAreaElement.prototype
+ : window.HTMLInputElement.prototype;
+ const desc = Object.getOwnPropertyDescriptor(proto, 'value');
+ if (desc && desc.set) {
+ desc.set.call(this, "");
+ } else {
+ this.value = "";
+ }
this.dispatchEvent(new Event("input", { bubbles: true }));
this.dispatchEvent(new Event("change", { bubbles: true }));
return {cleared: true, method: 'value', finalText: this.value};