use std::time::Duration;
use zendriver::stealth::StealthProfile;
use zendriver::{Browser, ImpervaClearanceOutcome, ImpervaError};
#[tokio::main]
#[allow(clippy::result_large_err)]
async fn main() -> zendriver::Result<()> {
tracing_subscriber::fmt::init();
let url = std::env::var("IMPERVA_DEMO_URL")
.unwrap_or_else(|_| "https://example.com/imperva-protected".into());
let browser = Browser::builder()
.stealth(StealthProfile::spoofed())
.headless(true)
.launch()
.await?;
let tab = browser.main_tab();
tab.goto(&url).await?;
tab.wait_for_load().await?;
match tab
.imperva()
.timeout(Duration::from_secs(60))
.wait_for_clearance()
.await
{
Ok(ImpervaClearanceOutcome::TimedOut { last_surface }) => {
println!("clearance timed out; last_surface = {last_surface:?}");
}
Ok(outcome) => println!("cleared: {outcome:?}"),
Err(ImpervaError::CaptchaRequired { kind }) => {
println!("captcha required ({kind:?}); register .on_captcha(...) to solve");
}
Err(e) => return Err(e.into()),
}
let title = tab.title().await?;
println!("title = {title:?}");
browser.close().await?;
Ok(())
}