headless_chrome/lib.rs
1//! A high-level API to control headless Chrome or Chromium over the DevTools Protocol. It is the
2//! Rust equivalent of [Puppeteer](https://github.com/GoogleChrome/puppeteer), a Node library
3//! maintained by the Chrome DevTools team.
4//!
5//! It is not 100% feature compatible with Puppeteer, but there's enough here to satisfy most
6//! browser testing / web crawling use cases, and there are several 'advanced' features such as:
7//!
8//! - [network request interception](https://docs.rs/headless_chrome/latest/headless_chrome/browser/tab/struct.Tab.html#method.enable_request_interception)
9//! - [JavaScript coverage monitoring](https://docs.rs/headless_chrome/latest/headless_chrome/browser/tab/struct.Tab.html#method.take_precise_js_coverage)
10//! - [taking screenshots of elements or the entire page](https://docs.rs/headless_chrome/latest/headless_chrome/browser/tab/struct.Tab.html#method.capture_screenshot)
11//! - [saving pages to PDF](https://docs.rs/headless_chrome/latest/headless_chrome/browser/tab/struct.Tab.html#method.print_to_pdf)
12//! - ['headful' browsing](https://docs.rs/headless_chrome/latest/headless_chrome/struct.LaunchOptionsBuilder.html#method.headless)
13//! - automatic downloading of 'known good' Chromium binaries for Linux / Mac / Windows
14//! - [extension pre-loading](https://docs.rs/headless_chrome/latest/headless_chrome/struct.LaunchOptionsBuilder.html#method.extensions)
15//!
16//! # Quick Start
17//!
18//! ```no_run
19//! use headless_chrome::{Browser, protocol::page::ScreenshotFormat};
20//! use headless_chrome::protocol::cdp::Page;
21//!
22//! fn browse_wikipedia() -> Result<(), failure::Error> {
23//! let browser = Browser::default()?;
24//!
25//! let tab = browser.new_tab()?;
26//!
27//! /// Navigate to wikipedia
28//! tab.navigate_to("https://www.wikipedia.org")?;
29//!
30//! /// Wait for network/javascript/dom to make the search-box available
31//! /// and click it.
32//! tab.wait_for_element("input#searchInput")?.click()?;
33//!
34//! /// Type in a query and press `Enter`
35//! tab.type_str("WebKit")?.press_key("Enter")?;
36//!
37//! /// We should end up on the WebKit-page once navigated
38//! tab.wait_for_element("#firstHeading")?;
39//! assert!(tab.get_url().ends_with("WebKit"));
40//!
41//! /// Take a screenshot of the entire browser window
42//! let _jpeg_data = tab.capture_screenshot(
43//! Page::CaptureScreenshotFormatOption::Png,
44//! Some(75),
45//! None,
46//! true)?;
47//!
48//! /// Take a screenshot of just the WebKit-Infobox
49//! let _png_data = tab
50//! .wait_for_element("#mw-content-text > div > table.infobox.vevent")?
51//! .capture_screenshot(ScreenshotFormat::PNG)?;
52//! Ok(())
53//! }
54//!
55//! assert!(browse_wikipedia().is_ok());
56//! ```
57
58#![deny(clippy::pedantic)]
59#![warn(renamed_and_removed_lints)]
60#![allow(
61clippy::module_name_repetitions,
62clippy::doc_markdown, // a number of false positives here
63clippy::default_trait_access, // fails on output of derive_builder
64clippy::needless_pass_by_value, // would stop us creating and passing in LaunchOptions to browser in one statement
65clippy::unreadable_literal, // not really applicable for timestamps
66clippy::too_many_lines,
67clippy::type_repetition_in_bounds,
68clippy::used_underscore_binding,
69clippy::must_use_candidate,
70clippy::derive_partial_eq_without_eq, // f64 doesn't impl Eq, for autogen protocol.rs
71clippy::missing_errors_doc,
72clippy::missing_panics_doc,
73clippy::struct_excessive_bools, // for autogen protocol.rs
74clippy::wildcard_imports, // for autogen protocol.rs
75clippy::cast_possible_truncation, // for types.rs:189 & 190
76clippy::cast_sign_loss, // for tab/element/mod.rs:492 & 493
77clippy::cast_lossless, // for tab/element/mod.rs:492 & 493
78ambiguous_wide_pointer_comparisons, // for tab/mod.rs:1415
79clippy::derivable_impls, // for types.rs Default for PrintToPDF because autogen
80clippy::type_complexity, // for transport/web_socket_connection.rs:133
81clippy::manual_let_else, // for transport/web_socket_connection.rs:142
82clippy::should_implement_trait, // for browser/mod.rs:106
83)]
84
85pub use browser::{
86 tab::{element::Element, Tab},
87 Browser, LaunchOptions, LaunchOptionsBuilder,
88};
89
90#[cfg(feature = "fetch")]
91pub use browser::FetcherOptions;
92
93#[cfg(feature = "fetch")]
94pub use browser::Revision;
95
96pub mod browser;
97pub mod protocol;
98pub mod types;
99pub mod util;
100
101#[cfg(feature = "nightly")]
102#[doc = include_str!("../README.md")]
103#[allow(dead_code)]
104type _READMETEST = ();