Crate chromiumoxide

Source
Expand description

A high-level API for programmatically interacting with the Chrome DevTools Protocol.

This crate uses the [Chrome DevTools protocol] to drive/launch a Chromium or Chrome (potentially headless) browser.

§Example

use futures::StreamExt;
use chromiumoxide::{Browser, BrowserConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {

    let (browser, mut handler) =
        Browser::launch(BrowserConfig::builder().with_head().build()?).await?;

    let handle = tokio::task::spawn(async move {
        loop {
            let _event = handler.next().await.unwrap();
        }
    });

    let page = browser.new_page("https://en.wikipedia.org").await?;

    // type into the search field and hit `Enter`,
    // this triggers a navigation to the search result page
    page.find_element("input#searchInput")
            .await?
            .click()
            .await?
            .type_str("Rust programming language")
            .await?
            .press_key("Enter")
            .await?;

    let html = page.wait_for_navigation().await?.content().await?;

    let _ = handle.await;
    Ok(())
}

The [chromiumoxide_pdl] crate contains a PDL parser, which is a rust rewrite of a python script in the chromium source tree and a Generator that turns the parsed PDL files into rust code. The chromiumoxide_cdp crate only purpose is to integrate the generator during is build process and include the generated output before compiling the crate itself. This separation is done merely because the generated output is ~60K lines of rust code (not including all the Proc macro extensions). So expect the compilation to take some time.

The generator can be configured and used independently, see [build.rs] of chromiumoxide_cdp.

chromedp rust-headless-chrome which the launch config, KeyDefinition and typing support is taken from. puppeteer

Re-exports§

Modules§

Structs§

  • Represents a binary type as defined in the CDP protocol.

Traits§

  • Trait that all the request types have to implement.
  • Methods are message types that contain the field method = Self::identifier() in their json body.
  • A trait that identifies a method on type level

Type Aliases§