8 releases (2 stable)
1.0.2 | Aug 15, 2024 |
---|---|
0.2.1 | Aug 9, 2024 |
0.1.3 | Aug 8, 2024 |
#212 in Operating systems
20KB
269 lines
chromedriver
Automatically download Chromedriver when browser/driver versions do not match.
usage
install
cargo install chromedriver-update
run
--browser-path: chrome browser path
--driver-path: chrome driver path, create when file not exist
# mac
chromedriver-update \
--browser-path="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
--driver-path="/usr/local/bin/chromedriver"
# linux
chromedriver-update \
--browser-path="/usr/bin/google-chrome" \
--driver-path="/usr/bin/chromedriver"
# windows (only tested in github workflow)
chromedriver-update \
--browser-path="C:\setup-chrome\chromium\120.0.6099.109\x64\chrome.exe" \
--driver-path="C:\setup-chrome\chromedriver.exe"
code usage
require rust >= v1.80
add package
cargo add chromedriver-update
code examples
- /examples/default_args.rs
use chromedriver_update::ChromeDriver;
#[tokio::main]
async fn main() {
let mut driver = ChromeDriver::new();
driver.init().await.unwrap();
println!("driver version {}", driver.version);
println!("browser version {}", driver.browser_version);
if driver.need_download() {
driver.try_download().await.unwrap();
}
}
- /examples/custom_args.rs
use chromedriver_update::ChromeDriver;
#[tokio::main]
async fn main() {
let mut driver = ChromeDriver::new();
driver
.set_driver_path("/usr/local/bin/chromedriver")
.set_browser_path("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
.set_connect_timeout(2000)
.set_timeout(5000)
.init()
.await
.unwrap();
println!("driver version {}", driver.version);
println!("browser version {}", driver.browser_version);
if !driver.need_download() {
println!("no need to update driver");
return;
}
println!("updating driver ...");
match driver.try_download().await {
Ok(_) => println!("Download driver successful"),
Err(err) => eprintln!("Download driver failed, {}", err),
}
}
Dependencies
~14–27MB
~401K SLoC