You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C# Selenium:如何结合Chrome配置文件与代理启动浏览器

How to Get Chrome User Profile + Proxy Working Together in Selenium

Got it, let's fix this so both your custom Chrome profile and proxy are active when you launch the driver. The commented profile line was almost right—we just need to uncomment it, tweak a few things to avoid conflicts, and ensure everything is configured correctly.

Working Code with Explanations

string IPtoUse = richTextBox2.Lines[0];
ChromeOptions options = new ChromeOptions();

// Enable your user profile (uncommented and formatted correctly)
options.AddArguments(@"user-data-dir=C:\Users\Kamil\AppData\Local\Google\Chrome\User Data");
// Optional: If you want to use a specific non-default profile (e.g., Profile 1), add this:
// options.AddArguments(@"--profile-directory=Profile 1");

// Keep your existing proxy setup—it's already correct
var proxy = new Proxy();
proxy.Kind = ProxyKind.Manual;
proxy.IsAutoDetect = false;
proxy.HttpProxy = proxy.SslProxy = IPtoUse;
options.Proxy = proxy;

// Retain your certificate error ignore flag
options.AddArgument("ignore-certificate-errors");

// Initialize the driver with all configured options
var Driver = new ChromeDriver(options);

Critical Tips to Avoid Headaches

  • Close All Chrome Windows First: Chrome locks its user data directory when any instance is open. If you have Chrome running in the background, the driver will throw an error when trying to load the profile. Make sure to kill all Chrome processes before running your code.
  • Double-Check the Profile Path: Confirm C:\Users\Kamil\AppData\Local\Google\Chrome\User Data is the correct path for your Windows user account. Replace "Kamil" with your own username if needed.
  • Use Verbatim Strings: The @ before the path string prevents escape character issues (so \ doesn't get misinterpreted as a special character).
  • Target Specific Profiles (Optional): If you have multiple Chrome profiles set up, use --profile-directory=Profile X to pick a specific one instead of the default. This is handy if you don't want to mess with your main browsing profile.

Give this a test run—your proxy should still work, and Chrome should load with all your saved bookmarks, extensions, and settings from the specified profile. If you hit issues with the profile not loading, double-check the path and make sure Chrome isn't running in the background.

内容的提问来源于stack exchange,提问作者SergioRamos78

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:36:11