title: Chrome extension set to `run_at` `document_start` is running too fast?
body: <p>EDIT: Something was wrong with my Chrome browser and creating a conflict with my script, a full reinstall eliminated whatever the problem source was. If I happen to find out what was causing it I will include it in here.</p>
  
  <p>EDIT2: Just to let anyone reading this in 2017 know that I haven't forgotten this and I have never had this problem since my previous edit.</p>
  
  <p>EDIT3: It is 2019 and so far I've never had this problem again.</p>
  
  <hr>
  
  <p>I have been learning how to create a simple Chrome extension which is a userscript port. The script works perfectly with Tampermonkey with the setting <code>run at</code> to <code>document-start</code>, all the necessary events that need to be caught from the beginning are all captured.</p>
  
  <p>However, when I set the same settings in the Chrome extension I discovered that the same running setting is faster than Tampermonkey's which causes the first function to fail: (<code>Uncaught TypeError: Cannot call method 'appendChild' of null.</code>) since it tries to append a script element to the <code>head</code> section, which doesn't exist until 0.010s later.</p>
  
  <p>My dirty solution so far has been to make use of a <code>setInterval</code> function with the timer set to 10 to check if <code>document.head</code> exists and then proceed with the code if the condition is true.</p>
  
  <p>Is there any way that I can make this work correctly without having to resort to <code>setInterval</code> or maybe replicate Tampermonkey's <code>grant none</code> option which appears to run the userscript on the webpage context?</p>
  
  <p>The following is my manifest.json file:</p>
  
  <pre><code>{
      "manifest_version": 2,
      "content_scripts": [ {
          "js":        [ "simpleuserscript.user.js" ],
          "matches":   [ "https://www.google.com/*"],
          "run_at":    "document_start"
      } ],
      "converted_from_user_script": true,
      "description":  "Chrome extension",
      "name":         "Testing",
      "version":      "1"
  }
  </code></pre>
  
  <p>All of this could be avoided if Chrome would adopt the <code>afterscriptexecute</code> event, but until that happens I am stuck with the <code>load</code> event. I thank in advance any help provided.</p>
  
  <hr>
  
  <p>EDIT: I have already tried the suggestions in the replies: using a different <code>run at</code> point, using <code>DOMContentLoaded</code> and append to <code>document.documentElement</code>. All were unsuccessful because: 1 and 2 makes the script miss early events, and 3 returns the same TypeError as when trying to append to <code>document.head</code>.</p>
  
  <p>The script has to be inserted/running when <code>document.readyState = loading</code> or else it will miss early necessary events, but not so early to the point of being unable to append childs to either <code>documentElement</code>or <code>head</code></p>
  
  <p>An example of the code inside <code>simpleuserscript.user.js</code>:</p>
  
  <pre><code>var script = document.createElement("script");
  script.textContent = "console.log('success')";
  if(document.head) {
      document.head.appendChild(script);
  } else if(document.documentElement) {
      document.documentElement.appendChild(script);
  }
  </code></pre>
  
  <p>Console will show <code>TypeError: Cannot call method 'appendChild' of null</code></p>