Expand description
A Rust library for capturing HTML screenshots using CDP.
- Auto cleanup
- Asynchronous API (Tokio)
- HTML screenshot captures
§Example
§Capture HTML screenshot
use base64::Engine;
use anyhow::Result;
use cdp_html_shot::Browser;
#[tokio::main]
async fn main() -> Result<()> {
const HTML: &str = r#"
<html lang="en-US">
<body>
<h1>My test page</h1>
<p>Hello, Rust!</p>
</body>
</html>
"#;
let browser = Browser::new().await?;
let base64 = browser.capture_html(HTML, "html").await?;
let img_data = base64::prelude::BASE64_STANDARD.decode(base64)?;
std::fs::write("test0.jpeg", img_data)?;
Ok(())
}
§Fine control
use base64::Engine;
use anyhow::Result;
use cdp_html_shot::Browser;
#[tokio::main]
async fn main() -> Result<()> {
let browser = Browser::new().await?;
let tab = browser.new_tab().await?;
tab.set_content("<h1>Hello world!</h1>").await?;
let element = tab.find_element("h1").await?;
let base64 = element.screenshot().await?;
tab.close().await?;
let img_data = base64::prelude::BASE64_STANDARD.decode(base64)?;
std::fs::write("test0.jpeg", img_data)?;
Ok(())
}
Structs§
- Browser
- A browser instance.
- Capture
Options - Configuration options for HTML capture.
- Element
- An element instance.
- Exit
Hook - A struct that manages cleanup functions to be executed on process termination.
- Tab
- A tab instance.