cdp_html_shot/lib.rs
1/*!
2[![GitHub]](https://github.com/araea/cdp-html-shot) [![crates-io]](https://crates.io/crates/cdp-html-shot) [![docs-rs]](crate)
3
4[GitHub]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
5[crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
6[docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs
7
8<br>
9
10A Rust library for capturing HTML screenshots using CDP.
11
12- Auto cleanup
13- Asynchronous API (Tokio)
14- HTML screenshot captures
15
16## Example
17
18### Capture HTML screenshot
19
20```rust
21use base64::Engine;
22use anyhow::Result;
23use cdp_html_shot::Browser;
24
25#[tokio::main]
26async fn main() -> Result<()> {
27 const HTML: &str = r#"
28 <html lang="en-US">
29 <body>
30 <h1>My test page</h1>
31 <p>Hello, Rust!</p>
32 </body>
33 </html>
34 "#;
35
36 let browser = Browser::new().await?;
37 let base64 = browser.capture_html(HTML, "html").await?;
38
39 let img_data = base64::prelude::BASE64_STANDARD.decode(base64)?;
40 std::fs::write("test0.jpeg", img_data)?;
41
42 Ok(())
43}
44```
45
46### Fine control
47
48```rust
49use base64::Engine;
50use anyhow::Result;
51use cdp_html_shot::Browser;
52
53#[tokio::main]
54async fn main() -> Result<()> {
55 let browser = Browser::new().await?;
56 let tab = browser.new_tab().await?;
57
58 tab.set_content("<h1>Hello world!</h1>").await?;
59
60 let element = tab.find_element("h1").await?;
61 let base64 = element.screenshot().await?;
62 tab.close().await?;
63
64 let img_data = base64::prelude::BASE64_STANDARD.decode(base64)?;
65 std::fs::write("test0.jpeg", img_data)?;
66
67 Ok(())
68}
69```
70*/
71
72mod tab;
73mod browser;
74mod element;
75mod transport;
76mod general_utils;
77mod transport_actor;
78mod capture_options;
79#[cfg(feature = "atexit")]
80mod exit_hook;
81
82pub use tab::Tab;
83pub use element::Element;
84pub use browser::Browser;
85pub use capture_options::CaptureOptions;
86#[cfg(feature = "atexit")]
87pub use exit_hook::ExitHook;