Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-driver): preserve cross-platform browser posture

trycua-release[bot]6ea780690388
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/download.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/download.rs
index ae33e93d3d..46871f5218 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/download.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/download.rs
@@ -127,6 +127,23 @@ fn validate_destination_root(raw: &str) -> Result<PathBuf, ToolResult> {
Ok(canonical)
}
+fn download_path_for_cdp(path: &Path) -> String {
+ let raw = path.to_string_lossy();
+ #[cfg(target_os = "windows")]
+ {
+ // `canonicalize` deliberately gives containment checks a verbatim
+ // Windows path. Chromium's download API does not accept that transport
+ // spelling, so remove only the namespace prefix after validation.
+ if let Some(unc) = raw.strip_prefix(r"\\?\UNC\") {
+ return format!(r"\\{unc}");
+ }
+ if let Some(local) = raw.strip_prefix(r"\\?\") {
+ return local.to_owned();
+ }
+ }
+ raw.into_owned()
+}
+
fn main_frame_id(frame_tree: &Value) -> Option<&str> {
frame_tree
.get("frameTree")?
@@ -403,7 +420,7 @@ impl Tool for BrowserDownloadTool {
"Browser.setDownloadBehavior",
json!({
"behavior": "allowAndName",
- "downloadPath": destination_root.to_string_lossy(),
+ "downloadPath": download_path_for_cdp(&destination_root),
"eventsEnabled": true
}),
)
@@ -554,4 +571,23 @@ mod tests {
remove_proven_partial(&canonical, Some("opaque-guid"));
assert!(!partial.exists());
}
+
+ #[test]
+ fn cdp_download_path_preserves_ordinary_paths() {
+ let path = Path::new("/tmp/approved-downloads");
+ assert_eq!(download_path_for_cdp(path), path.to_string_lossy());
+ }
+
+ #[cfg(target_os = "windows")]
+ #[test]
+ fn cdp_download_path_removes_only_windows_verbatim_prefixes() {
+ assert_eq!(
+ download_path_for_cdp(Path::new(r"\\?\C:\approved\downloads")),
+ r"C:\approved\downloads"
+ );
+ assert_eq!(
+ download_path_for_cdp(Path::new(r"\\?\UNC\server\share\downloads")),
+ r"\\server\share\downloads"
+ );
+ }
}
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/input/mod.rs b/libs/cua-driver/rust/crates/platform-linux/src/input/mod.rs
index 063923db88..1494da8fa2 100644
--- a/libs/cua-driver/rust/crates/platform-linux/src/input/mod.rs
+++ b/libs/cua-driver/rust/crates/platform-linux/src/input/mod.rs
@@ -930,7 +930,19 @@ pub fn x11_activate_window_persistent(xid: u64) -> Result<Option<u64>> {
prior.unwrap_or(0) as x11::xlib::Window,
);
unsafe {
+ // Some WMs honor `_NET_ACTIVE_WINDOW` as raise-only. Persistent
+ // activation must establish input focus too, just like the bounded
+ // foreground rung above, or `bring_to_front` can report success while
+ // keyboard focus remains on the previous window.
+ let previous_handler = x11::xlib::XSetErrorHandler(Some(ignore_x_error));
+ x11::xlib::XSetInputFocus(
+ display,
+ xid as x11::xlib::Window,
+ x11::xlib::RevertToParent,
+ x11::xlib::CurrentTime,
+ );
x11::xlib::XSync(display, 0);
+ x11::xlib::XSetErrorHandler(previous_handler);
x11::xlib::XCloseDisplay(display);
}
Ok(prior)