title: Google Chrome Extension - Script Injections
body: <p>I'm trying to get my Chrome Extension to inject some javascript with <code>content_scripts</code>, using this previous <strong><em><a href="https://stackoverflow.com/questions/9263671/google-chome-application-shortcut-how-to-auto-load-javascript/9310273#9310273">answer</a></em></strong> as a reference. </p>
  
  <h2>manifest.json</h2>
  
  <pre><code>"name": "My Chrome Extension",
  "version": "1.0",
  "manifest_version": 2,
  "content_scripts": [{
      "matches": ["http://pagetoinject/script/into/*"],
      "js": ["contentscript.js"]
  }]  
  </code></pre>
  
  <h2><strong>contenscript.js:</strong></h2>
  
  <pre><code>var s = document.createElement('script');
  s.src = chrome.extension.getURL("script.js");
  (document.head||document.documentElement).appendChild(s);
  s.parentNode.removeChild(s);
  </code></pre>
  
  <p><em>( also tried <strong></em><a href="https://stackoverflow.com/questions/9515704/building-a-chrome-extension-inject-code-in-a-page-using-a-content-script">this</a><em></strong> method with no success. )</em></p>
  
  <pre><code>var s = document.createElement('script');
  s.src = chrome.extension.getURL("script.js");
  s.onload = function() {
      this.parentNode.removeChild(this);
  };
  (document.head||document.documentElement).appendChild(s);
  </code></pre>
  
  <p>I keep getting this javascript error. Here's a <a href="https://i.imgur.com/SIXQp.png" rel="noreferrer">screenshot</a>.</p>
  
  <p><img src="https://i.stack.imgur.com/PTLMQ.png" alt="enter image description here">
      <code>GET chrome-extension://invalid/
         (anonymous function)</code></p>