private void SetupChromeDriver(Access access, string username, string server) { ChromeOptions options = new ChromeOptions(); // Turn on logging preferences for buildings localization (string). //var loggingPreferences = new OpenQA.Selenium.Chromium.ChromiumPerformanceLoggingPreferences(); //loggingPreferences.IsCollectingNetworkEvents = true; //options.PerformanceLoggingPreferences = loggingPreferences; //options.SetLoggingPreference("performance", LogLevel.All); if (!string.IsNullOrEmpty(access.Proxy)) { if (!string.IsNullOrEmpty(access.ProxyUsername)) { // Add proxy authentication var extensionPath = ProxyHelper.CreateExtension(username, server, access); options.AddExtension(extensionPath); } options.AddArgument($"--proxy-server={access.Proxy}:{access.ProxyPort}"); options.AddArgument("ignore-certificate-errors"); } if (!string.IsNullOrEmpty(access.UserAgent)) { options.AddArgument("--user-agent=" + access.UserAgent); } //options.AddArguments("--disable-logging"); //options.AddArguments("--disable-metrics"); //options.AddArguments("--disable-dev-tools"); //options.AddArguments("--disable-gpu-shader-disk-cache"); //options.AddArguments("--aggressive-cache-discard"); //options.AddArguments("--arc-disable-gms-core-cache"); // Mute audio because of the Ads options.AddArguments("--mute-audio"); // Make browser headless to preserve memory resources if (acc.Settings.HeadlessMode) { options.AddArguments("headless"); } // Do not download images in order to preserve memory resources / proxy traffic if (acc.Settings.DisableImages) { options.AddArguments("--blink-settings=imagesEnabled=false"); //--disable-images } // Add browser caching var dir = IoHelperCore.GetCacheDir(username, server, access); Directory.CreateDirectory(dir); options.AddArguments("user-data-dir=" + dir); // Hide command prompt chromeService = ChromeDriverService.CreateDefaultService(); chromeService.HideCommandPromptWindow = true; try { if (acc.Settings.OpenMinimized) { options.AddArguments("--window-position=5000,5000"); this.Driver = new ChromeDriver(chromeService, options); this.Driver.Manage().Window.Position = new System.Drawing.Point(200, 200); // TODO: change coords? this.Driver.Manage().Window.Minimize(); } else { this.Driver = new ChromeDriver(chromeService, options); } // Set timeout this.Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(60); } catch (Exception e) { Log($"Error opening chrome driver! Is it already opened?", e); } }
private void InitHttpClient(Access a) => this.RestClient = HttpHelper.InitRestClient(a, this.acc.AccInfo.ServerUrl);