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

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 this issue Apr 12, 2023 · 2 comments

Comments

@steve-the-crab
Copy link

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
@steve-the-crab steve-the-crab changed the title browser.pages() does not return pages not created directly by the crate but that are visible in CDP browser.pages() does not return pages that weren't created directly by the crate but that are visible in CDP Apr 12, 2023
@hackermondev
Copy link
Contributor

#187 should fix this

@steve-the-crab
Copy link
Author

Nice!

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

2 participants