Java 管理员禁止加载解压扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43571119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 01:01:08  来源:igfitidea点击:

Loading of unpacked extensions is disabled by the administrator

javaseleniumgoogle-chromeselenium-chromedriverchrome-automation-extension

提问by user7836878

When am running my webdriver script, am getting a confirmation dialog box with below message:

当我运行我的 webdriver 脚本时,我收到一个带有以下消息的确认对话框:

Error Loading Extension

Could not load extension from 'C:\Users\username\AppData\Local\Temp\scoped_dir6312_32763\internal'. Loading of unpacked extensions is disabled by the administrator.

Would you like to retry?

Yes No

加载扩展时出错

无法从“C:\Users\username\AppData\Local\Temp\scoped_dir6312_32763\internal”加载扩展。管理员禁止加载未打包的扩展。

您想重试吗?

是 否

Clicking "yes" lets the tests run.

单击“是”让测试运行。

I am not sure why am I getting this dialog box prompted,

我不知道为什么会提示这个对话框,

I've tried the mentioned workarounds below but neither of them are working:

我已经尝试了下面提到的解决方法,但它们都不起作用:

  1. Replaced chrome driver with latest version.
  2. Added below code in my script:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("no-sandbox");
    options.addArguments("disable-extensions");
    driver = new ChromeDriver(options);
    
  1. 用最新版本替换了 chrome 驱动程序。
  2. 在我的脚本中添加了以下代码:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("no-sandbox");
    options.addArguments("disable-extensions");
    driver = new ChromeDriver(options);
    

Below is my Test method:

下面是我的测试方法:

public void Login() throws IOException{
    test = extent.startTest("Login");
    signInPage = new SignInPage(driver);
    signInPage.enterMailId();   
    String screenShotPath = GetScreenShot.capture(driver, "enterMailId");
    test.log(LogStatus.PASS, "Email id is entered successfully: " + test.addScreenCapture(screenShotPath));
    signInPage.enterpwd();
    //test.log(LogStatus.INFO, "Password is entered successfully");
    screenShotPath = GetScreenShot.capture(driver, "enterpwd");
    test.log(LogStatus.PASS, "Password is entered successfully: " + test.addScreenCapture(screenShotPath));
    signInPage.clickOnLogin();
    test.log(LogStatus.PASS, "User logged in successfully");
}

Below is the method which invoke the browser:

下面是调用浏览器的方法:

private  void initChromeBrowser(){
    System.setProperty("webdriver.chrome.driver", userdir +"\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("test-type");
    options.addArguments("no-sandbox");
    //Fix for cannot get automation extension
    options.addArguments("disable-extensions");
    options.addArguments("start-maximized");
    options.addArguments("--js-flags=--expose-gc");         
    options.addArguments("disable-plugins");
    options.addArguments("--enable-precise-memory-info"); 
    options.addArguments("--disable-popup-blocking");
    options.addArguments("--disable-default-apps");
    options.addArguments("test-type=browser");
    options.addArguments("disable-infobars");
    driver = new ChromeDriver(options);
    launchApp();
}

Could there be anything else that I should incorporate in my script to prevent the dialog box.

我应该在脚本中加入任何其他内容来阻止对话框。

回答by jersey-city-ninja

I encountered this same issue after upgrading to ChromeDriver v2.29. I have Chrome v58.0. It looks like an open issue: https://bugs.chromium.org/p/chromedriver/issues/detail?id=639#c26

升级到 ChromeDriver v2.29 后,我遇到了同样的问题。我有 Chrome v58.0。它看起来像一个未解决的问题:https: //bugs.chromium.org/p/chromedriver/issues/detail?id=639#c26

Depending on your versions, YMMV, in my case, I had to downgrade to ChromeDriver v2.27.

根据您的版本,YMMV,就我而言,我不得不降级到 ChromeDriver v2.27。

回答by Swetha Kandimalla

You can set the useAutomationExtensioncapability to false.

您可以将useAutomationExtension功能设置为 false。

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

This capability will help to not load Chrome Automation extension. Due to which, "Failed to load extension"popup would not appear.

此功能将有助于不加载 Chrome 自动化扩展程序。因此,不会出现“加载扩展失败”弹出窗口。

But please note you will not be able to perform any window resizing/positioning operations without the Chrome automation extension.

但请注意,如果没有 Chrome 自动化扩展程序,您将无法执行任何窗口大小调整/定位操作。

Hope this helps!

希望这可以帮助!

Source : https://bugs.chromium.org/p/chromedriver/issues/detail?id=1749

来源:https: //bugs.chromium.org/p/chromedriver/issues/detail?id=1749

回答by wwjih123

If you go to chrome://version/you can see under the Command:

如果你去chrome://version/你可以在命令下看到:

C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-extensions-except="C:\Users\Inno3\AppData\Local\Temp\scoped_dir80288_6333\internal" --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --ignore-certificate-errors --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12354 --safebrowsing-disable-auto-update --start-maximized --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\Inno3\AppData\Local\Temp\scoped_dir80288_30914" --flag-switches-begin --flag-switches-end data:,

C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-extensions-except="C:\Users\Inno3\AppData\Local\Temp\scoped_dir80288_6333\internal" --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --ignore-certificate-errors --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12354 --safebrowsing-disable-auto-update --start-maximized --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\Inno3\AppData\Local\Temp\scoped_dir80288_30914" --flag-switches-begin --flag-switches-end data:,

This is why it throw error, I don't know why it give error, maybe user policy or Chrome updates?

这就是它抛出错误的原因,我不知道为什么它会给出错误,也许是用户政策或 Chrome 更新?

--disable-extensions-except="C:\Users\Inno3\AppData\Local\Temp\scoped_dir80288_6333\internal"

--disable-extensions-except="C:\Users\Inno3\AppData\Local\Temp\scoped_dir80288_6333\internal"

I believe the argument is added by Selenium, you need the following command to tell selenium to not add it.

我相信该参数是由 Selenium 添加的,您需要以下命令来告诉 selenium 不要添加它。

In C#:

在 C# 中:

chromeOptions = OpenQA.Selenium.Chrome.ChromeOptions();
chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
river = new ChromeDriver(chromeOptions);
launchApp();

In Java:

在 Java 中:

chromeOptions.AddAdditionalCapability("useAutomationExtension", false)

回答by Srihari

//Set the system property for chrome browser location
    System.setProperty("webdriver.chrome.driver", Global.sChromeDriverPath);
    //Set the Chrome capabilities
    ChromeOptions options = new ChromeOptions();
       options.addArguments("test-type");
       options.addArguments("start-maximized");
       options.addArguments("--js-flags=--expose-gc");
       options.addArguments("--enable-precise-memory-info");
       options.addArguments("--disable-popup-blocking");
       options.addArguments("--disable-default-apps");
       options.addArguments("--enable-automation");
       options.addArguments("test-type=browser");
       options.addArguments("disable-infobars");
       options.addArguments("disable-extensions");
       options.setExperimentalOption("useAutomationExtension", false);
       Global.driver = new ChromeDriver(options);

回答by minihunter97

I tried a bunch of things like removing the * entry of Chrome blacklist in Windows registry (which is a painful hack because it will be reversed back couple times a week by the company group policy). I finally came up with the working solution. With the following code, the "error loading extension" pop up isn't showing up any more.

我尝试了很多事情,比如删除 Windows 注册表中 Chrome 黑名单的 * 条目(这是一个痛苦的黑客,因为它每周会被公司组策略逆转几次)。我终于想出了可行的解决方案。使用以下代码,“错误加载扩展”弹出窗口不再显示。

${options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
Call Method    ${options}    add_argument    --start-maximized
Call Method    ${options}    add_experimental_option  useAutomationExtension  ${False}
Create WebDriver    Chrome    chrome_options=${options}

回答by Shirish Nagar

Below code is working fine for me chrome driver 2.41 and browser version 68.0.3440.84

下面的代码对我来说工作正常 chrome 驱动程序 2.41 和浏览器版本 68.0.3440.84

public class patCheck {

  WebDriver driver;

  @Test
  public void f() {

      System.setProperty("webdriver.chrome.driver", "C:\Users\shirish.nagar\Work\Selenium\Web\Drivers\chromedriver.exe");

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

      driver.manage().window().maximize();
      driver.get("https://www.google.com");
  }
}

It successfully invokes the chrome browser without any pop-up of "loading unpacked extension disabled by administrator"

成功调用chrome浏览器,没有弹出“加载管理员禁用的解压扩展”

回答by Roman Torskyi

    ChromeOptions options = new ChromeOptions();
    System.setProperty("webdriver.chrome.driver", "C:\drivers\chromedriver.exe");

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

回答by DebanjanB

This error message...

这个错误信息...

Error Loading Extension

Could not load extension from 'C:\Users\username\AppData\Local\Temp\scoped_dir6312_32763\internal'. Loading of unpacked extensions is disabled by the administrator.

Would you like to retry?

Yes No

加载扩展时出错

无法从“C:\Users\username\AppData\Local\Temp\scoped_dir6312_32763\internal”加载扩展。管理员禁止加载未打包的扩展。

您想重试吗?

是 否

...implies that an extension was not been loaded as it was disabled by the administrator.

...表示未加载扩展程序,因为它已被管理员禁用。

As per Issue 1749: Failed to load extention from: ... Loading of unpacked extensions is disabled by the administratorChromeDriveruses Chrome automation extensionfor automating various functions like window sizing, window positioning, etc.

根据问题 1749:无法从以下位置加载扩展:...管理员禁止加载未打包的扩展ChromeDriver使用Chrome 自动化扩展来自动执行各种功能,例如窗口大小调整、窗口定位等。

The Failed to load extension..popup means that this extension has not been loaded. If you manually close the popup, browser will act normally and ChromeDrivercommands will continue to work as expected. But in this case if you try executing window resizing or window re-positioning commands, it will throw an error as unknown error: cannot get automation extension.

无法加载扩展..弹出意味着该扩展还没有被加载。如果您手动关闭弹出窗口,浏览器将正常运行,ChromeDriver命令将继续按预期工作。但是在这种情况下,如果您尝试执行窗口大小调整或窗口重新定位命令,则会抛出错误为unknown error: cannot get automation extension.

Till ChromeDriver v2.28whenever an organizations admin policy forbidden extensions, to bypass the restriction users have used the argument disable-extensionsas follows:

直到ChromeDriver v2.28每当组织管理策略禁止扩展时,为了绕过限制,用户都使用disable-extensions如下参数:

ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);

and it worked perfecto.

它完美地工作。

ChromeDriver v2.28onwards, whenever disable-extensionsflag is passed by test, ChromeDriverimplicitly passes disable-extensions-exceptflag which in turn loads Chrome automation extension. This extension helps Chromedriver to perform window sizing and window re-positioning operations.

从 ChromeDriver v2.28开始,每当disable-extensions测试通过标志时,ChromeDriver 会隐式传递disable-extensions-except标志,进而加载Chrome 自动化扩展。此扩展程序帮助 Chromedriver 执行窗口大小调整和窗口重新定位操作。

So, if your organizational admin policy blocks extensions, display of popup Failed to load extension from: ... Loading of unpacked extensionsis an expected behavior.

因此,如果您的组织管理策略阻止扩展,弹出无法从以下位置加载扩展的显示:...加载解压缩的扩展是预期行为。

This issue had a dependency on Selenium support for headless.

此问题依赖于Selenium 对 headless 的支持

As an alternative, you can set the useAutomationExtensioncapability to falseas follows:

作为替代方案,您可以将useAutomationExtension功能设置false如下:

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

This capability inturn will help to not load Chrome Automation extensionand Failed to load extensionpopup would not appear. But you will not be able to perform any window resizing/positioning operations without the Chrome automation extension.

此功能反过来将有助于不加载Chrome 自动化扩展程序,并且Failed to load extension不会出现弹出窗口。但是,如果没有Chrome 自动化扩展,您将无法执行任何窗口大小调整/定位操作。

Now, Selenium support for headlessbeing resolved ChromeDriverwill no longer require this extension and you shouldn't have seen this error/popup.

现在,Selenium 支持无头解决ChromeDriver将不再需要此扩展程序,您不应该看到此错误/弹出窗口。

Solution

解决方案

The simplest solution would be to use the latest version of ChromeDriverand Chromecombination among either of the following:

最简单的解决方案是在以下任一选项中使用最新版本的ChromeDriverChrome组合:

  • If you are using Chrome version 73, please download ChromeDriver 73.0.3683.20
  • If you are using Chrome version 72, please download ChromeDriver 2.46or ChromeDriver 72.0.3626.69
  • If you are using Chrome version 71, please download ChromeDriver 2.46or ChromeDriver 71.0.3578.137
  • For older version of Chrome, please see this discussion.
  • 如果您使用的是Chrome 73 版,请下载ChromeDriver 73.0.3683.20
  • 如果您使用的是Chrome 72 版,请下载ChromeDriver 2.46ChromeDriver 72.0.3626.69
  • 如果您使用的是Chrome 71 版,请下载ChromeDriver 2.46ChromeDriver 71.0.3578.137
  • 对于旧版本的 Chrome,请参阅此讨论

Alternative

选择

Some other alternatives are:

其他一些替代方案是:

  • Add the Registry KeyExtensionInstallWhitelistto whitelist
  • Remove the Registry KeyExtensionInstallBlacklistcontaining a string key 1with value *
  • 注册表项添加ExtensionInstallWhitelist到白名单
  • 删除包含值为1的字符串键的注册表ExtensionInstallBlacklist*

回答by Shubham Jain

Below code works for me:

下面的代码对我有用:

Set useAutomationExtension as false

将 useAutomationExtension 设置为 false

options.setExperimentalOption("useAutomationExtension", false);

Fulll code:

完整代码:

    System.setProperty("webdriver.chrome.driver", "C:\Selenium Drivers\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setAcceptInsecureCerts(true);
    options.merge(capabilities);
    options.addArguments("--test-type");
    options.addArguments("start-maximized");
    options.addArguments("--js-flags=--expose-gc");
    options.addArguments("--enable-precise-memory-info");
    options.addArguments("--disable-popup-blocking");
    options.addArguments("--disable-default-apps");
    options.addArguments("--enable-automation");
    options.addArguments("disable-extensions");
    options.setExperimentalOption("useAutomationExtension", false);
    options.addArguments("--disable-dev-shm-usage");
    options.addArguments("--no-sandbox");
    options.addArguments("disable-infobars");
    driver = new ChromeDriver(options);
    driver.get("https://www.google.com/");

回答by Thiago Soares

On my company we have a GPO that block all extensions on chrome with the ExtensionInstallBacklist. So to avoid this we change the blocked extentensions registry key from * (all) to a random value (foobar).

在我的公司,我们有一个 GPO,它使用ExtensionInstallBacklist阻止 chrome 上的所有扩展。因此,为了避免这种情况,我们将阻止的扩展注册表项从 * (all) 更改为随机值 (foobar)。

To do that you can create a .reg file with this content:

为此,您可以使用以下内容创建一个 .reg 文件:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\ExtensionInstallBlacklist]
"1"="lala"