1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
//! Save a screenshot to disk. //! //! ```text //! CF_ACCOUNT_ID=... CF_API_TOKEN=... \ //! cargo run --example screenshot -- https://example.com ./out //! ``` use std::path::PathBuf; use flarer::{Account, Flarer, Tool}; #[tokio::main] async fn main() -> flarer::Result<()> { let mut args = std::env::args().skip(1); let url = args .next() .unwrap_or_else(|| "https://example.com".to_string()); let out_dir = args .next() .map(PathBuf::from) .unwrap_or_else(|| PathBuf::from("outputs")); let account = Account::from_env()?; let flarer = Flarer::builder() .account(account) .output_dir(out_dir) .build()?; flarer.verify().await?; let path = match flarer.run(Tool::Screenshot, &url).await? { flarer::Output::File(p) => p, other => panic!("unexpected output: {other:?}"), }; println!("screenshot saved to {}", path.display()); Ok(()) }