Crates.io | cdp-html-shot |
lib.rs | cdp-html-shot |
version | 0.1.15 |
source | src |
created_at | 2024-10-30 16:58:07.256576 |
updated_at | 2024-11-04 14:29:28.18799 |
description | A Rust library for capturing HTML screenshots using CDP. |
homepage | |
repository | https://github.com/araea/cdp-html-shot |
max_upload_size | |
id | 1428839 |
size | 135,379 |
A Rust library for capturing HTML screenshots using CDP.
[dependencies]
cdp-html-shot = "0.1"
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(())
}
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(())
}