private void ConfigureDriver(ChromeDriver driver, IWebDriverOptions webDriverOptions) { if (webDriverOptions.Stealth) { driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.utils); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.chrome_app); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.chrome_runtime); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.iframe_contentWindow); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.media_codecs); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_languages); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_permissions); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_plugins); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_vendor); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_webdriver); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.webgl_vendor); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.window_outerdimensions); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_hardwareConcurrency); //driver.AddScriptToEvaluateOnNewDocument("(() => { utils = undefined; })();"); } driver.Manage().Window.Position = webDriverOptions.WindowPosition; }
private static IWebDriver CreateChromeWebDriver(IWebBrowserInfo webBrowserInfo, IWebDriverOptions webDriverOptions) { string webDriverExecutablePath = GetFullWebDriverExecutablePath(webDriverOptions.WebDriverExecutablePath); // Create the driver service. ChromeOptions driverOptions = new ChromeOptions { BinaryLocation = webBrowserInfo.ExecutablePath }; ChromeDriverService driverService = string.IsNullOrEmpty(webDriverExecutablePath) ? ChromeDriverService.CreateDefaultService() : ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(webDriverExecutablePath)); driverService.HideCommandPromptWindow = true; if (webDriverOptions.Headless) { driverOptions.AddArgument("--headless"); } if (!string.IsNullOrEmpty(webDriverOptions.UserAgent)) { driverOptions.AddArgument($"--user-agent={webDriverOptions.UserAgent}"); } if (!webDriverOptions.Proxy.IsEmpty()) { driverOptions.AddArgument($"--proxy-server={webDriverOptions.Proxy.GetProxyString()}"); } driverOptions.PageLoadStrategy = (OpenQA.Selenium.PageLoadStrategy)webDriverOptions.PageLoadStrategy; // Resize the window to a reasonable resolution so that viewport matches a conventional monitor viewport. driverOptions.AddArgument($"--window-size={webDriverOptions.WindowSize.Width},{webDriverOptions.WindowSize.Height}"); driverOptions.AddArgument($"--window-position={webDriverOptions.WindowPosition.X},{webDriverOptions.WindowPosition.Y}"); // Disable the "navigator.webdriver" property. driverOptions.AddArgument("--disable-blink-features=AutomationControlled"); ChromeDriver driver = new ChromeDriver(driverService, driverOptions); if (webDriverOptions.Stealth) { driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.utils); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.chrome_app); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.chrome_runtime); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.iframe_contentWindow); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.media_codecs); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_languages); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_permissions); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_plugins); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_vendor); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_webdriver); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.webgl_vendor); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.window_outerdimensions); driver.AddScriptToEvaluateOnNewDocument(Properties.Resources.navigator_hardwareConcurrency); //driver.AddScriptToEvaluateOnNewDocument("(() => { utils = undefined; })();"); } return(driver); }