Skip to content

Commit 47e0388

Browse files
k4cper-gclaude
andcommitted
Make SetFocus non-fatal in type action for CEF/Chromium compatibility
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4ce48a0 commit 47e0388

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cup/actions/_windows.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,17 +520,23 @@ def _type(self, element, text: str) -> ActionResult:
520520
try:
521521
pat = _get_pattern(element, UIA_ValuePatternId, _IValue)
522522
if pat:
523-
element.SetFocus()
524-
time.sleep(0.05)
523+
try:
524+
element.SetFocus()
525+
time.sleep(0.05)
526+
except (comtypes.COMError, Exception):
527+
pass # element may already be focused
525528
pat.SetValue(text)
526529
return ActionResult(success=True, message=f"Typed: {text}")
527530
except (comtypes.COMError, Exception):
528531
pass # fall through to SendInput
529532

530533
# Fallback: keyboard simulation via Unicode SendInput.
531534
try:
532-
element.SetFocus()
533-
time.sleep(0.05)
535+
try:
536+
element.SetFocus()
537+
time.sleep(0.05)
538+
except (comtypes.COMError, Exception):
539+
pass # element may already be focused
534540
_send_key_combo("ctrl+a")
535541
time.sleep(0.05)
536542
_send_unicode_string(text)

0 commit comments

Comments
 (0)