【问题标题】:How to disable ALL chrome extensions using chromedriver如何使用 chromedriver 禁用所有 chrome 扩展
【发布时间】:2019-10-09 21:55:31
【问题描述】:

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

  1. 启动 chromedriver
chromedriver --log-level=ALL
  1. 使用已禁用的扩展创建会话
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- popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --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" 数据:,

注意

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

有没有办法摆脱它?在 chromedriver 文档中没有找到任何线索,这些非常粗略。

【问题讨论】:

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


【解决方案1】:

TL;DR

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

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

加长版

chromedriver docs 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 中提到的,使用 selenium 驱动程序的 Java 代码将是

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2020-07-04
    • 2012-12-12
    • 2018-06-22
    • 2022-10-19
    • 1970-01-01
    • 2013-04-02
    相关资源
    最近更新 更多