title: Chrome Extension: executeScript on tab
body: <p>I've recently started developing my first Google Chrome Extension, and am experiencing an issue that I'm not entirely sure how to fix.</p>
  
  <p>In my script, I'm checking if a tab is open to a specific website, and, if so, I'm performing the following code:</p>
  
  <pre><code>chrome.tabs.update(tab.id, {active: true});
  
  // Execute code on the existing tab to open the Message.
  chrome.tabs.executeScript(tab.id, {
      "code": "messageOpen(15, false);"
  });
  </code></pre>
  
  <p>The above code should update the tab setting it as active and should then attempt to execute a function called <code>messageOpen()</code>. The problem I'm experiencing is that the function <code>messageOpen()</code> exists as a function that was included in the <code>&lt;HEAD&gt;</code> of my website, but <strong>not</strong> my extension.</p>
  
  <p>Hence, when attempting to execute the <code>messageOpen()</code> function, I'm receiving this error:</p>
  
  <pre><code>Uncaught ReferenceError: messageOpen is not defined
  </code></pre>
  
  <p>I'm 100% positive that the <code>messageOpen()</code> function works if I browse the website regularly, but when using <code>executeScript</code>, it's as if the extension is incapable of running functions that have already been loaded in my active tab.</p>
  
  <p>Does anybody have some suggestions or alternatives?</p>