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

Implement function to fetch existing targets when connecting to existing chromium instance #187

Merged
merged 2 commits into from
Nov 6, 2023

Conversation

hackermondev
Copy link
Contributor

When connecting to an existing Chromium instance with Browser::connect, pages created before the connection cannot be used because chromiumoxide doesn't know they exist.

I implemented a function Browser::fetch_targets that uses Target.getTargets to fetch all existing pages. If the user wants to use pages created before the connection, all they need to do is call that function.

@hackermondev
Copy link
Contributor Author

@mattsse mind reviewing this?

Copy link
Owner

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@mattsse mattsse merged commit c189e64 into mattsse:main Nov 6, 2023
7 checks passed
@steve-the-crab
Copy link

Hi @hackermondev,

I had a few problems in that frequently the pages of fetched targets might hang or not be discoverable.

For the sake of testing, trying to connect to any target in a loop to get any that might be available has the effect of either getting a usable target and it hanging on navigation or no target being available.

It works very well the first time, but seems to run into issues on subsequent tries.

Is this something you have seen yourself? I'm just wondering if I have missed something.

Thanks

pub async fn get_first_connectable_page(mut browser: Browser) -> anyhow::Result<(Browser, Page)> {
    for t in browser.fetch_targets().await? {
        let target = t.target_id.clone();
        match browser.get_page(target).await {
            Ok(page) => return Ok((browser, page)),
            Err(_) => {}
        };
    }
    Err(anyhow!("..."))
}

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

Successfully merging this pull request may close these issues.

3 participants