Fix Google CUA clear_before_typing behavior in Python client #246
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
why
Stagehand’s Google CUA integration was ignoring
clear_before_typingfortype_text_atactions in the Python client.As a result, when Gemini tried to overwrite input fields (e.g. email search fields), text kept getting appended instead of replaced, even when the model explicitly set
clear_before_typing=True.The TypeScript client already behaves correctly; this PR brings the Python client in line with that behavior.
what changed
clear_before_typing: Optional[bool] = Falseto [TypeAction] in [stagehand/types/agent.py] so the flag is representable in the Python action model.clear_before_typingfrom Geminitype_text_attool call args.clear_before_typingtoTruewhen not provided, matching the TS client’s behavior.action_type == "type":clear_before_typing=True, perform a triple-click at(x, y)to select all existing text, then type the new text so it replaces the selection.clear_before_typing=False, keep the existing behavior: single click then type (append).clear_before_typing=True, fall back toMeta+a/Control+a+Backspacebefore typing.clear_before_typing.press_enter_afterinteraction withclear_before_typing.clear_before_typingfield behavior.test plan
pytest tests/unit/handlers/test_cua_handler.py -vpython test_clear_typing.pyto:clear_before_typing=False, text is appended to the pre-filled field.clear_before_typing=True, the field is cleared (via triple-click select-all) and only the new text remains, consistently across multiple attempts.test_clear_typing.py
Summary by cubic
Fixes the Python Google CUA client so type_text_at honors clear_before_typing, matching TS behavior and preventing accidental text appends. Defaults to clearing before typing for Gemini tool calls and adds reliable field clearing.
Written for commit 1801c1f. Summary will update automatically on new commits.