Skip to main content

chromiumoxide/
lib.rs

1#![recursion_limit = "256"]
2//! A high-level API for programmatically interacting with the [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/).
3//!
4//! This crate uses the [Chrome DevTools protocol] to drive/launch a Chromium or
5//! Chrome (potentially headless) browser.
6//!
7//! # Example
8//! ```no_run
9//! use futures_util::StreamExt;
10//! use chromiumoxide::{Browser, BrowserConfig};
11//!
12//! #[tokio::main]
13//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
14//!
15//!     let (browser, mut handler) =
16//!         Browser::launch(BrowserConfig::builder().with_head().build()?).await?;
17//!
18//!     let handle = tokio::task::spawn(async move {
19//!         loop {
20//!             let _event = handler.next().await.unwrap();
21//!         }
22//!     });
23//!
24//!     let page = browser.new_page("https://en.wikipedia.org").await?;
25//!
26//!     // type into the search field and hit `Enter`,
27//!     // this triggers a navigation to the search result page
28//!     page.find_element("input#searchInput")
29//!             .await?
30//!             .click()
31//!             .await?
32//!             .type_str("Rust programming language")
33//!             .await?
34//!             .press_key("Enter")
35//!             .await?;
36//!
37//!     let html = page.wait_for_navigation().await?.content().await?;
38//!
39//!     let _ = handle.await;
40//!     Ok(())
41//! }
42//! ```
43//!
44//! The [`chromiumoxide_pdl`] crate contains a [PDL
45//! parser](chromiumoxide_pdl/src/pdl/parser.rs), which is a rust rewrite of a
46//! [python script in the chromium source tree]( https://chromium.googlesource.com/deps/inspector_protocol/+/refs/heads/master/pdl.py) and a
47//! [`Generator`](chromiumoxide_pdl/src/build/generator.rs) that turns the
48//! parsed PDL files into rust code. The
49//! [`chromiumoxide_cdp`](chromiumoxide_cdp) crate only purpose is to integrate
50//! the generator during is build process and include the generated output
51//! before compiling the crate itself. This separation is done merely because
52//! the generated output is ~60K lines of rust code (not including all the Proc
53//! macro extensions). So expect the compilation to take some time.
54//!
55//! The generator can be configured and used independently, see [`build.rs`] of
56//! [`chromiumoxide_cdp`].
57//!
58//! [chromedp](https://github.com/chromedp/chromedp)
59//! [rust-headless-chrome](https://github.com/Edu4rdSHL/rust-headless-chrome) which the launch
60//! config, `KeyDefinition` and typing support is taken from.
61//! [puppeteer](https://github.com/puppeteer/puppeteer)
62
63#![warn(missing_debug_implementations, rust_2018_idioms)]
64
65pub mod async_process;
66pub mod auth;
67pub mod bg_cleanup;
68pub mod browser;
69#[cfg(feature = "_cache")]
70pub mod cache;
71pub mod content_markdown;
72pub mod content_stream;
73#[cfg(feature = "_cache")]
74pub mod http;
75
76pub mod cmd;
77pub mod conn;
78pub mod detection;
79pub mod dns;
80pub mod element;
81pub mod error;
82pub mod handler;
83pub mod javascript;
84pub mod js;
85pub mod keys;
86pub mod layout;
87pub mod listeners;
88pub mod mouse;
89pub mod page;
90pub mod runtime_release;
91pub mod uring_fs;
92pub mod utils;
93pub mod webmcp;
94
95use crate::handler::http::HttpRequest;
96use std::sync::Arc;
97
98/// re-export fingerprint management.
99pub use spider_fingerprint;
100/// re-export network blocker.
101pub use spider_network_blocker;
102
103#[cfg(feature = "firewall")]
104/// re-export firewall.
105pub use spider_firewall;
106
107pub use crate::browser::{Browser, BrowserConfig};
108pub use crate::conn::Connection;
109pub use crate::element::Element;
110pub use crate::error::Result;
111#[cfg(feature = "fetcher")]
112pub use crate::fetcher::{BrowserFetcher, BrowserFetcherOptions};
113pub use crate::handler::page::active_page_count;
114pub use crate::handler::Handler;
115pub use crate::page::Page;
116/// re-export the generated cdp types
117pub use chromiumoxide_cdp::cdp;
118pub use chromiumoxide_types::{self as types, Binary, Command, Method, MethodType};
119
120#[cfg(feature = "fetcher")]
121pub mod fetcher {
122    pub use chromiumoxide_fetcher::*;
123}
124
125/// HTTP request.
126pub type ArcHttpRequest = Option<Arc<HttpRequest>>;
127
128pub use serde;
129#[cfg(not(feature = "simd"))]
130pub use serde_json;
131#[cfg(feature = "simd")]
132pub use sonic_rs as serde_json;
133
134/// Init the cache global worker.
135#[cfg(feature = "_cache")]
136pub use cache::dump_remote::init_default_cache_worker;