Skip to content

Commit 299812f

Browse files
committed
fix(desktop): revalidate the editor's window before every keystroke
type_text and input_sequence check, before each key, that the editor still sits in an observed window (or a dialog above it) at its observed frame.
1 parent c5309b7 commit 299812f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎apps/desktop/native/computer-use/ComputerUse.swift‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,14 @@ final class Driver {
656656
}
657657
return false
658658
}
659+
let observedFrames = Array(snapshot.windowFrames.values)
659660
func validateFocus() throws {
660661
try checkCancellation(); try requireNonSecure(element)
662+
// The editor must still sit in an observed window (or a dialog above it) at the observed frame.
663+
guard let rawWindow = attribute(element, kAXWindowAttribute), CFGetTypeID(rawWindow) == AXUIElementGetTypeID(),
664+
acceptsInput(unsafeBitCast(rawWindow, to: AXUIElement.self), observed: observedFrames) else {
665+
throw ComputerError("stale_window", "The editor's window moved or is not an observed window; observe again.")
666+
}
661667
guard let current = attribute(root, kAXFocusedUIElementAttribute), holdsFocus(current) else { throw ComputerError("focus_changed", "The exact editor is no longer focused; remaining input was not dispatched. Observe again.") }
662668
if let focused = attribute(root, kAXFocusedUIElementAttribute), CFGetTypeID(focused) == AXUIElementGetTypeID() { try requireNonSecure(unsafeBitCast(focused, to: AXUIElement.self)) }
663669
}

0 commit comments

Comments
 (0)