title: How to wait for page load in a content script?
body: <p>I'm creating a Google chrome extension. The extension doesn't need to be active on all websites and thus instead of adding a <code>"content_scripts"</code> entry to <code>manifest.json</code>, I've added a <code>"permissions"</code> entry like this:</p>
  
  <pre><code> "permissions": [
      "activetab"
    ]
  </code></pre>
  
  <p>I need to wait for DOM completion since my extension tries to get some data from DOM.</p>
  
  <p>In my content script I've added the following code to wait for DOM creation:</p>
  
  <pre><code>window.addEventListener('DOMContentLoaded', function () {});
  </code></pre>
  
  <p>The problem is that the above trick works if somebody clicks my extension during page load, but if somebody opens my extension after the page has fully loaded, then my content script won't do anything, since the <code>DOMContentLoaded</code> event has already occured.</p>
  
  <p>What should I do to make sure the code in my content-script fires irrespective of the fact that the page has loaded or not. </p>