mattsse / chromiumoxide

Chrome Devtools Protocol rust API
Apache License 2.0
712 stars 69 forks source link

Times Out On Any Website Using <browser>.new_page() #178

Closed Coops0 closed 9 months ago

Coops0 commented 9 months ago

This is a weird one.

I have used this library ~3 times before this without any issues, yet now on this specific project it just times out whenever creating a new tab. Attached below is the project. I have been trying different fixes and combinations for the last 3 hours. I think it may just be my computer, but I tested this on a windows server I own, but that also just timed out. It's so strange, I was able to compile my older project and it worked fine! Any help is appreciated.

test.zip

Here is the error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Timeout', src\main.rs:22:69
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

For quick reference, here is main.rs in the zip:

use std::time::Duration;
use chromiumoxide::Browser;
use chromiumoxide::browser::BrowserConfigBuilder;
use futures::StreamExt;
use tokio::task;

#[tokio::main]
async fn main() {
    let (browser, mut handler) = Browser::launch(
          BrowserConfigBuilder::default()
             .request_timeout(Duration::from_secs(5))
             .build()
             .unwrap()
    ).await.unwrap();

    let h = task::spawn(async move {
          while let Some(h) = handler.next().await {
             h.unwrap();
          }
    });

    let page = browser.new_page("https://www.google.com").await.unwrap();

    h.await.unwrap();
}
Coops0 commented 9 months ago

Same result on clean install on Mac!

makindotcc commented 9 months ago

Same issue with

chromiumoxide = { version = "0.5.3", features = ["tokio-runtime"], default-features = false }

When I add sleep before new_page it starts working:

        sleep(Duration::from_secs(5)).await;
        let page = browser
            .new_page("https://buzkaaclicker.pl/download/test123")
            .await
            .unwrap();

But it sometimes times out on different things later (sometimes not! just a rng)

makindotcc commented 9 months ago

I've tested it and issue is introduced in 0.5.0 version, sample code works fine in 0.4.0 release.

nvm, I'm testing it once again. I don't know, I cannot reproduce it reliably. If new_page launches then find_element and click fails. Sometimes the browser is not starting anymore.

msmps commented 9 months ago

I can confirm I too started a clean project tonight on arm m1 and got the timeout issue mentioned above.

Coops0 commented 9 months ago

Can confirm nothing above 0.4 works on my windows 11.

When I add sleep before new_page it starts working:

Yesterday, when I was messing with it, I got it to work very finicky by adding a println! before the .new_page. Now that doesn't even work anymore and a sleep doesn't work on never versions either.

mattsse commented 9 months ago

sorry about this,

I can reproduce this and it looks like the root cause is the async-tungstenite bump here

https://github.com/mattsse/chromiumoxide/pull/177

example above fails with 0.23 but succeeds with 0.22

checking

mattsse commented 9 months ago

okay, so this tokio change surfaced incorrect api usage of the connection Sink

https://github.com/snapview/tokio-tungstenite/pull/284

should be fixed via #179

I'm yanking the current release and publish a new one since critical

mattsse commented 9 months ago

0.5.4 is out, please try again after upgrading

Coops0 commented 9 months ago

0.5.4 works for me! Thanks for the quick fix!