Skip to main content

chaser_oxide/
lib.rs

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