The headless browser for AI agents and web scraping
Keep blocked requests without a fabricated HTTP status
vvinayakkkafb0d613ec22
diff --git a/crates/obscura-cli/src/worker.rs b/crates/obscura-cli/src/worker.rsindex ab2c0ab0..6c2ef608 100644--- a/crates/obscura-cli/src/worker.rs+++ b/crates/obscura-cli/src/worker.rs@@ -102,10 +102,12 @@ async fn main() {// Navigation clears the event list and records the main// Document response before scripts and child frames.// Its status is the final response after HTTP redirects.+ // Zero denotes a blocked request, not an HTTP response.let status = page.network_events.iter().find(|event| event.resource_type == "Document").filter(|event| {- event.url.starts_with("http://") || event.url.starts_with("https://")+ event.status != 0+ && (event.url.starts_with("http://") || event.url.starts_with("https://"))}).map(|event| event.status);WorkerResponse::success(serde_json::json!({diff --git a/crates/obscura-cli/tests/worker_navigation_status.rs b/crates/obscura-cli/tests/worker_navigation_status.rsindex 5f7eed86..29cbbc29 100644--- a/crates/obscura-cli/tests/worker_navigation_status.rs+++ b/crates/obscura-cli/tests/worker_navigation_status.rs@@ -304,3 +304,16 @@ fn stealth_transport_reports_http_status_and_recovers_after_failure() {assert_eq!(worker.navigate(&server.url("/ok"))["status"], 200);assert_eq!(worker.navigate("about:blank")["status"], Value::Null);}++#[test]+fn blocked_document_has_no_fabricated_http_status() {+ // The blocklist short-circuits before DNS or HTTP, so this stays offline.+ assert!(obscura_net::blocklist::is_blocked("google-analytics.com"));+ let mut worker = Worker::with_stealth(true);+ let result = worker.navigate("https://google-analytics.com/worker-status-test");+ assert!(+ result.as_object().unwrap().contains_key("status"),+ "{result}"+ );+ assert_eq!(result["status"], Value::Null, "{result}");+}diff --git a/docs/CLI-reference.md b/docs/CLI-reference.mdindex 004c5916..49285755 100644--- a/docs/CLI-reference.md+++ b/docs/CLI-reference.md@@ -148,7 +148,8 @@ existing title and URL:script, image, or child frame's response. HTTP errors such as 404 and 503 stillreturn `ok: true`: the server responded and the error document can be inspectedwith `dump_html`, `dump_text`, or `evaluate`. Navigation without an HTTP response,-such as `about:blank` or a `data:` URL, returns `status: null`. A transport or+such as `about:blank`, a `data:` URL, or a tracker blocked before the request,+returns `status: null`. A transport ornavigation failure retains the existing `{"ok":false,"error":"..."}` envelopewithout a `result` object.