如何在Chrome选项中添加Chrome浏览器的本地状态文件中的首选项功能?



这是我的本地状态文件中的内容:

{
   ...
   "browser": {
      "enabled_labs_experiments": [ "force-compositing-mode-2@1" ],
      "hung_plugin_detect_freq": 2000,
      "last_redirect_origin": "",
      "plugin_message_response_timeout": 25000
   },
   ...
}

我希望ChromeDriver加载我的"enabled_labs_experiments"设置。这就是我试图在 C# 中做的事情:

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);

我认为我的代码在使用 Chrome 浏览器浏览 chrome://flags 时不起作用,该设置仍然显示"默认"而不是"启用"。

我还尝试将我的代码更改为:

dict.Add("enabled_labs_experiments", "force-compositing-mode-2@1");

。它也不行。知道我的代码有什么问题吗?

我用java的方式。希望它能帮助你。这个答案可以在 https://sites.google.com/a/chromium.org/chromedriver/extensions 在这里找到。Chrome 扩展程序可以打包,也可以解压缩。 打包扩展名是具有.crx扩展名的单个文件。 解压缩的扩展是包含扩展的目录,包括 manifest.json 文件。

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

打包(.crx文件)

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);

最新更新