Skip to content

The headless browser for AI agents and web scraping

Merge branch 'main' into fix-482-stealth-dump-original

Zed128d781207d04c8
diff --cc crates/obscura-cli/src/main.rs
index e3ae9734,21a2d965..f8bace80
--- a/crates/obscura-cli/src/main.rs
+++ b/crates/obscura-cli/src/main.rs
@@@ -384,18 -443,71 +443,72 @@@ async fn main() -> anyhow::Result<()>
),
}
let urls = read_urls_from_file(&file)?;
- run_batch_fetch(urls, concurrency.get(), timeout, user_agent, global_proxy, output, quiet, stealth).await?;
+ run_batch_fetch(
+ urls,
+ concurrency.get(),
+ timeout,
+ user_agent,
+ global_proxy,
+ output,
+ quiet,
++ stealth
+ )
+ .await?;
} else {
let url = url.ok_or_else(|| {
- anyhow::anyhow!("No URL provided. Pass a URL, or a list of URLs with --file <path>.")
+ anyhow::anyhow!(
+ "No URL provided. Pass a URL, or a list of URLs with --file <path>."
+ )
})?;
- run_fetch(&url, dump, selector, wait, timeout, &wait_until, user_agent, stealth, eval, output, quiet, global_proxy, storage_dir, args.allow_private_network).await?;
+ let wait_is_fixed = wait.is_some();
+ run_fetch(
+ &url,
+ dump,
+ selector,
+ wait.unwrap_or(5),
+ wait_is_fixed,
+ timeout,
+ &wait_until,
+ user_agent,
+ stealth,
+ eval,
+ output,
+ quiet,
+ global_proxy,
+ storage_dir,
+ args.allow_private_network,
+ screenshot,
+ )
+ .await?;
}
}
- Some(Command::Scrape { urls, eval, concurrency, format, timeout, quiet }) => {
- run_parallel_scrape(urls, eval, concurrency.get(), &format, timeout, quiet, global_proxy, stealth).await?;
+ Some(Command::Scrape {
+ urls,
+ eval,
+ concurrency,
+ format,
+ timeout,
+ quiet,
+ }) => {
+ run_parallel_scrape(
+ urls,
+ eval,
+ concurrency.get(),
+ &format,
+ timeout,
+ quiet,
+ global_proxy,
+ stealth,
+ )
+ .await?;
}
- Some(Command::Mcp { http, host, port, proxy, user_agent }) => {
+ Some(Command::Mcp {
+ http,
+ host,
+ port,
+ proxy,
+ user_agent,
+ }) => {
let mcp_proxy = merge_proxy(global_proxy.clone(), proxy);
if http {
obscura_mcp::http::run(host, port, mcp_proxy, user_agent, stealth).await?;
@@@ -750,9 -1102,12 +1134,13 @@@ async fn fetch_original_bytes
proxy: Option<String>,
user_agent: Option<String>,
timeout_secs: u64,
+ stealth: bool,
) -> anyhow::Result<Vec<u8>> {
- Ok(fetch_original_response(url_str, proxy, user_agent, timeout_secs, stealth).await?.body)
+ Ok(
- fetch_original_response(url_str, proxy, user_agent, timeout_secs)
++ fetch_original_response(url_str, proxy, user_agent, timeout_secs, stealth)
+ .await?
+ .body,
+ )
}
/// Read newline-delimited URLs from `path` (or stdin when `path` is `-`).
@@@ -1577,42 -2002,12 +2037,45 @@@ mod tests
let _ = tokio::fs::remove_file(&path).await;
- assert_eq!(bytes, PNG_BYTES, "raw response body must match the file byte-for-byte");
+ assert_eq!(
+ bytes, PNG_BYTES,
+ "raw response body must match the file byte-for-byte"
+ );
}
+ // A stealth-enabled build routes `--dump original` through
+ // StealthHttpClient (wreq), which only speaks http(s). file:// must keep
+ // working the same as without --stealth instead of being handed to wreq
+ // (issue #482).
+ #[tokio::test(flavor = "current_thread")]
+ async fn fetch_original_bytes_file_url_ignores_stealth_flag() {
+ const PNG_BYTES: &[u8] = &[
+ 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48,
+ 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00, 0x00,
+ 0x00, 0x1F, 0x15, 0xC4, 0x89, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x44, 0x41, 0x54, 0x78,
+ 0x9C, 0x63, 0x00, 0x01, 0x00, 0x00, 0x05, 0x00, 0x01, 0x0D, 0x0A, 0x2D, 0xB4, 0x00,
+ 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82,
+ ];
+
+ let path = std::env::temp_dir().join(format!(
+ "obscura-fetch-original-stealth-test-{}.png",
+ std::process::id()
+ ));
+ let _ = tokio::fs::remove_file(&path).await;
+ tokio::fs::write(&path, PNG_BYTES)
+ .await
+ .expect("seed temp PNG fixture");
+
+ let file_url = format!("file://{}", path.display());
+ let bytes = fetch_original_bytes(&file_url, None, None, 5, true)
+ .await
+ .expect("fetch_original_bytes should still round-trip file:// with stealth=true");
+
+ let _ = tokio::fs::remove_file(&path).await;
+
+ assert_eq!(bytes, PNG_BYTES, "stealth=true must not change file:// handling");
+ }
+
#[tokio::test(flavor = "current_thread")]
async fn write_or_print_bytes_writes_without_trailing_newline() {
// Regression guard for #117: stdout must receive raw bytes. The file