eoka 0.13.0

Stealth browser automation for Rust. Puppeteer/Playwright alternative with anti-bot bypass.
Documentation
//! Launch a stealth browser and serve a loopback CDP endpoint for other
//! clients. Prints the WebSocket and HTTP URLs, then serves until stdin
//! closes or `--stop-file PATH` exists.
//!
//! cargo run --example cdp_proxy -- [--visible] [--chrome PATH]
//!     [--chrome-arg ARG]... [--pass-through | --ack-runtime-enable |
//!     --emulate-runtime] [--log path.jsonl] [--stop-file PATH]

use eoka::cdp::CdpProxyOptions;
use eoka::{Browser, Result};

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt()
        .with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
        .with_writer(std::io::stderr)
        .init();
    let args: Vec<String> = std::env::args().collect();
    let visible = args.iter().any(|a| a == "--visible");
    let log_path = args
        .iter()
        .position(|a| a == "--log")
        .and_then(|i| args.get(i + 1))
        .map(Into::into);
    let mut config = if visible {
        eoka::StealthConfig::visible()
    } else {
        eoka::StealthConfig::default()
    };
    config.chrome_path = args
        .iter()
        .position(|a| a == "--chrome")
        .and_then(|i| args.get(i + 1))
        .cloned();
    config.extra_args = args
        .iter()
        .enumerate()
        .filter(|(_, a)| *a == "--chrome-arg")
        .filter_map(|(i, _)| args.get(i + 1).cloned())
        .collect();
    let browser = Browser::launch_with_config(config).await?;
    let pass_through = args.iter().any(|a| a == "--pass-through");
    let runtime = if args.iter().any(|a| a == "--ack-runtime-enable") {
        eoka::cdp::RuntimeMode::Ack
    } else if args.iter().any(|a| a == "--emulate-runtime") {
        eoka::cdp::RuntimeMode::Emulate
    } else {
        eoka::cdp::RuntimeMode::Forward
    };
    let mut options = CdpProxyOptions::default();
    options.log_path = log_path;
    options.pass_through = pass_through;
    options.runtime = runtime;
    let proxy = browser.serve_cdp(options).await?;
    println!("{}", proxy.ws_url());
    println!("{}", proxy.http_url());
    match args
        .iter()
        .position(|a| a == "--stop-file")
        .and_then(|i| args.get(i + 1))
    {
        Some(stop) => {
            while !std::path::Path::new(stop).exists() {
                tokio::time::sleep(std::time::Duration::from_millis(200)).await;
            }
        }
        None => {
            let _ = tokio::task::spawn_blocking(|| {
                let mut sink = String::new();
                while std::io::stdin().read_line(&mut sink).is_ok_and(|n| n > 0) {}
            })
            .await;
        }
    }
    drop(proxy);
    browser.close().await
}