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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
//! Launch and session configuration: [`StealthConfig`], [`Mode`] and [`Proxy`].
use crate::util::Redacted;
/// How eoka drives a browser.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Mode {
/// Fingerprint, evasion scripts and viewport on every page, and the
/// transport refuses detectable CDP commands such as `Runtime.enable`.
#[default]
Stealth,
/// A plain attached session: no fingerprint, evasions or viewport
/// override, full CDP access, and `restore_state` merges cookies and
/// storage. Used for a Chrome eoka did not spawn.
Plain,
}
/// A proxy server, optionally with credentials. `Debug` redacts the
/// credentials, including any embedded in `server`.
#[derive(Clone, PartialEq, Eq)]
pub struct Proxy {
/// Proxy server URL (e.g. "http://host:port"), passed to `--proxy-server`.
pub server: String,
/// Username answered to explicit `Proxy` auth challenges.
pub username: Option<String>,
/// Password answered to explicit `Proxy` auth challenges.
pub password: Option<String>,
}
impl Proxy {
/// A proxy without credentials.
pub fn new(server: impl Into<String>) -> Self {
Self {
server: server.into(),
username: None,
password: None,
}
}
/// Answer `Proxy` auth challenges with these credentials.
#[must_use]
pub fn with_credentials(
mut self,
username: impl Into<String>,
password: impl Into<String>,
) -> Self {
self.username = Some(username.into());
self.password = Some(password.into());
self
}
}
impl std::fmt::Debug for Proxy {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self {
server,
username,
password,
} = self;
let mut output = f.debug_struct("Proxy");
// A proxy URL can embed credentials.
if server.contains('@') {
output.field("server", &Redacted);
} else {
output.field("server", server);
}
output
.field("username", &username.as_ref().map(|_| Redacted))
.field("password", &password.as_ref().map(|_| Redacted))
.finish()
}
}
/// Configuration for stealth features. `Debug` omits proxy credentials.
#[derive(Clone)]
pub struct StealthConfig {
/// Stealth (default) or a plain session. See [`Mode`].
pub mode: Mode,
/// Spoof the WebGL vendor/renderer and add canvas and audio noise.
/// Defaults to true.
pub fingerprint_spoofing: bool,
/// Custom user agent (None = random realistic)
pub user_agent: Option<String>,
/// Headless mode
pub headless: bool,
/// Absolute path to Chrome/Chromium. Invalid explicit paths never fall back.
pub chrome_path: Option<String>,
/// Absolute parent directory for a unique private browser runtime.
/// The parent is preserved; only Eoka's owned child is removed.
pub runtime_dir: Option<String>,
/// Enable Chrome's sandbox. Defaults to true. Unsupported sandbox
/// environments (some containers/CI) fail without an unsandboxed retry;
/// set this to false there explicitly.
pub sandbox: bool,
/// Opt-in: rewrite ChromeDriver automation markers in a cached private
/// copy of Chrome. Defaults to false; stock Chrome has none, so it then
/// launches the original binary unchanged. See `stealth::patcher`.
pub patch_binary: bool,
/// Viewport width in CSS pixels.
pub viewport_width: u32,
/// Viewport height in CSS pixels.
pub viewport_height: u32,
/// Physical pixels per CSS pixel. Must be finite and positive.
pub device_scale_factor: f64,
/// Directory for debug screenshots (defaults to current directory)
pub debug_dir: Option<String>,
/// Proxy server and optional credentials.
pub proxy: Option<Proxy>,
/// Durable Chrome user-data directory. When set, Eoka preserves the
/// profile and its full fingerprint identity across browser launches.
///
/// A running instance may be borrowed only without explicit
/// executable/runtime paths, since those cannot be applied to another
/// process. With `sandbox` enabled, it is borrowed only when its argv is
/// readable and carries no sandbox-disabling flag.
pub user_data_dir: Option<String>,
/// Named profile within `user_data_dir` (Chrome's `--profile-directory`,
/// e.g. "Profile 1"). Only meaningful when `user_data_dir` is set;
/// defaults to Chrome's implicit "Default" profile when `None`.
///
/// Chrome's singleton lock (and thus Eoka's reuse detection above) is
/// scoped to the whole `user_data_dir`, not the individual profile —
/// launching a second `profile_dir` while a Chrome is already running
/// on the same `user_data_dir` attaches to that same running instance
/// rather than opening a separate one, matching Chrome's own behavior.
pub profile_dir: Option<String>,
/// CDP command, automatic-reply write, and WebSocket connection timeout
/// (default: 30s, increase for slow proxies). Used as given, without rounding.
pub cdp_timeout: std::time::Duration,
/// IANA timezone (default: random from common US/EU timezones).
/// Set to a specific value like "America/New_York" to control the timezone.
pub timezone: Option<String>,
/// Extra Chrome command-line arguments appended after standard stealth args.
/// E.g. vec!["--use-fake-ui-for-media-stream".into()] to auto-grant camera.
pub extra_args: Vec<String>,
/// Ignore TLS certificate errors on every page from creation, before the
/// first navigation. `Page::ignore_cert_errors` is applied too late for
/// `new_page`'s own initial navigate — this covers self-signed/expired
/// certs (e.g. .onion services) hit on the very first load. Defaults to
/// false.
pub ignore_cert_errors: bool,
/// Resolve timezone and interface language from the browser's apparent
/// public IP via a one-shot navigation to Cloudflare's trace endpoint
/// before any real page is created. Keeps `Date`/`Intl` and the injected
/// `navigator.languages` consistent with IP geolocation instead of a
/// random timezone. Ignored when `timezone` is set explicitly and when
/// attaching to an existing browser. Defaults to false.
pub geo_align: bool,
}
impl std::fmt::Debug for StealthConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Exhaustive, so that adding a field forces a decision about printing it.
let Self {
mode,
fingerprint_spoofing,
user_agent,
headless,
chrome_path,
runtime_dir,
sandbox,
patch_binary,
viewport_width,
viewport_height,
device_scale_factor,
debug_dir,
proxy,
user_data_dir,
profile_dir,
cdp_timeout,
timezone,
extra_args,
ignore_cert_errors,
geo_align,
} = self;
let mut output = f.debug_struct("StealthConfig");
output
.field("mode", mode)
.field("fingerprint_spoofing", fingerprint_spoofing)
.field("user_agent", user_agent)
.field("headless", headless)
.field("chrome_path", chrome_path)
.field("runtime_dir", runtime_dir)
.field("sandbox", sandbox)
.field("patch_binary", patch_binary)
.field("viewport_width", viewport_width)
.field("viewport_height", viewport_height)
.field("device_scale_factor", device_scale_factor)
.field("debug_dir", debug_dir)
// `Proxy`'s Debug redacts its credentials.
.field("proxy", proxy)
.field("user_data_dir", user_data_dir)
.field("profile_dir", profile_dir)
.field("cdp_timeout", cdp_timeout)
.field("timezone", timezone)
// Arguments can embed credentials, such as --proxy-server=user:pass@host.
.field("extra_args", &extra_args.len())
.field("ignore_cert_errors", ignore_cert_errors)
.field("geo_align", geo_align)
.finish()
}
}
impl Default for StealthConfig {
fn default() -> Self {
Self {
mode: Mode::Stealth,
fingerprint_spoofing: true,
user_agent: None,
headless: true,
chrome_path: None,
runtime_dir: None,
sandbox: true,
patch_binary: false,
viewport_width: 1920,
viewport_height: 1080,
device_scale_factor: 1.0,
debug_dir: None,
proxy: None,
user_data_dir: None,
profile_dir: None,
cdp_timeout: crate::cdp::transport::DEFAULT_CDP_TIMEOUT,
timezone: None, // Random from common timezones
extra_args: Vec::new(),
ignore_cert_errors: false,
geo_align: false,
}
}
}
impl StealthConfig {
/// Proxy credentials the transport answers `Proxy` challenges with.
pub(crate) fn proxy_credentials(&self) -> Option<(String, String)> {
let proxy = self.proxy.as_ref()?;
proxy.username.clone().zip(proxy.password.clone())
}
/// [`Mode::Plain`]: no fingerprint, evasions or viewport override, and
/// live-attach semantics.
pub(crate) fn live_session(&self) -> bool {
self.mode == Mode::Plain
}
/// [`Mode::Stealth`]: the transport refuses detectable CDP commands.
pub(crate) fn filter_cdp(&self) -> bool {
self.mode == Mode::Stealth
}
/// Create a minimal config (no spoofing, no patching)
pub fn minimal() -> Self {
Self {
fingerprint_spoofing: false,
headless: false,
..Default::default()
}
}
/// Create a visible (non-headless) config
pub fn visible() -> Self {
Self {
headless: false,
..Default::default()
}
}
/// Create a debug config: visible. Logs come from `tracing`.
pub fn debug() -> Self {
Self::visible()
}
/// Config tuned for attaching to a user-owned browser via `Browser::connect*`.
///
/// Disables anything that touches the user's Chrome state:
/// - [`Mode::Plain`] — no evasion script injection on attached tabs and
/// full DevTools-equivalent CDP access
/// - `patch_binary = false` — we don't manage the binary
/// - all spoofing off — the user's browser already has its own fingerprint
pub fn live() -> Self {
Self {
mode: Mode::Plain,
fingerprint_spoofing: false,
..Default::default()
}
}
}
#[cfg(test)]
mod tests {
use super::{Proxy, StealthConfig};
#[test]
fn debug_output_omits_proxy_credentials() {
let printed = format!(
"{:?}",
StealthConfig {
proxy: Some(
Proxy::new("http://embedded-user:embedded-pass@proxy.test:8080")
.with_credentials("named-user", "named-pass")
),
extra_args: vec!["--proxy-server=arg-user:arg-pass@proxy.test".into()],
..Default::default()
}
);
for secret in [
"embedded-user",
"embedded-pass",
"named-user",
"named-pass",
"arg-user",
"arg-pass",
] {
assert!(!printed.contains(secret), "{secret} leaked: {printed}");
}
assert!(printed.contains("password: Some(<redacted>)"));
let plain = StealthConfig {
proxy: Some(Proxy::new("http://proxy.test:8080")),
..Default::default()
};
let printed = format!("{plain:?}");
assert!(printed.contains("http://proxy.test:8080"), "{printed}");
assert!(printed.contains("password: None"), "{printed}");
assert!(format!("{:?}", StealthConfig::default()).contains("proxy: None"));
}
#[test]
fn debug_output_omits_values_from_actions_and_network_types() {
use crate::{Action, BrowserFetchRequest, CapturedRequest, Expectation, LocatorSpec};
let headers = std::collections::HashMap::from([("Cookie".into(), "header-secret".into())]);
let printed = format!(
"{:?} {:?} {:?} {:?} {:?} {:?} {:?}",
Action::Fill {
target: LocatorSpec::css("#pw"),
value: "value-secret".into(),
input_mode: Default::default(),
},
Action::NavigateWithHeaders {
url: "https://x.test/?t=url-secret".into(),
headers: headers.clone(),
},
Expectation::Value {
target: LocatorSpec::css("#pw"),
value: "value-secret".into(),
},
CapturedRequest {
request_id: "1".into(),
url: "https://x.test/?t=url-secret".into(),
method: "POST".into(),
headers: headers.clone(),
post_data: Some("body-secret".into()),
resource_type: None,
status: None,
status_text: None,
response_headers: Some(headers.clone()),
mime_type: None,
timestamp: 0.0,
complete: false,
},
crate::NetworkEvent::ResponseReceived {
request_id: "1".into(),
status: 200,
status_text: "OK".into(),
headers: headers.clone(),
mime_type: None,
},
BrowserFetchRequest {
headers,
body: Some("body-secret".into()),
..BrowserFetchRequest::get("https://x.test/?t=url-secret")
},
crate::ResponseBody::Text("body-secret".into()),
);
for secret in ["value-secret", "url-secret", "header-secret", "body-secret"] {
assert!(!printed.contains(secret), "{secret} leaked: {printed}");
}
assert!(printed.contains("Cookie"), "header names stay useful");
}
#[test]
fn default_config_is_headless() {
assert!(StealthConfig::default().headless);
}
#[test]
fn binary_patching_is_opt_in() {
assert!(!StealthConfig::default().patch_binary);
assert!(!StealthConfig::visible().patch_binary);
assert!(!StealthConfig::debug().patch_binary);
}
#[test]
fn visible_configs_are_explicitly_not_headless() {
assert!(!StealthConfig::visible().headless);
assert!(!StealthConfig::debug().headless);
}
}