1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
//! A high-level API to control headless Chrome or Chromium over the DevTools Protocol. It is the //! Rust equivalent of [Puppeteer](https://github.com/GoogleChrome/puppeteer), a Node library //! maintained by the Chrome DevTools team. //! //! It is not 100% feature compatible with Puppeteer, but there's enough here to satisfy most //! browser testing / web crawling use cases, and there are several 'advanced' features such as: //! //! - [network request interception](https://docs.rs/headless_chrome/latest/headless_chrome/browser/tab/struct.Tab.html#method.enable_request_interception) //! - [JavaScript coverage monitoring](https://docs.rs/headless_chrome/latest/headless_chrome/browser/tab/struct.Tab.html#method.take_precise_js_coverage) //! - [taking screenshots of elements or the entire page](https://docs.rs/headless_chrome/latest/headless_chrome/browser/tab/struct.Tab.html#method.capture_screenshot) //! - [saving pages to PDF](https://docs.rs/headless_chrome/latest/headless_chrome/browser/tab/struct.Tab.html#method.print_to_pdf) //! - ['headful' browsing](https://docs.rs/headless_chrome/latest/headless_chrome/struct.LaunchOptionsBuilder.html#method.headless) //! - automatic downloading of 'known good' Chromium binaries for Linux / Mac / Windows //! - [extension pre-loading](https://docs.rs/headless_chrome/latest/headless_chrome/struct.LaunchOptionsBuilder.html#method.extensions) //! //! # Quick Start //! //! ```no_run //! use headless_chrome::{Browser, protocol::page::ScreenshotFormat}; //! //! fn browse_wikipedia() -> Result<(), failure::Error> { //! let browser = Browser::default()?; //! //! let tab = browser.wait_for_initial_tab()?; //! //! /// Navigate to wikipedia //! tab.navigate_to("https://www.wikipedia.org")?; //! //! /// Wait for network/javascript/dom to make the search-box available //! /// and click it. //! tab.wait_for_element("input#searchInput")?.click()?; //! //! /// Type in a query and press `Enter` //! tab.type_str("WebKit")?.press_key("Enter")?; //! //! /// We should end up on the WebKit-page once navigated //! tab.wait_for_element("#firstHeading")?; //! assert!(tab.get_url().ends_with("WebKit")); //! //! /// Take a screenshot of the entire browser window //! let _jpeg_data = tab.capture_screenshot( //! ScreenshotFormat::JPEG(Some(75)), //! None, //! true)?; //! //! /// Take a screenshot of just the WebKit-Infobox //! let _png_data = tab //! .wait_for_element("#mw-content-text > div > table.infobox.vevent")? //! .capture_screenshot(ScreenshotFormat::PNG)?; //! Ok(()) //! } //! //! assert!(browse_wikipedia().is_ok()); //! ``` #![cfg_attr(feature = "nightly", feature(external_doc))] #![deny(clippy::pedantic)] #![warn(renamed_and_removed_lints)] #![allow( clippy::unknown_clippy_lints, clippy::module_name_repetitions, clippy::doc_markdown, // a number of false positives here clippy::default_trait_access, // fails on output of derive_builder clippy::needless_pass_by_value // would stop us creating and passing in LaunchOptions to browser in one statement )] #[macro_use] extern crate derive_builder; extern crate log; pub use browser::{ tab::{element::Element, Tab}, Browser, LaunchOptionsBuilder, }; pub mod browser; pub mod protocol; pub mod util; #[cfg(feature = "nightly")] #[doc(include = "../README.md")] #[allow(dead_code)] type _READMETEST = ();