Read SSL Certificates in a Firefox Extension
<p>I am working on a Firefox extension that would display the SSL certificate information to the user.  The actual information would be the same as the one built in to the browser, but I will be experimenting with layouts and other information for UX.</p>

<p>I've been working with Firefox extensions instead of add ons due to deprecation of add-ons in 2017, but this project will be finished before then.</p>

<p>I was trying the example found <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/How_to_check_the_secruity_state_of_an_XMLHTTPRequest_over_SSL" rel="nofollow">here</a>, but the extension seems to stop on the <code>require("chrome")</code>.  </p>

<p>Next I tried writing simpler code to figure out how the example works, but this code doesn't have a channel attached to the request.  My code, minus all sorts of printing statements, is below:</p>

<pre><code>document.getElementById("click_button").addEventListener("click",
  function(e) {
    var url = "https://secure-website-example.google.com";
    xhr = new XMLHttpRequest();
    xhr.open("GET", url, true);
    xhr.addEventListener("error",
      function(e) {
        dumpSecurityInfo(xhr, -1);
     }, false);

    xhr.onload = function(e) {
      dumpSecurityInfo(xhr);
    };
    xhr.send();
  });

function dumpSecurityInfo(xhr, error) {
  var channel = xhr.channel;
  try {
    console.log("Connection status:");
    if (!error) {  console.log("Succeeded"); }
    else        {  console.log("Failed :("); }

    var securityInfo = channel.securityInfo;
  } catch(err) {
    alert(err);
  }
}
</code></pre>

<p>with a manifest like this:</p>

<pre><code>  "manifest_version": 2,
  "name": "Certificate Browser",
  "version": "1.0",
  ...

  "permissions": [
    "activeTab",
    "webRequest",
    "https://secure-website-example.google.com/*"
  ],

  "browser_action": {
    ...
    "default_popup": "popup/certificate_information.html"
  }
</code></pre>

<p>Am I missing any permissions necessary to have access to the certificate?  Is there a better way of grabbing certificate information?  </p>