From 63ef5448e1be93649305eb3536e8d045772d1ec9 Mon Sep 17 00:00:00 2001 From: Acelya Date: Wed, 27 Mar 2024 11:12:52 +0000 Subject: [PATCH] feat(browser): add a function to disable easy automation detection Use the `--disable-blink-features=AutomationControlled` arg to set `navigator.webdriver` to `false`. --- src/browser.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/browser.rs b/src/browser.rs index d939e9f..0954526 100644 --- a/src/browser.rs +++ b/src/browser.rs @@ -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)] @@ -637,6 +640,7 @@ pub struct BrowserConfigBuilder { disable_default_args: bool, request_intercept: bool, cache_enabled: bool, + hidden: bool, } impl BrowserConfig { @@ -670,6 +674,7 @@ impl Default for BrowserConfigBuilder { disable_default_args: false, request_intercept: false, cache_enabled: true, + hidden: false, } } } @@ -816,6 +821,11 @@ impl BrowserConfigBuilder { self } + pub fn hide(mut self) -> Self { + self.hidden = true; + self + } + pub fn build(self) -> std::result::Result { let executable = if let Some(e) = self.executable { e @@ -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, }) } } @@ -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); }