title: Chrome extension - call function defined on tab (Reference error)
body: <p>I'm opening a tab and trying to call a function defined in it but i always get a "reference error". I send a message to the script after the script is loaded asking to run "test1" function located on the tab code.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>Extention code</strong></p>
  
  <pre><code>chrome.tabs.executeScript(tab.id, {file: "script.js", runAt: "document_end"}, function(array){  
      //send message executeTest to the created tab
      chrome.tabs.sendMessage(tab.id, {msg: "executeTest"});
  });
  </code></pre>
  
  <p><strong>script.js</strong></p>
  
  <pre><code>url = document.URL; 
  window.addEventListener("load", doStuff, true);
  
  function doStuff(){
  
      //listen for messages coming from extension
      chrome.runtime.onMessage.addListener(
          function(message, sender) {
  
              var msg = message.msg;
              var url = message.url;    
  
              switch(msg){
                  case "executeTest":
                      test1();
                  break;
              }
          }
      );
  }  
  </code></pre>
  
  <p><strong>Tab HTML</strong></p>
  
  <p></p>
  
  <pre><code>&lt;head&gt;
  &lt;title&gt;Test&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;script src="app.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Tab Javascript</strong></p>
  
  <pre><code>function test1(){
      console.log("test1 is running!");
  }
  </code></pre>
  
  <p>I receive the message on the script but it's not possible to execute "test1()".</p>
  
  <p>What am i doing wrong ?</p>