Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Report unreachable sites as navigation errors, not browser failures

Oleksandr Ivanchenko361e53656665
diff --git a/src/sandbox/browser.rs b/src/sandbox/browser.rs
index 61517c88..d0a5acea 100644
--- a/src/sandbox/browser.rs
+++ b/src/sandbox/browser.rs
@@ -97,6 +97,9 @@ pub enum BrowserError {
Timeout,
#[error("Browser is controlled by a person. Retry after control is returned.")]
HumanControl,
+ /// The browser works, but the page itself could not be loaded (DNS, TLS, refused, ...).
+ #[error("Page could not be loaded: {0}")]
+ Navigation(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -578,7 +581,11 @@ impl BrowserController {
.send_cdp_command("Page.navigate", json!({ "url": target_url }))
.await?;
if let Some(error) = res["errorText"].as_str() {
- return Err(BrowserError::Protocol(format!("Navigation failed: {}", error)));
+ // Chrome shows its own error page; reflect it in the viewer
+ tokio::time::sleep(Duration::from_millis(200)).await;
+ let _ = self.sync_location().await;
+ let _ = self.capture_screenshot().await;
+ return Err(BrowserError::Navigation(error.to_string()));
}
*self.last_screenshot.lock().await = None;
diff --git a/src/server/routes.rs b/src/server/routes.rs
index f8f8f7ba..329d907e 100644
--- a/src/server/routes.rs
+++ b/src/server/routes.rs
@@ -307,7 +307,8 @@ fn execute_single_turn(
target_url
)));
if let Some(ctrl) = get_or_create_browser_controller(&state, &sandbox_target).await {
- if let Ok(nav) = ctrl.navigate(&target_url).await {
+ match ctrl.navigate(&target_url).await {
+ Ok(nav) => {
let page_text = ctrl.extract_content().await.unwrap_or_default();
let preview = truncate_chars(&page_text, 3000);
let _ = event_broadcast.send(RuntimeEvent::BrowserNavigated {
@@ -330,6 +331,23 @@ fn execute_single_turn(
prompt, target_url, nav.title, clickable.join(" | "), preview
);
}
+ Err(crate::sandbox::BrowserError::Navigation(reason)) => {
+ let shown_url = ctrl.current_url.lock().await.clone().unwrap_or_else(|| target_url.clone());
+ if let Some(b64) = ctrl.last_screenshot.lock().await.clone() {
+ let _ = event_broadcast.send(RuntimeEvent::BrowserScreenshot {
+ team_id: sandbox_target.clone(),
+ url: shown_url,
+ image_base64: b64,
+ timestamp: chrono::Utc::now().to_rfc3339(),
+ });
+ }
+ final_prompt = format!(
+ "{}\n\n[Sandbox Browser State: Tried to open {} in the right-panel bot browser, but the site could not be reached ({}). The browser itself works fine; do not retry or suggest restarting it. Briefly tell the user the address didn't resolve/load and, if it looks like a typo, suggest the likely intended address.]",
+ prompt, target_url, reason
+ );
+ }
+ Err(_) => {}
+ }
}
} else if let Some(ref curr_url) = active_browser_url {
if !curr_url.is_empty() && !curr_url.contains("about:blank") && !curr_url.contains("example.com") {
@@ -1480,6 +1498,11 @@ fn browser_unavailable() -> (StatusCode, Json<serde_json::Value>) {
fn browser_request_failed(error: crate::sandbox::BrowserError) -> (StatusCode, Json<serde_json::Value>) {
if matches!(error, crate::sandbox::BrowserError::HumanControl) { return (StatusCode::CONFLICT, Json(json!({"error": error.to_string()}))); }
+ if let crate::sandbox::BrowserError::Navigation(reason) = &error {
+ return (StatusCode::UNPROCESSABLE_ENTITY, Json(json!({
+ "error": format!("The site could not be reached ({}). The browser is working; check the address.", reason)
+ })));
+ }
tracing::warn!("Sandbox browser request failed: {}", error);
(StatusCode::BAD_GATEWAY, Json(json!({
"error": "The sandbox browser did not respond. Restart the browser and try again."