Skip to main content

capture_test/
capture_test.rs

1//! Test page capture: MHTML (full page) + HTML (DOM only).
2//!
3//! Run: CLAWSER_CHROME_PATH=out/Default/chrome.exe cargo run --manifest-path clawser-browser/Cargo.toml --example capture_test
4
5use clawser_browser::Browser;
6
7#[tokio::main]
8async fn main() {
9    let browser = Browser::builder()
10        .headful()
11        .random()
12        .build().await
13        .expect("failed to create browser");
14
15    let page = browser.navigate("https://www.youtube.com").await
16        .expect("navigate failed");
17
18    // Wait for page to fully load
19    tokio::time::sleep(std::time::Duration::from_secs(3)).await;
20
21    // 1. Capture full MHTML (HTML + JS + CSS + images)
22    println!("[1] Capturing MHTML...");
23    let mhtml = page.capture_mhtml().await.expect("mhtml failed");
24    std::fs::write("youtube.mhtml", &mhtml).expect("write failed");
25    println!("    Saved youtube.mhtml ({} bytes)", mhtml.len());
26
27    // 2. Capture HTML via DOM (scripts intact, no escaping issues)
28    println!("[2] Capturing HTML via DOM...");
29    let html = page.capture_html().await.expect("html failed");
30    std::fs::write("youtube.html", &html).expect("write failed");
31    println!("    Saved youtube.html ({} bytes)", html.len());
32
33    // Verify scripts are intact
34    let script_count = html.matches("<script").count();
35    println!("    <script> tags found: {}", script_count);
36
37    browser.shutdown().await.expect("shutdown failed");
38    println!("\nDone. Open youtube.mhtml in Chrome to verify.");
39}