lukaslueg / rust-headless-chrome

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Headless Chrome

Build Status Crate API

Puppeteer for Rust. It looks a little something like this:

use headless_chrome::{Browser, LaunchOptionsBuilder};

fn browse_wikipedia() -> Result<(), failure::Error> {
    let options = LaunchOptionsBuilder::default().build().expect("Failed to find chrome");
    let browser = Browser::new(options)?;

    let tab = browser.wait_for_initial_tab()?;

    tab.navigate_to("https://www.wikipedia.org")?;

    tab.wait_for_element("input#searchInput")?
       .click()?;
    tab.type_str("WebKit")?
       .press_key("Enter")?;

    tab.wait_for_element("#firstHeading")?;
    assert_eq!(true, tab.get_url().ends_with("WebKit"));
    Ok(())
}

assert!(browse_wikipedia().is_ok());

For fuller examples, take a look at tests/simple.rs and examples/real_world.rs.

If you're looking to do general browser testing or scraping (rather than anything specific to Chrome / DevTools), you're probably better off with fantoccini for now. It's a lot more feature-complete and stable.

Troubleshooting

If you get errors related to timeouts, you likely need to enable sandboxing either in the kernel or as a setuid sandbox. Puppeteer has some information about how to do that here

Missing features

Contributing

Pull requests and issues are most welcome, even if they're just experience reports. If you find anything frustrating or confusing, let me know!

About


Languages

Language:Rust 97.9%Language:HTML 1.8%Language:JavaScript 0.3%