use std::time::Duration;
use zendriver::Browser;
#[tokio::main]
#[allow(clippy::result_large_err)] async fn main() -> zendriver::Result<()> {
tracing_subscriber::fmt::init();
let proxy = std::env::var("ZD_PROXY")
.expect("Set ZD_PROXY=http://user:pass@host:port (rotating proxy recommended)");
let browser = Browser::builder().headless(true).launch().await?;
let ctx1 = browser
.browser_context()
.proxy(&proxy)
.proxy_bypass("<-loopback>")
.build()
.await?;
let tab1 = ctx1.new_tab().await?;
tab1.goto("https://ipv4.webshare.io/").await?;
tab1.wait_for_load().await?;
tokio::time::sleep(Duration::from_secs(1)).await;
let ip1: String = tab1.evaluate("document.body.textContent.trim()").await?;
println!("context 1 exit IP = {ip1}");
let ctx2 = browser
.browser_context()
.proxy(&proxy)
.proxy_bypass("<-loopback>")
.build()
.await?;
let tab2 = ctx2.new_tab().await?;
tab2.goto("https://ipv4.webshare.io/").await?;
tab2.wait_for_load().await?;
tokio::time::sleep(Duration::from_secs(1)).await;
let ip2: String = tab2.evaluate("document.body.textContent.trim()").await?;
println!("context 2 exit IP = {ip2}");
if ip1 == ip2 {
eprintln!(
"WARNING: both contexts returned the same IP. Rotation may not be working, OR \
the upstream gave the same exit twice in a row. Re-run a few times to confirm."
);
} else {
println!("OK: contexts have isolated proxies (rotation observed).");
}
drop(ctx1);
drop(ctx2);
tokio::time::sleep(Duration::from_millis(500)).await;
browser.close().await?;
Ok(())
}