mattsse / chromiumoxide

Chrome Devtools Protocol rust API
Apache License 2.0
773 stars 81 forks source link

Error: Ws(Url(TlsFeatureNotEnabled)) When trying to connect to a cdp instance behind TLS #249

Closed GRVYDEV closed 2 hours ago

GRVYDEV commented 2 hours ago

Hello I am running into an issue trying to connect to a remote browser that is behind tls.

Here is my code:

use chromiumoxide::browser::Browser;
use futures::StreamExt;

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // create a `Browser` that spawns a `chromium` process running with UI (`with_head()`, headless is default)
    // and the handler that drives the websocket etc.
    let (mut browser, mut handler) = Browser::connect(
        "wss://connect.browserbase.com?apiKey=MY_KEY",
    )
    .await?;

    println!("Browser connected");

    // spawn a new task that continuously polls the handler
    let handle = async_std::task::spawn(async move {
        while let Some(h) = handler.next().await {
            if h.is_err() {
                break;
            }
        }
    });

    // create a new browser page and navigate to the url
    let page = browser.new_page("https://en.wikipedia.org").await?;

    // find the search bar type into the search field and hit `Enter`,
    // this triggers a new 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?;

    println!("{}", html);

    browser.close().await?;
    handle.await;
    Ok(())
}

It seems like I need to enable a tls feature somewhere but I am not sure where. Here is my Cargo.toml

[package]
name = "chromeoxide"
version = "0.1.0"
edition = "2021"

[dependencies]
async-std = "1.13.0"
async-tungstenite = { version = "*", features = ["async-tls", "async-native-tls", "async-std-runtime"] }
chromiumoxide = {version = "0.7.0", features = ["async-std-runtime"]}
futures = "0.3.31"
GRVYDEV commented 2 hours ago

Closing since I solved this by changing the tungstenite dep to async-tungstenite = { version = "*", features = ["async-tls", "async-native-tls", "async-std-runtime"] }