chromedriver-api 0.1.7

This API is designed for interacting with chromedriver (browser auto clicker)
docs.rs failed to build chromedriver-api-0.1.7
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: chromedriver-api-0.1.14

githubcrates-iodocs-rs

Chromedriver API (auto clicker)

This API is designed to interact with the google chromedriver. This is useful to create browser-based parsers or autoclickers.

Examples:

use chromedriver_api::{ Result, Session };
use tokio::time::{ sleep, Duration };

#[tokio::main]
async fn main() -> Result<()> {
    let free_port = std::net::TcpListener::bind("127.0.0.1:0")?.local_addr()?.port().to_string();

    println!("[INFO]: Starting chrome session ..");

    let mut session = Session::run(
        &free_port,  // session server ip port
        Some("/bin/chromedriver/chromedriver.exe"),  // path to chromedriver (None = to use global system Path)
        Some("C:/Users/Admin/AppData/Local/Google/Chrome/Profiles/Profile1"),  // path to load/save profile (cookies, localStorage and etc.)
        false  // headless mode (without interface)
    ).await?;

    println!("[INFO]: Session is launched on port [{free_port}] ..");

    // open first tab:
    let first_tab = session.open("https://example.com/").await?;
    let mut first_tab = first_tab.lock().await;
    println!("[INFO]: A new tab is opened on 'https://example.com/' ..");
    
    sleep(Duration::from_secs(1)).await;

    // open second tab:
    let second_tab = session.open("https://example.com/").await?;
    let mut second_tab = second_tab.lock().await;
    println!("[INFO]: A new tab is opened on 'https://example.com/' ..");

    sleep(Duration::from_secs(1)).await;

    // inject script to first tab (where: <DESERIALIZE_DATA>):
    let _result = first_tab.inject::<()>(r#"
        alert("Ok!")
    "#).await?;

    sleep(Duration::from_secs(1)).await;

    // do second tab active:
    second_tab.active().await?;

    sleep(Duration::from_secs(1)).await;

    // close second tab:
    second_tab.close().await?;
    println!("[INFO]: The second tab is closed");

    sleep(Duration::from_secs(1)).await;

    // close session:
    session.close().await?;
    println!("[INFO]: The session is closed");

    Ok(())
}

Licensing:

Distributed under the MIT license.

Feedback:

You can contact me via GitHub or send a message to my Telegram @fuderis.

This library is constantly evolving, and I welcome your suggestions and feedback.