#chrome

chrome-remote-interface

Chrome DevTools Protocol Client

8 releases

0.1.0-alpha.8 Jul 2, 2021
0.1.0-alpha.7 Feb 20, 2021
0.1.0-alpha.5 Feb 15, 2021
0.1.0-alpha.3 Feb 13, 2021
0.1.0-alpha.1 Feb 12, 2021

#32 in #chrome

MIT/Apache

155KB
1K SLoC

chrome-remote-interface

Chrome DevTools Protocol client.

Currently Work In Progress.

Supported Browser

  • Chromium (latest)

Browser Discovery

  1. Using environemnt variable CRI_CHROME_BIN if specified.
  2. Search Platform path.
    • Windows: C:\Program Files\Chromium\Application\chrome.exe
    • Mac: /Applications/Chromium.app/Contents/MacOS/Chromium
    • Linux: /usr/bin/chromium or /usr/bin/chromium-browser
  3. Lookup via PATH env var.

Example

use chrome_remote_interface::Browser;
use chrome_remote_interface::model::target::{CreateTargetCommand, AttachToTargetCommand};

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
    let browser = Browser::launcher()
        .headless(true) // headless mode (Default)
        .launch()
        .await?;

    browser.run_with(|mut client| async move {
        // Open new page
        let response = client.request(CreateTargetCommand::builder()
            .url("https://example.org/".into())
            .build()
            .unwrap()
        ).await?;

        // Attach opened page.
        let response = client
            .request(AttachToTargetCommand::new((*response).clone(), Some(true)))
            .await?;

        // construct attached session.
        let mut session = client.session(response);

        // DO STUFF
        // ...

        Ok(())
    }).await
}

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.!

License: MIT OR Apache-2.0

Dependencies

~11–41MB
~654K SLoC