title: Getting chrome extension id programatically in injected script
body: <p>In my content script, I am using this approach to be able to access web page's variables:</p>
  
  <pre><code>function exec(fn) {
      var script = document.createElement('script');
      script.setAttribute("type", "application/javascript");
      script.textContent = '(' + fn + ')();';
      document.body.appendChild(script); //run the script
      document.body.removeChild(script); //clean up
  }
  
  exec( function(){
      var test = websiteVar
  
      chrome.runtime.sendMessage("extensionID", {test: test}, function(response) {
  
      });
  });
  </code></pre>
  
  <p>Where it says extensionID, if I hardcode it, it works. However, I can't use <code>chrome.runtime.id</code> as it is injected in the page. I think I read they don't work in the same context.</p>
  
  <p>Is there a way to get the extension id programatically?</p>