Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
649fa4ce94 | ||
|
|
3ac69e822a | ||
|
|
d7a0ed85f9 |
Generated
+1
-1
@@ -45,7 +45,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "agent-browser-stealth"
|
name = "agent-browser-stealth"
|
||||||
version = "0.27.0-fork.46"
|
version = "0.27.0-fork.47"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes-gcm",
|
"aes-gcm",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "agent-browser-stealth"
|
name = "agent-browser-stealth"
|
||||||
version = "0.27.0-fork.46"
|
version = "0.27.0-fork.47"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Fast browser automation CLI for AI agents"
|
description = "Fast browser automation CLI for AI agents"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|||||||
@@ -315,6 +315,13 @@ pub struct BrowserManager {
|
|||||||
/// browser after it ends. Only ever holds tabs we created — never the user's
|
/// browser after it ends. Only ever holds tabs we created — never the user's
|
||||||
/// existing tabs or other sessions' tabs — so closing them is always safe.
|
/// existing tabs or other sessions' tabs — so closing them is always safe.
|
||||||
created_targets: HashSet<String>,
|
created_targets: HashSet<String>,
|
||||||
|
/// The session's *intended* active tab, pinned by stable target_id rather
|
||||||
|
/// than the fragile `active_page_index`. Set on every explicit open / tab new
|
||||||
|
/// / tab switch. `active_session_id` resolves through this so a foreign tab
|
||||||
|
/// opening (passive discovery), a tab closing, or list reordering can't drift
|
||||||
|
/// the session's commands onto the wrong page — the wrong-origin-fetch hazard
|
||||||
|
/// in the dogfood reports. Falls back to the index if the pinned tab is gone.
|
||||||
|
active_target_id: Option<String>,
|
||||||
next_tab_id: u32,
|
next_tab_id: u32,
|
||||||
/// Whether to enable the CDP `Runtime` domain (console / error / exception capture).
|
/// Whether to enable the CDP `Runtime` domain (console / error / exception capture).
|
||||||
/// OFF by default for stealth: a live `Runtime.enable` is a detectable CDP signal
|
/// OFF by default for stealth: a live `Runtime.enable` is a detectable CDP signal
|
||||||
@@ -440,6 +447,7 @@ impl BrowserManager {
|
|||||||
ignore_https_errors,
|
ignore_https_errors,
|
||||||
visited_origins: HashSet::new(),
|
visited_origins: HashSet::new(),
|
||||||
created_targets: HashSet::new(),
|
created_targets: HashSet::new(),
|
||||||
|
active_target_id: None,
|
||||||
next_tab_id: 1,
|
next_tab_id: 1,
|
||||||
capture_console: console_capture_enabled(),
|
capture_console: console_capture_enabled(),
|
||||||
};
|
};
|
||||||
@@ -531,6 +539,7 @@ impl BrowserManager {
|
|||||||
ignore_https_errors: false,
|
ignore_https_errors: false,
|
||||||
visited_origins: HashSet::new(),
|
visited_origins: HashSet::new(),
|
||||||
created_targets: HashSet::new(),
|
created_targets: HashSet::new(),
|
||||||
|
active_target_id: None,
|
||||||
next_tab_id: 1,
|
next_tab_id: 1,
|
||||||
capture_console: console_capture_enabled(),
|
capture_console: console_capture_enabled(),
|
||||||
};
|
};
|
||||||
@@ -547,6 +556,7 @@ impl BrowserManager {
|
|||||||
target_type: "page".to_string(),
|
target_type: "page".to_string(),
|
||||||
});
|
});
|
||||||
manager.active_page_index = 0;
|
manager.active_page_index = 0;
|
||||||
|
manager.pin_active_target();
|
||||||
manager.enable_domains_direct().await?;
|
manager.enable_domains_direct().await?;
|
||||||
} else {
|
} else {
|
||||||
manager.discover_and_attach_targets().await?;
|
manager.discover_and_attach_targets().await?;
|
||||||
@@ -621,6 +631,7 @@ impl BrowserManager {
|
|||||||
target_type: "page".to_string(),
|
target_type: "page".to_string(),
|
||||||
});
|
});
|
||||||
self.active_page_index = 0;
|
self.active_page_index = 0;
|
||||||
|
self.pin_active_target();
|
||||||
self.enable_domains(&attach_result.session_id).await?;
|
self.enable_domains(&attach_result.session_id).await?;
|
||||||
} else {
|
} else {
|
||||||
for target in &page_targets {
|
for target in &page_targets {
|
||||||
@@ -650,6 +661,7 @@ impl BrowserManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.active_page_index = 0;
|
self.active_page_index = 0;
|
||||||
|
self.pin_active_target();
|
||||||
let session_id = self.pages[0].session_id.clone();
|
let session_id = self.pages[0].session_id.clone();
|
||||||
self.enable_domains(&session_id).await?;
|
self.enable_domains(&session_id).await?;
|
||||||
}
|
}
|
||||||
@@ -736,9 +748,31 @@ impl BrowserManager {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Index of the session's active page, resolved through the pinned
|
||||||
|
/// `active_target_id` (stable across reorder/removal/passive discovery) and
|
||||||
|
/// falling back to `active_page_index` when nothing is pinned or the pin is
|
||||||
|
/// gone. This is what keeps commands on the tab the agent actually opened.
|
||||||
|
fn resolved_active_index(&self) -> usize {
|
||||||
|
if let Some(tid) = &self.active_target_id {
|
||||||
|
if let Some(i) = self.pages.iter().position(|p| &p.target_id == tid) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.active_page_index
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pin the current active page by target_id so later commands stick to it.
|
||||||
|
/// Call after any explicit open / tab new / tab switch.
|
||||||
|
fn pin_active_target(&mut self) {
|
||||||
|
self.active_target_id = self
|
||||||
|
.pages
|
||||||
|
.get(self.active_page_index)
|
||||||
|
.map(|p| p.target_id.clone());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn active_session_id(&self) -> Result<&str, String> {
|
pub fn active_session_id(&self) -> Result<&str, String> {
|
||||||
self.pages
|
self.pages
|
||||||
.get(self.active_page_index)
|
.get(self.resolved_active_index())
|
||||||
.map(|p| p.session_id.as_str())
|
.map(|p| p.session_id.as_str())
|
||||||
.ok_or_else(|| "No active page".to_string())
|
.ok_or_else(|| "No active page".to_string())
|
||||||
}
|
}
|
||||||
@@ -991,7 +1025,7 @@ impl BrowserManager {
|
|||||||
|
|
||||||
pub fn active_target_id(&self) -> Result<&str, String> {
|
pub fn active_target_id(&self) -> Result<&str, String> {
|
||||||
self.pages
|
self.pages
|
||||||
.get(self.active_page_index)
|
.get(self.resolved_active_index())
|
||||||
.map(|p| p.target_id.as_str())
|
.map(|p| p.target_id.as_str())
|
||||||
.ok_or_else(|| "No active page".to_string())
|
.ok_or_else(|| "No active page".to_string())
|
||||||
}
|
}
|
||||||
@@ -1219,6 +1253,7 @@ impl BrowserManager {
|
|||||||
target_type: "page".to_string(),
|
target_type: "page".to_string(),
|
||||||
});
|
});
|
||||||
self.active_page_index = index;
|
self.active_page_index = index;
|
||||||
|
self.pin_active_target();
|
||||||
|
|
||||||
Ok(json!({
|
Ok(json!({
|
||||||
"tabId": format_tab_id(tab_id),
|
"tabId": format_tab_id(tab_id),
|
||||||
@@ -1238,6 +1273,7 @@ impl BrowserManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.active_page_index = index;
|
self.active_page_index = index;
|
||||||
|
self.pin_active_target();
|
||||||
let session_id = self.pages[index].session_id.clone();
|
let session_id = self.pages[index].session_id.clone();
|
||||||
self.enable_domains(&session_id).await?;
|
self.enable_domains(&session_id).await?;
|
||||||
|
|
||||||
@@ -1581,6 +1617,7 @@ impl BrowserManager {
|
|||||||
let index = self.pages.len();
|
let index = self.pages.len();
|
||||||
self.pages.push(page);
|
self.pages.push(page);
|
||||||
self.active_page_index = index;
|
self.active_page_index = index;
|
||||||
|
self.pin_active_target();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a passively-discovered page WITHOUT changing the active tab.
|
/// Add a passively-discovered page WITHOUT changing the active tab.
|
||||||
@@ -1783,6 +1820,7 @@ async fn initialize_lightpanda_manager(
|
|||||||
ignore_https_errors: false,
|
ignore_https_errors: false,
|
||||||
visited_origins: HashSet::new(),
|
visited_origins: HashSet::new(),
|
||||||
created_targets: HashSet::new(),
|
created_targets: HashSet::new(),
|
||||||
|
active_target_id: None,
|
||||||
next_tab_id: 1,
|
next_tab_id: 1,
|
||||||
capture_console: console_capture_enabled(),
|
capture_console: console_capture_enabled(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -556,8 +556,12 @@ async fn verify_ref_identity(
|
|||||||
Err(format!(
|
Err(format!(
|
||||||
"Ref {} no longer matches its snapshot. Was [{} \"{}\"], now [{} \"{}\"].\n\
|
"Ref {} no longer matches its snapshot. Was [{} \"{}\"], now [{} \"{}\"].\n\
|
||||||
The DOM mutated between snapshot and interaction (typical with React/Vue \
|
The DOM mutated between snapshot and interaction (typical with React/Vue \
|
||||||
reusing nodes during re-render). Take a fresh snapshot, then re-target.\n\
|
reusing nodes during re-render). Fix: take a fresh `snapshot` and re-target \
|
||||||
To bypass this guard set AGENT_BROWSER_VERIFY_REF=0.",
|
with the new ref. For SPAs where refs churn every interaction, drive the \
|
||||||
|
element directly with `eval` (e.g. `eval \"document.querySelector(...).click()\"`), \
|
||||||
|
which doesn't depend on refs.\n\
|
||||||
|
(Last resort: AGENT_BROWSER_VERIFY_REF=0 disables this safety check — only \
|
||||||
|
if you accept clicks may land on a re-rendered/wrong node.)",
|
||||||
ref_id, expected_role, expected_name, actual_role, actual_name,
|
ref_id, expected_role, expected_name, actual_role, actual_name,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1305,6 +1305,39 @@ fn render_tree(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// True if a snapshot line names an interactive ARIA role. Compaction keeps
|
||||||
|
/// these even without a `ref=`/`": "` marker, so a clickable control never gets
|
||||||
|
/// dropped from `-c` output (the dogfood reports saw a button present in the full
|
||||||
|
/// snapshot vanish from compact, leaving the agent clicking an empty ref).
|
||||||
|
fn is_interactive_line(line: &str) -> bool {
|
||||||
|
const ROLES: &[&str] = &[
|
||||||
|
"button",
|
||||||
|
"link",
|
||||||
|
"textbox",
|
||||||
|
"checkbox",
|
||||||
|
"radio",
|
||||||
|
"combobox",
|
||||||
|
"listbox",
|
||||||
|
"menuitem",
|
||||||
|
"menuitemcheckbox",
|
||||||
|
"menuitemradio",
|
||||||
|
"option",
|
||||||
|
"switch",
|
||||||
|
"slider",
|
||||||
|
"spinbutton",
|
||||||
|
"searchbox",
|
||||||
|
"tab ",
|
||||||
|
"clickable",
|
||||||
|
"focusable",
|
||||||
|
"editable",
|
||||||
|
];
|
||||||
|
let t = line.trim_start();
|
||||||
|
// Lines look like `- button "Label" [ref=e1]`; match the role token after the
|
||||||
|
// leading "- " marker.
|
||||||
|
let t = t.strip_prefix("- ").unwrap_or(t);
|
||||||
|
ROLES.iter().any(|r| t.starts_with(r))
|
||||||
|
}
|
||||||
|
|
||||||
fn compact_tree(tree: &str, interactive: bool) -> String {
|
fn compact_tree(tree: &str, interactive: bool) -> String {
|
||||||
let lines: Vec<&str> = tree.lines().collect();
|
let lines: Vec<&str> = tree.lines().collect();
|
||||||
if lines.is_empty() {
|
if lines.is_empty() {
|
||||||
@@ -1314,7 +1347,7 @@ fn compact_tree(tree: &str, interactive: bool) -> String {
|
|||||||
let mut keep = vec![false; lines.len()];
|
let mut keep = vec![false; lines.len()];
|
||||||
|
|
||||||
for (i, line) in lines.iter().enumerate() {
|
for (i, line) in lines.iter().enumerate() {
|
||||||
if line.contains("ref=") || line.contains(": ") {
|
if line.contains("ref=") || line.contains(": ") || is_interactive_line(line) {
|
||||||
keep[i] = true;
|
keep[i] = true;
|
||||||
// Mark ancestors
|
// Mark ancestors
|
||||||
let my_indent = count_indent(line);
|
let my_indent = count_indent(line);
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "agent-browser-stealth",
|
"name": "agent-browser-stealth",
|
||||||
"version": "0.27.0-fork.46",
|
"version": "0.27.0-fork.47",
|
||||||
"description": "Browser automation CLI for AI agents — stealth fork with anti-detection",
|
"description": "Browser automation CLI for AI agents — stealth fork with anti-detection",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"packageManager": "pnpm@11.1.3",
|
"packageManager": "pnpm@11.1.3",
|
||||||
|
|||||||
Reference in New Issue
Block a user