mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.21k stars 1.53k forks source link

Unable to install extensions into profile, fails with warning: "not correctly signed" #1225

Open nddipiazza opened 6 years ago

nddipiazza commented 6 years ago

System

Testcase

Download https://addons.mozilla.org/firefox/downloads/file/897501/ajax_requestcounter-1.0-an+fx.xpi?src=dp-btn-primary

Add the extension from selenium:

FirefoxOptions options = new FirefoxOptions();
firefoxProfile.addExtension(new File("/home/ndipiazza/Downloads/ajax_requestcounter-1.0-an+fx.xpi"));
options.setProfile(firefoxProfile);
WebDriver driver = new FirefoxDriver(options);

Plugin will not install. Logs say:

1521570438589   addons.xpi  WARN    Add-on ajax-requestcounter@1.0 is not correctly signed.
1521570438589   addons.xpi  WARN    Add-on ajax-requestcounter@1.0 is not correctly signed.
1521570438589   addons.xpi  WARN    Add-on ajax-requestcounter@1.0 is not correctly signed.

This all works fine when running in dev-mode or nightly firefox.

Plugin works fine when installed manually in Firefox, or through the addons "add to firefox" link.

Trace-level log

https://gist.github.com/nddipiazza/3c42b705dd76a45d86fc944e48129045

andreastt commented 6 years ago

Does it install correctly in Nightly?

nddipiazza commented 6 years ago

yes. updated desc to include that. @andreastt

andreastt commented 6 years ago

That probably means this isn’t a geckodriver issue, but a signing issue with your add-on.

nddipiazza commented 6 years ago

@andreastt weird. i signed it through the addons.mozilla.org site (not self-signed). do you know if there is someone i can email about this?

andreastt commented 6 years ago

I would file a bug in the WebExtensions component in Bugzilla.

nddipiazza commented 6 years ago

@andreastt is there a back-door way to install this extension? Like get the path of the profile then add the xpi to a folder and .... something like that?

andreastt commented 6 years ago

You can try the /session/{session id}/moz/addon/install endpoint: it takes a payload of a JSON Object with either the addon field containing a string with the Base64-encoded addon, or a path string to the location of the .xpi file.

andreastt commented 6 years ago

After some investigation on IRC, @nddipiazza discovered this is a problem with installing an addon into the Firefox profile. Using the addon extension command mentioned in https://github.com/mozilla/geckodriver/issues/1225#issuecomment-374987968 works fine.

nddipiazza commented 6 years ago

This is the workaround i was able to get going with:

driver = new FirefoxDriver(geckoDriverService, options);
URL geckoDriverServiceUrl = geckoDriverService.getUrl();
                CloseableHttpClient client = HttpClientBuilder.create().build();
                HttpPost httpPost = new HttpPost(geckoDriverServiceUrl.toString() + "/session/" + driver.getSessionId
                    () + "/moz/addon/install");
                httpPost.setEntity(new StringEntity(String.format("{\"path\": \"%s\"}",
                    requestCounterFile.getAbsolutePath())));
                CloseableHttpResponse response = client.execute(httpPost);
andreastt commented 6 years ago
  1. It would be good to have support for the addon installation/deletion extension directly in the Java client. Someone should submit a patch for it to Selenium.

  2. We need to investigate, possibly file a bug against the web extensions component in Bugzilla, about why addons installed in the profile are considered unsafe. In relation to this, what is the observable difference between a profile where you manually install the addon and one that has a signed addon installed through the UI?

miksch123 commented 1 year ago

This is something that has worked for me:

        //create service
        FirefoxDriverService service = FirefoxDriverService.CreateDefaultService("./");
        service.Host = "::1";
        service.HideCommandPromptWindow = true;
        service.Port = 4444;
        service.Start();
        //Create a FirefoxDriver instance (IWebdriver does not have InstallAddonFromDirectory method available.)
        FirefoxDriver driver = new FirefoxDriver(service);
        string extractedPath = @"C:\path\to\extensionfolderwheremanifestfileis"; // Replace with the path where you want to 

        //add unpacked extension (has worked better for this example. you can unzip using c# code in beforehand)
        driver.InstallAddOnFromDirectory(extractedPath, true);
        driver.Navigate().GoToUrl("https://www.example.com");
        Thread.Sleep(5000);

        // Close the browser
        driver.Quit();
        //stop geckodriver process instance you have started before.

Removed the options part of the code as per comment https://github.com/mozilla/geckodriver/issues/1225#issuecomment-1514454655

whimboo commented 1 year ago

Dupe of issue #1225.

whimboo commented 1 year ago

--allow-unsigned-xpi is not an available command line argument for Firefox. As such it will not work to install this addon. See this comment in how to get the addon installed temporarily.