Skip to content

Commit

Permalink
feat(browser): add a function to disable easy automation detection
Browse files Browse the repository at this point in the history
Use the `--disable-blink-features=AutomationControlled` arg to set `navigator.webdriver` to `false`.
  • Loading branch information
Acelya-9028 committed Mar 27, 2024
1 parent 6dfac53 commit 63ef544
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@ pub struct BrowserConfig {

/// Whether to enable cache
pub cache_enabled: bool,

/// Avoid easy bot detection by setting `navigator.webdriver` to false
hidden: bool,
}

#[derive(Debug, Clone)]
Expand All @@ -637,6 +640,7 @@ pub struct BrowserConfigBuilder {
disable_default_args: bool,
request_intercept: bool,
cache_enabled: bool,
hidden: bool,
}

impl BrowserConfig {
Expand Down Expand Up @@ -670,6 +674,7 @@ impl Default for BrowserConfigBuilder {
disable_default_args: false,
request_intercept: false,
cache_enabled: true,
hidden: false,
}
}
}
Expand Down Expand Up @@ -816,6 +821,11 @@ impl BrowserConfigBuilder {
self
}

pub fn hide(mut self) -> Self {
self.hidden = true;
self
}

pub fn build(self) -> std::result::Result<BrowserConfig, String> {
let executable = if let Some(e) = self.executable {
e
Expand All @@ -841,6 +851,7 @@ impl BrowserConfigBuilder {
disable_default_args: self.disable_default_args,
request_intercept: self.request_intercept,
cache_enabled: self.cache_enabled,
hidden: self.hidden,
})
}
}
Expand Down Expand Up @@ -901,6 +912,10 @@ impl BrowserConfig {
cmd.arg("--incognito");
}

if self.hidden {
cmd.arg("--disable-blink-features=AutomationControlled");
}

if let Some(ref envs) = self.process_envs {
cmd.envs(envs);
}
Expand Down

0 comments on commit 63ef544

Please sign in to comment.