C# 如何在Chrome浏览器&x27;什么是地方州档案?

C# 如何在Chrome浏览器&x27;什么是地方州档案?,c#,selenium-chromedriver,C#,Selenium Chromedriver,这是我在本地州文件中的内容: { ... "browser": { "enabled_labs_experiments": [ "force-compositing-mode-2@1" ], "hung_plugin_detect_freq": 2000, "last_redirect_origin": "", "plugin_message_response_timeout": 25000 }, ... } 我想让Chr

这是我在本地州文件中的内容:

{
   ...
   "browser": {
      "enabled_labs_experiments": [ "force-compositing-mode-2@1" ],
      "hung_plugin_detect_freq": 2000,
      "last_redirect_origin": "",
      "plugin_message_response_timeout": 25000
   },
   ...
}
我想让ChromeDriver加载我的“启用的实验室实验”设置。 这就是我在C中尝试做的:


…它不太管用。你知道我的代码有什么问题吗?

我知道java的方法。希望它能帮助你。这个答案可以在这里找到。 Chrome扩展可以打包也可以解包。压缩扩展名是扩展名为.crx的单个文件。解包扩展是包含扩展的目录,包括manifest.json文件

要打包未打包的扩展,请使用中的“打包”按钮chrome://extensions 或者使用Chrome:“Chrome.exe--pack extension=C:\path\to\unpacket\extension--pack extension key=C:\myext.pem”。请参阅扩展文档,了解其他更方便自动化的方法。要解压打包的扩展名,只需解压文件(您可能需要将文件从.crx重命名为.zip,zip实用程序才能识别它)。 通过ChromeDriver安装扩展插件

打包(.crx文件)

解包(目录)

ChromeOptions options = new ChromeOptions();
options.AddArgument("--start-maximized");
options.AddArgument("--disable-logging");
Dictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("enabled_labs_experiments", "[ force-compositing-mode-2@1 ]");
options.AddAdditionalCapability("localState", dict);
driver = new ChromeDriver(options);
dict.Add("enabled_labs_experiments", "force-compositing-mode-2@1");
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
ChromeOptions options = new ChromeOptions();
options.addArguments("load-extension=/path/to/extension");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);