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): refresh the semantic page title after navigation (#4261)

Francesco Bonacci9d2456213f64
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/engine.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/engine.rs
index 73bdd663e4..5daa967c8e 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/engine.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/engine.rs
@@ -2558,10 +2558,11 @@ impl BrowserEngine {
OopifStatus::Unsupported
};
let next_offset = page.next_offset;
+ let title = document.document_title().unwrap_or(&tab.title).to_owned();
let (outcome, new_refs) = self.semantic_outcome(
snapshot.id,
snapshot.url.clone(),
- tab.title,
+ title,
page,
document.complete,
"continuation",
@@ -2630,6 +2631,7 @@ impl BrowserEngine {
.collect_semantic_session(&conn, &cdp_session, &document, local_tree.as_ref(), None)
.await?;
semantic.complete &= document_complete;
+ let title = semantic.document_title().unwrap_or(&tab.title).to_owned();
let oopif = if local_tree.is_some() {
match self.attached_iframe_children(&conn, &cdp_session).await {
@@ -2725,7 +2727,7 @@ impl BrowserEngine {
let (outcome, refs) = self.semantic_outcome(
snapshot_id,
url.clone(),
- tab.title.clone(),
+ title.clone(),
page,
semantic.complete,
scope,
@@ -2736,6 +2738,8 @@ impl BrowserEngine {
self.store
.update_target(session, target_id, |stored_target| {
if let Some(stored_tab) = stored_target.tabs.get_mut(tab_id) {
+ stored_tab.url = url.clone();
+ stored_tab.title = title;
let mut continuations = HashMap::new();
if let (Some(token), Some(offset)) = (continuation_token, next_offset) {
continuations.insert(
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/semantic.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/semantic.rs
index 63ee10a560..dc7cecebcf 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/semantic.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/semantic.rs
@@ -170,6 +170,13 @@ pub(crate) struct SemanticDocument {
}
impl SemanticDocument {
+ pub(crate) fn document_title(&self) -> Option<&str> {
+ self.nodes
+ .iter()
+ .find(|node| matches!(node.role.as_str(), "rootwebarea" | "webarea"))
+ .and_then(|node| node.name.as_deref())
+ }
+
pub(crate) fn extend(&mut self, mut other: Self) {
let was_empty = self.nodes.is_empty();
let offset = self.nodes.len();
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/v2_tests.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/v2_tests.rs
index 2b82930cdc..ce67c41534 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/v2_tests.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/v2_tests.rs
@@ -1445,6 +1445,16 @@ async fn snapshot_composes_shadow_iframe_and_oopif_refs() {
);
}
+#[tokio::test]
+async fn semantic_snapshot_refreshes_bind_time_title_from_main_document() {
+ let f = fixture_with(|st| st.semantic_large_page = true).await;
+ let (target, tab) = bind(&f).await;
+ let snap = semantic_snapshot(&f, &target, &tab).await;
+
+ assert_eq!(snap["status"], "ok", "{snap}");
+ assert_eq!(snap["page"]["title"], "Fixture inbox", "{snap}");
+}
+
#[tokio::test]
async fn semantic_snapshot_keeps_visible_content_after_hidden_node_pressure() {
let f = fixture_with(|st| st.semantic_large_page = true).await;
@@ -1639,6 +1649,7 @@ async fn semantic_continuation_is_opaque_single_use_and_reaches_offscreen_conten
let continued = semantic_snapshot_with(&f, &target, &tab, json!({"continuation": token})).await;
assert_eq!(continued["status"], "ok", "{continued}");
assert_eq!(continued["snapshot"]["scope"], "continuation");
+ assert_eq!(continued["page"]["title"], "Fixture inbox", "{continued}");
assert!(
continued["refs"]
.as_array()