browser_use/browser/
config.rs1use std::path::PathBuf;
2
3#[derive(Debug, Clone)]
5pub struct LaunchOptions {
6 pub headless: bool,
8
9 pub chrome_path: Option<PathBuf>,
11
12 pub window_width: u32,
14
15 pub window_height: u32,
17
18 pub user_data_dir: Option<PathBuf>,
20
21 pub sandbox: bool,
23
24 pub launch_timeout: u64,
26}
27
28impl Default for LaunchOptions {
29 fn default() -> Self {
30 Self {
31 headless: true,
32 chrome_path: None,
33 window_width: 1280,
34 window_height: 720,
35 user_data_dir: None,
36 sandbox: true,
37 launch_timeout: 30000,
38 }
39 }
40}
41
42impl LaunchOptions {
43 pub fn new() -> Self {
45 Self::default()
46 }
47
48 pub fn headless(mut self, headless: bool) -> Self {
50 self.headless = headless;
51 self
52 }
53
54 pub fn chrome_path(mut self, path: PathBuf) -> Self {
56 self.chrome_path = Some(path);
57 self
58 }
59
60 pub fn window_size(mut self, width: u32, height: u32) -> Self {
62 self.window_width = width;
63 self.window_height = height;
64 self
65 }
66
67 pub fn user_data_dir(mut self, dir: PathBuf) -> Self {
69 self.user_data_dir = Some(dir);
70 self
71 }
72
73 pub fn sandbox(mut self, sandbox: bool) -> Self {
75 self.sandbox = sandbox;
76 self
77 }
78
79 pub fn launch_timeout(mut self, timeout_ms: u64) -> Self {
81 self.launch_timeout = timeout_ms;
82 self
83 }
84}
85
86#[derive(Debug, Clone)]
88pub struct ConnectionOptions {
89 pub ws_url: String,
91
92 pub timeout: u64,
94}
95
96impl ConnectionOptions {
97 pub fn new<S: Into<String>>(ws_url: S) -> Self {
99 Self {
100 ws_url: ws_url.into(),
101 timeout: 10000,
102 }
103 }
104
105 pub fn timeout(mut self, timeout_ms: u64) -> Self {
107 self.timeout = timeout_ms;
108 self
109 }
110}
111
112#[cfg(test)]
113mod tests {
114 use super::*;
115
116 #[test]
117 fn test_launch_options_default() {
118 let opts = LaunchOptions::default();
119 assert!(opts.headless);
120 assert_eq!(opts.window_width, 1280);
121 assert_eq!(opts.window_height, 720);
122 assert!(opts.sandbox);
123 assert_eq!(opts.launch_timeout, 30000);
124 }
125
126 #[test]
127 fn test_launch_options_builder() {
128 let opts = LaunchOptions::new()
129 .headless(false)
130 .window_size(1920, 1080)
131 .sandbox(false)
132 .launch_timeout(60000);
133
134 assert!(!opts.headless);
135 assert_eq!(opts.window_width, 1920);
136 assert_eq!(opts.window_height, 1080);
137 assert!(!opts.sandbox);
138 assert_eq!(opts.launch_timeout, 60000);
139 }
140
141 #[test]
142 fn test_connection_options() {
143 let opts = ConnectionOptions::new("ws://localhost:9222").timeout(5000);
144
145 assert_eq!(opts.ws_url, "ws://localhost:9222");
146 assert_eq!(opts.timeout, 5000);
147 }
148}