Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c26afbaba6 | ||
|
|
ffb386e3af | ||
|
|
947d150561 | ||
|
|
06a29251a2 | ||
|
|
0eacec9b9f |
Generated
+1
-1
@@ -45,7 +45,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "agent-browser-stealth"
|
name = "agent-browser-stealth"
|
||||||
version = "0.27.0-fork.6"
|
version = "0.27.0-fork.8"
|
||||||
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.6"
|
version = "0.27.0-fork.8"
|
||||||
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"
|
||||||
|
|||||||
@@ -201,6 +201,31 @@ pub async fn resolve_element_center(
|
|||||||
|
|
||||||
if let Ok(r) = result {
|
if let Ok(r) = result {
|
||||||
let (x, y) = box_model_center(&r.model);
|
let (x, y) = box_model_center(&r.model);
|
||||||
|
// Occlusion check: a transient overlay (X.com's "click
|
||||||
|
// outside to close" mask, modal backdrop, sticky banner,
|
||||||
|
// etc.) can land on top of our target between snapshot
|
||||||
|
// and click. Coordinates are correct, but
|
||||||
|
// `document.elementFromPoint(x, y)` returns the overlay
|
||||||
|
// — and the click goes to the overlay's handler, not
|
||||||
|
// ours. Catch it here so the user gets "occluded by
|
||||||
|
// DIV[testid=mask]" instead of "modal silently closed +
|
||||||
|
// thread submitted by accident".
|
||||||
|
//
|
||||||
|
// Set AGENT_BROWSER_VERIFY_CLICK_TARGET=0 to skip.
|
||||||
|
if std::env::var("AGENT_BROWSER_VERIFY_CLICK_TARGET").as_deref() != Ok("0") {
|
||||||
|
if let Err(e) = verify_click_target(
|
||||||
|
client,
|
||||||
|
effective_session_id,
|
||||||
|
backend_node_id,
|
||||||
|
&ref_id,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
return Ok((x, y, effective_session_id.to_string()));
|
return Ok((x, y, effective_session_id.to_string()));
|
||||||
}
|
}
|
||||||
// backend_node_id is stale; re-query the accessibility tree below
|
// backend_node_id is stale; re-query the accessibility tree below
|
||||||
@@ -440,6 +465,168 @@ async fn verify_ref_identity(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// At the moment we'd dispatch the click, ask the page itself which element
|
||||||
|
/// occupies (x, y). If it's not our target (and not a descendant or
|
||||||
|
/// ancestor), an overlay has appeared between snapshot and click — we'd
|
||||||
|
/// silently click the overlay otherwise. Returns Err with details about
|
||||||
|
/// the occluding element so the caller can wait + re-snapshot.
|
||||||
|
///
|
||||||
|
/// Implemented as a single Runtime.callFunctionOn: resolve the cached
|
||||||
|
/// backendNodeId to a remote object, then run a function on it that
|
||||||
|
/// compares with elementFromPoint. The function returns null when the
|
||||||
|
/// click is safe and a JSON string with diagnostic info when it isn't.
|
||||||
|
async fn verify_click_target(
|
||||||
|
client: &CdpClient,
|
||||||
|
session_id: &str,
|
||||||
|
backend_node_id: i64,
|
||||||
|
ref_id: &str,
|
||||||
|
x: f64,
|
||||||
|
y: f64,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
// Resolve once. backendNodeId is stable across renders; only the
|
||||||
|
// element under (x, y) is what changes when an overlay flickers.
|
||||||
|
let resolve_params = DomResolveNodeParams {
|
||||||
|
backend_node_id: Some(backend_node_id),
|
||||||
|
node_id: None,
|
||||||
|
object_group: Some("agent-browser-occlusion".to_string()),
|
||||||
|
};
|
||||||
|
let resolve_fut = client.send_command_typed::<_, serde_json::Value>(
|
||||||
|
"DOM.resolveNode",
|
||||||
|
&resolve_params,
|
||||||
|
Some(session_id),
|
||||||
|
);
|
||||||
|
let Ok(resolve_resp) =
|
||||||
|
tokio::time::timeout(std::time::Duration::from_millis(500), resolve_fut).await
|
||||||
|
else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
let Ok(resolved) = resolve_resp else { return Ok(()) };
|
||||||
|
let Some(object_id) = resolved
|
||||||
|
.get("object")
|
||||||
|
.and_then(|o| o.get("objectId"))
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
|
// Auto-retry on transient occlusion. Many real-world overlays
|
||||||
|
// (modal backdrops, focus rings, click-outside masks) blink in for
|
||||||
|
// a frame or two during state transitions and clear on their own.
|
||||||
|
// Without retries the user gets an "occluded" error and has to
|
||||||
|
// wrap every click in their own retry loop. With retries the
|
||||||
|
// common case is invisible — only persistent overlays surface.
|
||||||
|
//
|
||||||
|
// AGENT_BROWSER_OCCLUSION_RETRIES (default 3, 0 disables)
|
||||||
|
// AGENT_BROWSER_OCCLUSION_RETRY_DELAY_MS (default 200)
|
||||||
|
let max_retries: u32 = std::env::var("AGENT_BROWSER_OCCLUSION_RETRIES")
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.parse().ok())
|
||||||
|
.unwrap_or(3);
|
||||||
|
let retry_delay_ms: u64 = std::env::var("AGENT_BROWSER_OCCLUSION_RETRY_DELAY_MS")
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.parse().ok())
|
||||||
|
.unwrap_or(200);
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Occluder {
|
||||||
|
tag: Option<String>,
|
||||||
|
testid: Option<String>,
|
||||||
|
role: Option<String>,
|
||||||
|
#[serde(rename = "ariaLabel")]
|
||||||
|
aria_label: Option<String>,
|
||||||
|
text: Option<String>,
|
||||||
|
reason: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// function(x, y) { ... } where `this` is the target element.
|
||||||
|
// Return null → click is safe.
|
||||||
|
// Return JSON → describes the occluding element.
|
||||||
|
let function_decl = "function(x, y) { \
|
||||||
|
const at = document.elementFromPoint(x, y); \
|
||||||
|
if (!at) return JSON.stringify({reason:'no-element-at-point'}); \
|
||||||
|
if (at === this || this.contains(at) || at.contains(this)) return null; \
|
||||||
|
return JSON.stringify({ \
|
||||||
|
tag: at.tagName, \
|
||||||
|
testid: (at.dataset && at.dataset.testid) || null, \
|
||||||
|
role: at.getAttribute('role'), \
|
||||||
|
ariaLabel: at.getAttribute('aria-label'), \
|
||||||
|
text: ((at.textContent||'').trim().slice(0, 60)) \
|
||||||
|
}); \
|
||||||
|
}";
|
||||||
|
|
||||||
|
let mut last_occ: Option<Occluder> = None;
|
||||||
|
for attempt in 0..=max_retries {
|
||||||
|
if attempt > 0 {
|
||||||
|
tokio::time::sleep(std::time::Duration::from_millis(retry_delay_ms)).await;
|
||||||
|
}
|
||||||
|
let call_params = serde_json::json!({
|
||||||
|
"objectId": object_id,
|
||||||
|
"functionDeclaration": function_decl,
|
||||||
|
"arguments": [{"value": x}, {"value": y}],
|
||||||
|
"returnByValue": true,
|
||||||
|
});
|
||||||
|
let call_fut = client.send_command_typed::<_, serde_json::Value>(
|
||||||
|
"Runtime.callFunctionOn",
|
||||||
|
&call_params,
|
||||||
|
Some(session_id),
|
||||||
|
);
|
||||||
|
let Ok(call_resp) =
|
||||||
|
tokio::time::timeout(std::time::Duration::from_millis(500), call_fut).await
|
||||||
|
else {
|
||||||
|
return Ok(()); // probe itself stalled — fall through to click
|
||||||
|
};
|
||||||
|
let Ok(call_result) = call_resp else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
let value = call_result.get("result").and_then(|r| r.get("value"));
|
||||||
|
let json_str = match value {
|
||||||
|
Some(serde_json::Value::String(s)) => s.clone(),
|
||||||
|
// null / undefined → element at point IS our target. Safe.
|
||||||
|
_ => return Ok(()),
|
||||||
|
};
|
||||||
|
let occ: Occluder = match serde_json::from_str(&json_str) {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(_) => return Ok(()),
|
||||||
|
};
|
||||||
|
last_occ = Some(occ);
|
||||||
|
}
|
||||||
|
|
||||||
|
// All retries exhausted — overlay is sticky. Build the descriptive error.
|
||||||
|
let occ = last_occ.expect("loop ran at least once");
|
||||||
|
if let Some(reason) = occ.reason {
|
||||||
|
return Err(format!(
|
||||||
|
"Ref {} cannot be clicked at its computed position: {}. \
|
||||||
|
The element may have moved off-screen — re-run snapshot.",
|
||||||
|
ref_id, reason
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let mut desc = occ.tag.unwrap_or_else(|| "unknown".to_string());
|
||||||
|
if let Some(t) = occ.testid {
|
||||||
|
desc.push_str(&format!("[testid={}]", t));
|
||||||
|
}
|
||||||
|
if let Some(r) = occ.role {
|
||||||
|
desc.push_str(&format!("[role={}]", r));
|
||||||
|
}
|
||||||
|
if let Some(a) = occ.aria_label {
|
||||||
|
desc.push_str(&format!("[aria-label=\"{}\"]", a));
|
||||||
|
}
|
||||||
|
if let Some(t) = occ.text {
|
||||||
|
if !t.is_empty() {
|
||||||
|
desc.push_str(&format!(" text=\"{}\"", t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let waited_ms = (max_retries as u64) * retry_delay_ms;
|
||||||
|
Err(format!(
|
||||||
|
"Ref {} is occluded by {} at the click point (still occluded after \
|
||||||
|
{} retries / {}ms). A persistent overlay is in the way — \
|
||||||
|
re-run snapshot, dismiss the overlay, or set \
|
||||||
|
AGENT_BROWSER_VERIFY_CLICK_TARGET=0 to bypass.",
|
||||||
|
ref_id, desc, max_retries, waited_ms,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
/// Re-query the accessibility tree to find a node matching role+name+nth,
|
/// Re-query the accessibility tree to find a node matching role+name+nth,
|
||||||
/// returning its fresh backendDOMNodeId. This uses the same data source
|
/// returning its fresh backendDOMNodeId. This uses the same data source
|
||||||
/// (Accessibility.getFullAXTree) that built the ref map during snapshot,
|
/// (Accessibility.getFullAXTree) that built the ref map during snapshot,
|
||||||
|
|||||||
+18
-13
@@ -20,10 +20,10 @@ services:
|
|||||||
|
|
||||||
# Build both targets in parallel
|
# Build both targets in parallel
|
||||||
(echo "→ Linux x64" && cargo zigbuild --release --target x86_64-unknown-linux-gnu && cp /build/target/x86_64-unknown-linux-gnu/release/agent-browser /output/agent-browser-linux-x64 && chmod +x /output/agent-browser-linux-x64 && echo "✓ Linux x64 done") &
|
(echo "→ Linux x64" && cargo zigbuild --release --target x86_64-unknown-linux-gnu && cp /build/target/x86_64-unknown-linux-gnu/release/agent-browser /output/agent-browser-linux-x64 && chmod +x /output/agent-browser-linux-x64 && echo "✓ Linux x64 done") &
|
||||||
PID1=$!
|
PID1=$$!
|
||||||
|
|
||||||
(echo "→ Linux ARM64" && cargo zigbuild --release --target aarch64-unknown-linux-gnu && cp /build/target/aarch64-unknown-linux-gnu/release/agent-browser /output/agent-browser-linux-arm64 && chmod +x /output/agent-browser-linux-arm64 && echo "✓ Linux ARM64 done") &
|
(echo "→ Linux ARM64" && cargo zigbuild --release --target aarch64-unknown-linux-gnu && cp /build/target/aarch64-unknown-linux-gnu/release/agent-browser /output/agent-browser-linux-arm64 && chmod +x /output/agent-browser-linux-arm64 && echo "✓ Linux ARM64 done") &
|
||||||
PID2=$!
|
PID2=$$!
|
||||||
|
|
||||||
# Wait for both and check exit codes individually — without this
|
# Wait for both and check exit codes individually — without this
|
||||||
# the outer script exits 0 even if one of the parallel builds
|
# the outer script exits 0 even if one of the parallel builds
|
||||||
@@ -31,8 +31,8 @@ services:
|
|||||||
# previous release. Caused 0.27.0-fork.5 to ship with a stale
|
# previous release. Caused 0.27.0-fork.5 to ship with a stale
|
||||||
# linux-x64 binary at the first publish attempt until caught
|
# linux-x64 binary at the first publish attempt until caught
|
||||||
# manually by checking the embedded version string.
|
# manually by checking the embedded version string.
|
||||||
wait $PID1 || { echo "✗ Linux x64 build failed"; exit 1; }
|
wait $$PID1 || { echo "✗ Linux x64 build failed"; exit 1; }
|
||||||
wait $PID2 || { echo "✗ Linux ARM64 build failed"; exit 1; }
|
wait $$PID2 || { echo "✗ Linux ARM64 build failed"; exit 1; }
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "✓ Linux platforms built successfully!"
|
echo "✓ Linux platforms built successfully!"
|
||||||
@@ -71,16 +71,21 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- TARGET=${TARGET:-x86_64-unknown-linux-gnu}
|
- TARGET=${TARGET:-x86_64-unknown-linux-gnu}
|
||||||
- OUTPUT_NAME=${OUTPUT_NAME:-agent-browser-linux-x64}
|
- OUTPUT_NAME=${OUTPUT_NAME:-agent-browser-linux-x64}
|
||||||
|
# NOTE: $$ escapes a literal $ for the in-container shell. A single $ is
|
||||||
|
# interpolated by docker compose at YAML parse time against the *host*
|
||||||
|
# environment, which silently drops script-local variables like SRC
|
||||||
|
# (caused 0.27.0-fork.7 to ship with a stale linux-arm64 binary because
|
||||||
|
# the cp command resolved to `cp "" "/output/"` after compose ate $SRC
|
||||||
|
# and $OUTPUT_NAME). $TARGET / $OUTPUT_NAME are set via `environment:`
|
||||||
|
# below — those are also passed into the container, so $$TARGET and
|
||||||
|
# $$OUTPUT_NAME read them at script time.
|
||||||
command: |
|
command: |
|
||||||
-c '
|
-c '
|
||||||
set -e
|
set -e
|
||||||
cargo zigbuild --release --target $TARGET
|
cargo zigbuild --release --target $$TARGET
|
||||||
# Copy the binary explicitly. The previous `agent-browser*` glob
|
SRC="/build/target/$$TARGET/release/agent-browser"
|
||||||
# matched the binary AND its `.d` dependency file, which made cp
|
if [ -f "$$SRC.exe" ]; then SRC="$$SRC.exe"; fi
|
||||||
# treat the destination as a directory and silently failed.
|
cp "$$SRC" "/output/$$OUTPUT_NAME"
|
||||||
SRC="/build/target/$TARGET/release/agent-browser"
|
chmod +x /output/$$OUTPUT_NAME 2>/dev/null || true
|
||||||
if [ -f "$SRC.exe" ]; then SRC="$SRC.exe"; fi
|
echo "✓ Built $$OUTPUT_NAME"
|
||||||
cp "$SRC" "/output/$OUTPUT_NAME"
|
|
||||||
chmod +x /output/$OUTPUT_NAME 2>/dev/null || true
|
|
||||||
echo "✓ Built $OUTPUT_NAME"
|
|
||||||
'
|
'
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "agent-browser-stealth",
|
"name": "agent-browser-stealth",
|
||||||
"version": "0.27.0-fork.6",
|
"version": "0.27.0-fork.8",
|
||||||
"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",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
Reference in New Issue
Block a user