title: How to execute javascript code in the namespace (scope) of the webpage, from a firefox extension?
body: <p>I'm looking for a clean way to call/execute/redefine javascript code from a webpage, within firefox, through a firefox extension. My temporary solution is to use the scratchpad (Shift-F4, Ctrl-A, Ctrl-V, Ctrl-R), it works fine but is a sad work-around. Greasemonkey would be my last resort, very very last.</p>
  
  <p>Here' the code so far:
  <br></p>
  
  <p><strong>main.js:</strong></p>
  
  <pre><code>exports.main = function() {
    var data = require("self").data;
    var pageMod = require("page-mod");
    pageMod.PageMod({
      include: "*.google.com",
      contentScriptFile: data.url("my-script.js")
    });
  };
  </code></pre>
  
  <p><strong>my-script.js</strong></p>
  
  <pre><code>$('#mydiv').html('yo')
  alreadyHere.sayHello=function (){alert('Bonjour');}
  </code></pre>
  
  <p><br>
  This code halts on line #1 of my-script.js saying that $ is not defined.
  Problem of namespace/scope.</p>
  
  <p>How can I work within the namespace/scope of the webpage, from my extension, like I do with the scratchpad?</p>
  
  <p><strong>Edit:</strong> There should be a link between <em>window.content</em> of the firefox main window and <em>alreadyHere.sayHello</em> from the webpage, no?</p>
  
  <pre><code>window.content.(things).alreadyHere.sayHello();
  </code></pre>
  
  <p>What am I missing here?</p>