Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page.goto hangs on some websites while browser.new_page works #191

Open
krant opened this issue Nov 15, 2023 · 0 comments
Open

Page.goto hangs on some websites while browser.new_page works #191

krant opened this issue Nov 15, 2023 · 0 comments

Comments

@krant
Copy link
Contributor

krant commented Nov 15, 2023

For some use cases browser.new_page is not applicable (WebView not supporting it at all, also latency requirements) so I had to use page.goto. Unfortunately it hangs on some websites while browser.new_page handles them correctly:

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

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (mut browser, mut handler) =
        Browser::launch(BrowserConfig::builder()
            .build()?).await?;
    let handle = tokio::spawn(async move {
        while let Some(h) = handler.next().await {
            h.unwrap();
        }
    });

    let url = "https://time.com";

    // This works:
    //  let page = browser.new_page(url).await.unwrap();
    // This hangs and eventually timeouts:
        let page = browser.new_page("about:blank").await.unwrap(); // imitate re-use of existing page for brevity
        page.goto(url).await?;

    let content = page.content().await.unwrap();
    println!("{content}");

    browser.close().await?;
    browser.wait().await?;
    handle.await?;

    Ok(())
}

P.S. I've tried putting goto into separate task and then wait for Page.loadEventFired, and it was kinda working, but only for the first request - when second one arrives, the existing page still processes something from the previous request, which leads to large delays or timeouts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant