pub fn is_browser_active() -> boolExamples found in repository?
examples/basic_usage.rs (line 26)
5fn main() {
6 println!("š Browser URL - Basic Usage Demo");
7 println!("==================================");
8
9 // Give the user time to switch to a browser window
10 println!("\nš Instructions:");
11 println!("1. Open a browser (Chrome, Firefox, Zen, etc.)");
12 println!("2. Navigate to any website");
13 println!("3. When it says 'NOW!', quickly click on the browser window");
14 println!("\nā° Starting in 5 seconds...");
15
16 for i in (1..=5).rev() {
17 println!(" {i} seconds...");
18 thread::sleep(Duration::from_secs(1));
19 }
20
21 println!("\nš NOW! Quickly click on your browser window!");
22 thread::sleep(Duration::from_millis(2000));
23
24 // Check if a browser is the active window
25 println!("\nš Checking for active browser...");
26 if !is_browser_active() {
27 println!("ā No browser window detected as active");
28 println!("\nš Retrying for 10 seconds ā switch to your browser!");
29
30 let mut found = false;
31 for i in (1..=10).rev() {
32 thread::sleep(Duration::from_secs(1));
33 if is_browser_active() {
34 println!("ā
Browser detected!");
35 found = true;
36 break;
37 }
38 if i > 1 {
39 println!(" Checking... {} seconds left", i - 1);
40 }
41 }
42
43 if !found {
44 println!("ā Still no browser detected.");
45 println!("š” Try running again while keeping a browser window focused:");
46 println!(" cargo run --example basic_usage");
47 return;
48 }
49 } else {
50 println!("ā
Browser detected immediately!");
51 }
52
53 // Extract browser info including URL
54 println!("\nš Extracting browser URL...");
55 match get_active_browser_url() {
56 Ok(info) => {
57 println!("ā
Browser info extracted successfully!\n");
58 println!(" š URL: {}", info.url);
59 println!(" š Title: {}", info.title);
60 println!(" š Browser: {} ({:?})", info.browser_name, info.browser_type);
61 println!(" š Process ID: {}", info.process_id);
62 println!(
63 " š Position: ({:.0}, {:.0})",
64 info.window_position.x, info.window_position.y
65 );
66 println!(
67 " š Size: {:.0}x{:.0}",
68 info.window_position.width, info.window_position.height
69 );
70 }
71 Err(e) => {
72 println!("ā Failed to extract browser info: {e}");
73 }
74 }
75
76 println!("\nšÆ Demo completed!");
77}