From 189053936482c548d7cb3ecd730e9d0dce6c3360 Mon Sep 17 00:00:00 2001 From: Contributor Date: Mon, 25 May 2026 10:24:45 +0800 Subject: [PATCH] fix(screenshot): apply maxImageDimension cap to match get_window_state Fixes #1592 (Bug 1). ScreenshotTool called captureWindow(windowID:format:quality:) without maxImageDimension, so it defaulted to 0 (no resize) and returned native Retina resolution (2x logical). GetWindowStateTool passes config.maxImageDimension and registers the resize ratio in ImageResizeRegistry so ClickTool can reverse it. An agent using screenshot to see the screen and click with those pixel coordinates would miss every target on a Retina display because the coordinate spaces were mismatched. Fix: load ConfigStore.shared and pass config.maxImageDimension to captureWindow, matching the get_window_state code path exactly. --- .../Sources/CuaDriverServer/Tools/ScreenshotTool.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/cua-driver/swift/Sources/CuaDriverServer/Tools/ScreenshotTool.swift b/libs/cua-driver/swift/Sources/CuaDriverServer/Tools/ScreenshotTool.swift index 0c43f48631..488f65698d 100644 --- a/libs/cua-driver/swift/Sources/CuaDriverServer/Tools/ScreenshotTool.swift +++ b/libs/cua-driver/swift/Sources/CuaDriverServer/Tools/ScreenshotTool.swift @@ -87,10 +87,17 @@ public enum ScreenshotTool { } do { + // Load config so we can apply the same maxImageDimension cap + // that get_window_state uses. Without this, screenshot returns + // native Retina resolution (2× logical) while click coordinates + // are calibrated against the downscaled image — causing every + // click to miss its target on Retina displays (issue #1592). + let config = await ConfigStore.shared.load() let shot = try await capture.captureWindow( windowID: windowID, format: format, - quality: quality + quality: quality, + maxImageDimension: config.maxImageDimension ) let base64 = shot.imageData.base64EncodedString() let mime = format == .png ? "image/png" : "image/jpeg"