-
Notifications
You must be signed in to change notification settings - Fork 65
/
chrome_devtools.rs
40 lines (33 loc) · 1.35 KB
/
chrome_devtools.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Requires chromedriver running on port 9515:
//!
//! chromedriver --port=9515
//!
//! Run as follows:
//!
//! cargo run --example chrome_devtools
use thirtyfour::extensions::cdp::{ChromeDevTools, NetworkConditions};
use thirtyfour::prelude::*;
#[tokio::main]
async fn main() -> color_eyre::Result<()> {
// The use of color_eyre gives much nicer error reports, including making
// it much easier to locate where the error occurred.
color_eyre::install()?;
let caps = DesiredCapabilities::chrome();
let driver = WebDriver::new("http://localhost:9515", caps).await?;
// Use Chrome Devtools Protocol (CDP).
let dev_tools = ChromeDevTools::new(driver.handle.clone());
let mut conditions = NetworkConditions::new();
conditions.download_throughput = 20;
conditions.upload_throughput = 10;
dev_tools.set_network_conditions(&conditions).await?;
let conditions = dev_tools.get_network_conditions().await?;
assert_eq!(conditions.download_throughput, 20);
assert_eq!(conditions.upload_throughput, 10);
println!("Conditions: {:?}", conditions);
// Execute CDP command.
let version_info = dev_tools.execute_cdp("Browser.getVersion").await?;
println!("Chrome Version: {:?}", version_info);
// Always explicitly close the browser. There are no async destructors.
driver.quit().await?;
Ok(())
}