stealth-oxide 0.1.2

Typed Chromiumoxide browser profiles and CDP emulation configuration
Documentation
use std::time::Instant;

use anyhow::{Result, bail};
use chromiumoxide::{Browser, BrowserConfig};
use futures::StreamExt;
use stealth_oxide::{PlatformProfile, StealthConfig};

const TARGET_URL: &str = "https://example.com";

#[tokio::main]
async fn main() -> Result<()> {
    let browser_config = BrowserConfig::builder()
        .hide()
        .build()
        .map_err(anyhow::Error::msg)?;

    let (mut browser, mut handler) = Browser::launch(browser_config).await?;
    tokio::spawn(async move {
        while let Some(event) = handler.next().await {
            if let Err(error) = event {
                eprintln!("chromiumoxide handler error: {error:?}");
            }
        }
    });

    let page = browser.new_page("about:blank").await?;
    let config = StealthConfig::for_platform(PlatformProfile::Linux);
    let plan = config.plan();
    println!("patch plan: {:?}", plan.operations());
    if !plan.issues().is_empty() {
        bail!("profile configuration is inconsistent: {:?}", plan.issues());
    }
    let report = config.apply(&page).await?;

    let navigation_started = Instant::now();
    page.goto(TARGET_URL).await?;
    let navigation_time = navigation_started.elapsed();

    let title = page.get_title().await?.unwrap_or_default();
    let content_size = page.content().await?.len();

    println!("page title: {title}");
    println!("content size: {content_size} bytes");
    println!("navigation time: {navigation_time:.2?}");
    println!("applied patches: {:?}", report.applied());
    println!("native patches: {:?}", report.native());
    println!("skipped patches: {:?}", report.skipped());
    browser.close().await?;
    Ok(())
}