title: Access Firefox extension XPCOM object from Javascript inside an HTML page
body: <p>I'm trying to get the most basic XPCOM javascript object to be accessible to the javascript I load into my webpage. I'm using the example code from this tutorial: 
  <a href="https://developer.mozilla.org/en-US/docs/How_to_Build_an_XPCOM_Component_in_Javascript" rel="nofollow">https://developer.mozilla.org/en-US/docs/How_to_Build_an_XPCOM_Component_in_Javascript</a></p>
  
  <p>Here is my set up:</p>
  
  <p><br />
  <b>install.rdf:</b></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
       xmlns:em="http://www.mozilla.org/2004/em-rdf#"&gt;
  
      &lt;Description about="urn:mozilla:install-manifest"&gt;
          &lt;em:id&gt;helloworld@thellamatesting.com&lt;/em:id&gt;
          &lt;em:name&gt;Hello World&lt;/em:name&gt;
          &lt;em:version&gt;1.0&lt;/em:version&gt;
          &lt;em:type&gt;2&lt;/em:type&gt;
          &lt;em:creator&gt;The Llama&lt;/em:creator&gt;
          &lt;em:description&gt;Testing&lt;/em:description&gt;
  
          &lt;em:targetApplication&gt;
              &lt;Description&gt;
                  &lt;em:id&gt;{ec8030f7-c20a-464f-9b0e-13a3a9e97384}&lt;/em:id&gt;
                  &lt;em:minVersion&gt;2.0&lt;/em:minVersion&gt;
                  &lt;em:maxVersion&gt;20.0&lt;/em:maxVersion&gt;
              &lt;/Description&gt;
          &lt;/em:targetApplication&gt;
      &lt;/Description&gt;      
  &lt;/RDF&gt;
  </code></pre>
  
  <p><br />
  <br />
  <b>chrome.manifest</b></p>
  
  <pre><code>content     helloworld    chrome/content/
  content     helloworld    chrome/content/ contentaccessible=yes
  overlay chrome://browser/content/browser.xul chrome://helloworld/content/browser.xul
  
  component {4762b5c0-5b32-11e2-bcfd-0800200c9a66} components/HelloWorld.js
  contract @thellamatesting.com/helloworld;1 {4762b5c0-5b32-11e2-bcfd-0800200c9a66}
  
  locale  helloworld  en-US   locale/en-US/
  </code></pre>
  
  <p><br />
  <br />
  <b>components/HelloWorld.js</b></p>
  
  <pre><code>Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
  
  function HelloWorld() {
      // If you only need to access your component from Javascript, uncomment the following line:
      this.wrappedJSObject = this;
  }
  
  HelloWorld.prototype = {
      classDescription: "My Hello World Javascript XPCOM Component",
      classID:          Components.ID("{4762b5c0-5b32-11e2-bcfd-0800200c9a66}"),
      //Also tried
      //classID:          Components.ID("4762b5c0-5b32-11e2-bcfd-0800200c9a66"),
      contractID:       "@thellamatesting.com/helloworld;1",
      QueryInterface: XPCOMUtils.generateQI(),
      // Also tried
      //QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIHelloWorld]),
      hello: function() { 
          return "Hello World!"; 
      }
  };
  
  var components = [HelloWorld];
  if ("generateNSGetFactory" in XPCOMUtils)
    var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);  // Firefox 4.0 and higher
  else
    var NSGetModule = XPCOMUtils.generateNSGetModule(components);    // Firefox 3.x
  </code></pre>
  
  <p><br />
  <br />
  <b>Testing HTML:</b></p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
          &lt;title&gt;&lt;/title&gt;
          &lt;script type="application/javascript"&gt;
  
              function go() {
                  try {
                      var coms = Components;
                      alert(Components.classes);
                      var myComponent = Components.classes['@thellamatesting.com/helloworld;1'].getService().wrappedJSObject;
                      alert(myComponent.hello());
                  } catch (anError) {
                          dump("ERROR: " + anError);
                  }
              };
  
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;button onclick="javascript:go()"&gt;Click to go&lt;/button&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>After all this, I end up with "Components.classes is undefined". Does anyone know what I'm doing wrong here?</p>
  
  <p>Thanks so much!</p>