title: Firefox Extension, get a reference to the loaded document using browser.contentDocument
body: <p>I want to write a simple firefox extension.</p>
  
  <p>How can I get a reference to the loaded document object in a browser window? For example, how can I access the document in this html page loaded here on stackoverflow? According to the vague mozilla development center I can use browser.contentDocument, but it is not working for me.</p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
  &lt;overlay id="sample" 
           xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt;
  &lt;script type="application/x-javascript"&gt;
   function change(){
    //var doc = document.getElementsByTagName("browser")[0].contentDocument;
    //var doc = document.browser.contentDocument;
    var doc = browser.contentDocument;
  
  
    var body = doc.getElementsByTagName("body")[0];
    var text = doc.createTextNode("blah");
    body.appendChild(text);
   }
  &lt;/script&gt;
  &lt;statusbar id="status-bar"&gt;
    &lt;statusbarpanel id="my-panel" label="click me" onclick="change();"  /&gt;
   &lt;/statusbar&gt;
  &lt;/overlay&gt;
  </code></pre>