如何使用chromedriver禁用所有chrome扩展

时间:2019-05-23 10:32:15

标签: selenium selenium-chromedriver chrome-automation-extension

升级到chromedriver 74后,发现Windows上的奇数扩展行为。 是否可以关闭所有扩展名?

  1. 启动chromedriver
chromedriver --log-level=ALL
  1. 创建扩展名为DISABLED的会话
curl -d '{"desiredCapabilities":{"browserName":"chrome","goog:chromeOptions":{"args":["--disable-extensions"]}}}' http://localhost:9515/session

某些开发工具扩展已加载

  

[1558606783.990] [INFO]:正在启动chrome:“ C:\ Program Files(x86)\ Google \ Chrome \ Application \ chrome.exe” --disable-background-networking --disable-client-side-phishing-检测--disable-default-apps --disable-extensions --disable-extensions-except =“ C:\ Users \ user \ AppData \ Local \ Temp \ scoped_dir19964_411 \ internal” --disable-hang-monitor --disable-弹出窗口阻止-禁用重新启动提示-禁用同步-禁用Web资源-启用自动化-启用眨眼功能= ShadowDOMV0-启用日志记录--force-fieldtrials = SiteIsolationExtensions / Control --ignore-certificate-errors --log-level = 0 --no-first-run --password-store = basic --remote-debugging-port = 0 --test-type = webdriver --use-模拟钥匙串--user-data-dir =“ C:\ Users \ user \ AppData \ Local \ Temp \ scoped_dir19964_22650” data:,

注意

  

-disable-extensions-except =“ C:\ Users \ user \ AppData \ Local \ Temp \ scoped_dir19964_411 \ internal”

是否有摆脱它的方法?在chromedriver文档中找不到任何线索,这些线索非常粗略。

1 个答案:

答案 0 :(得分:0)

TL; DR

chromeOptions.useAutomationExtension设置为false,将阻止注入Chrome自动化扩展

{
  "desiredCapabilities": {
    "browserName": "chrome",
    "goog:chromeOptions": {
      "useAutomationExtension": false,
      "args": [
        "--disable-extensions"
      ]
    }
  }
}

长版

chromedriver文档http://chromedriver.chromium.org/capabilities中未提及自动化扩展标志,但可以在source code中跟踪当前版本(75.0。)

    parser_map["useAutomationExtension"] =
        base::Bind(&ParseBoolean, &capabilities->use_automation_extension);
    status = internal::ProcessExtensions(
        capabilities.extensions, extension_dir->GetPath(),
        capabilities.use_automation_extension, &switches, extension_bg_pages);
  if (include_automation_extension) {
    ...
    if (switches->HasSwitch("disable-extensions")) {
      UpdateExtensionSwitch(switches, "disable-extensions-except",
                            automation_extension.value());

54594305中所述,使用硒驱动程序的Java代码将是

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);