mattsse / chromiumoxide

Chrome Devtools Protocol rust API
Apache License 2.0
755 stars 78 forks source link

browser.pages() does not return pages that weren't created directly by the crate but that are visible in CDP #147

Open steve-the-crab opened 1 year ago

steve-the-crab commented 1 year ago

If I connect() to an existing Chromium instance with one or more already open tabs, calling browser.pages() returns an empty vector instead of listing the open tabs which are visible via CDP at http://localhost:9222/json.

I don't know if this is intended behaviour but it somewhat negates the usefulness of connecting to an existing instance I believe.

It can be reproduced as so:

Launch chrome with remote debugging enabled, for example:

$ google-chrome-stable --remote-debugging-port=9222

Connect and list the pages:

let url = "ws://localhost:9222/devtools/browser/{some id}";

// browser/handler
let (mut browser, mut handler) = Browser::connect(url).await.unwrap();

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

// list pages
let pages = browser.pages().await;
let pages = pages.unwrap_or_default();
println!("{:?}", pages); 
// --> an empty vec

let page = browser.new_page("https://example.com").await;
let pages = browser.pages().await;
let pages = pages.unwrap_or_default();
println!("{:?}", pages);  
// --> a vec containing the example.com page
hackermondev commented 11 months ago

187 should fix this

steve-the-crab commented 11 months ago

Nice!