title: How to handle proxy authentication in Firefox with self-created extension using Selenium in Java?
body: <p>I followed @Mike solution provided at this topic <a href="https://stackoverflow.com/questions/8885137/selenium-using-python-enter-provide-http-proxy-password-for-firefox/35293222">Selenium using Python: enter/provide http proxy password for firefox</a>
  and it worked great to solve the proxy authentication issue on Chrome through the plugin.</p>
  
  <p>Now I'm facing the same problem with Firefox browser: i'm in Java, using Selenium and i'm trying to create an extension (packing it into .xpi), that would make the same job.</p>
  
  <p>So what i'm doing right now in my code is the following:<ul>- Taking from pojo's file a pre-written manifest.json and background.js and modifying the script inserting my proxy datas. This is how they appear:</p>
  
  <pre><code>**manifest.json
  {
  "version": "1.0.0",
  "manifest_version": 2,
  "name": "Firefox Proxy | (Proxy Connector)",
  "permissions": [
      "proxy",
      "tabs",
      "unlimitedStorage",
      "storage",
      "&lt;all_urls&gt;",
      "webRequest",
      "webRequestBlocking"
  ],
  "background": {
      "scripts": ["background.js"]
  }
  }
  
  **background.js
  var config = {
      mode: "fixed_servers",
      rules: {
        singleProxy: {
          scheme: "https",
          host: "%proxy_host",
          port: parseInt("%proxy_port")
        },
        bypassList: []
      }
    };
  
  firefox.proxy.settings.set({value: config, scope: "regular"}, function() {});
  
  function callbackFn(details) {
  return {
      authCredentials: {
          username: "%username",
          password: "%password"
      }
  };
  }
  
  firefox.webRequest.onAuthRequired.addListener(
          callbackFn,
          {urls: ["&lt;all_urls&gt;"]},
          ['blocking']
  );
  </code></pre>
  
  <p>- Creating a .zip file but naming it as .xpi <code>I read somewhere that should work, but i'm not too sure</code></p>
  
  <pre><code>try {
          FileOutputStream fos = new FileOutputStream("./src/temp/plugin.xpi");
          ZipOutputStream zipOS = new ZipOutputStream(fos);
  
          writeToZipFile(manifestTemp.toString(), zipOS);
          writeToZipFile(scriptModified.toString(), zipOS);
  
          zipOS.close();
          fos.close();
  
      } catch (IOException e2) {
          // TODO Auto-generated catch block
          e2.printStackTrace();
      }
  
  private void writeToZipFile(String path, ZipOutputStream zipOS) throws IOException {
      File aFile = new File(path); 
      FileInputStream fis = new FileInputStream(aFile); 
      ZipEntry zipEntry = new ZipEntry(aFile.getName()); 
      zipOS.putNextEntry(zipEntry); 
      byte[] bytes = new byte[1024]; 
      int length; 
  
      while ((length = fis.read(bytes)) &gt;= 0) { 
          zipOS.write(bytes, 0, length); 
          } 
  
      zipOS.closeEntry(); 
      fis.close();        
  }
  </code></pre>
  
  <p>- Set a Firefox profile, adding the extension and run the webdriver:</p>
  
  <pre><code>File extension = new File("./src/temp/plugin.xpi");
  
  System.setProperty("webdriver.gecko.driver", "./src/WebDriver/geckodriver.exe");
  FirefoxProfile profile = new FirefoxProfile();
  profile.addExtension(extension);
  profile.setPreference("extensions.firebug.onByDefault", true);
  profile.setPreference("xpinstall.signatures.required", false);
  FirefoxOptions options = new FirefoxOptions();
  options.setBinary(new FirefoxBinary()); //don't know if this is correct
  options.setProfile(profile);
  
  this.driver = new FirefoxDriver(options);
  </code></pre>
  
  <p></ul></p>
  
  <p>When I run all this, the following error code appear at driver declaration line:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" org.openqa.selenium.firefox.UnableToCreateProfileException: java.io.FileNotFoundException: ...%user%\AppData\Local\Temp\anonymous1577938325377124354webdriver-profile\extensions\FirefoxProxy|(ProxyConnector)@1.0.0.xpi (The syntax of the file name, directory or volume is incorrect)
  Build info: version: '3.141.59'
  //geckodriver version '0.24.0'
  </code></pre>
  
  <p>I also tried to add the extension on Firefox manually in debugging mode so that Firefox doesn't refuse it also if it doesn't have a signature, but it didn't work. It seem that it recognize the plugin but it didn't apply it.</p>
  
  <p>I have doubts about the .xpi format and a file .rdf that I read somewhere should be into the .xpi and that should give instructions about the plugin installation, but i didn't understand much.</p>
  
  <p>Thanks for any support :)</p>
  
  <p><strong>EDIT:</strong>
  I'm not forced to use the plugin by the way, the final result that i want to obtain is an auto proxy authentication made dinamically with different datas and letting the user navigate freely after that. I already searched for a less complex solution but found any.</p>
  
  <p><strong>EDIT2:</strong>
  I solved the problem.. It was not my code, Firefox browser does not accept anymore not signed extensions unless you use a developer Firefox version and set the profile preference <code>xpinstall.signatures.required</code> to <code>false</code>.</p>