From 47f55b00d1043184b8744dbb7f22c440c93634ad Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Mon, 16 Nov 2026 19:29:28 -0800 Subject: [PATCH] fix(computer-use): find a save panel control's window through its ancestors when it reports none --- .../native/computer-use/ComputerUse.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/desktop/native/computer-use/ComputerUse.swift b/apps/desktop/native/computer-use/ComputerUse.swift index 17cc5afdedb..3c3fc161b8a 100644 --- a/apps/desktop/native/computer-use/ComputerUse.swift +++ b/apps/desktop/native/computer-use/ComputerUse.swift @@ -167,11 +167,22 @@ func takesText(_ element: AXUIElement) -> Bool { return AXUIElementIsAttributeSettable(element, kAXSelectedTextRangeAttribute as CFString, &settable) == .success && settable.boolValue } /// The window holding `element`: the element itself when it is a window or sheet, which report no -/// window of their own, otherwise the window it reports. +/// window of their own, otherwise the window it reports. Controls of an open or save panel belong to +/// the panel's service process and report no window, so for them the nearest window or sheet among +/// their ancestors is used. func containingWindow(_ element: AXUIElement) -> AXUIElement? { - if [kAXWindowRole, kAXSheetRole].contains(attribute(element, kAXRoleAttribute) as? String ?? "") { return element } - guard let raw = attribute(element, kAXWindowAttribute), CFGetTypeID(raw) == AXUIElementGetTypeID() else { return nil } - return unsafeBitCast(raw, to: AXUIElement.self) + let windowRoles = [kAXWindowRole, kAXSheetRole] + if windowRoles.contains(attribute(element, kAXRoleAttribute) as? String ?? "") { return element } + if let raw = attribute(element, kAXWindowAttribute), CFGetTypeID(raw) == AXUIElementGetTypeID() { + return unsafeBitCast(raw, to: AXUIElement.self) + } + var current = element + for _ in 0..<64 { + guard let raw = attribute(current, kAXParentAttribute), CFGetTypeID(raw) == AXUIElementGetTypeID() else { return nil } + current = unsafeBitCast(raw, to: AXUIElement.self) + if windowRoles.contains(attribute(current, kAXRoleAttribute) as? String ?? "") { return current } + } + return nil } func axActions(_ element: AXUIElement) -> [String] { var names: CFArray?