title: Detect all images with Javascript in an html page
body: <p>I am writing a chrome extension and I am trying to detect all images in a webpage.</p>
  
  <p>I am trying in my JS code to detect <strong>all</strong> images on a webpage, and by all I mean:</p>
  
  <ol>
  <li>Images that are loaded once the webpage is loaded</li>
  <li>Images that are used as background (either in the CSS or inline html)</li>
  <li>Images that could be loaded after the webpage is done loading, for instance, when doing a google image search it is easy to find all images, but once you click on one image to make it bigger, this image is not detected. Same thing for browsing social media website.</li>
  </ol>
  
  <p>The code that I have right now makes it easy to find the initial images (1). But I struggle with the other two parts (2) and (3).</p>
  
  <p>Here is my current code in contentScript.js:</p>
  
  <pre><code>var images = document.getElementsByTagName('img');
  for (var i = 0, l = images.length; i &lt; l; i++) {
      //Do something
  }
  </code></pre>
  
  <p>How should I modify it so that it actually can detect all other images (2 and 3).</p>
  
  <p>I have seen a couple of questions on (2) on SO like <a href="https://stackoverflow.com/questions/43175307/get-background-image-src-from-div-and-set-that-as-an-images-src">this one</a> or <a href="https://stackoverflow.com/questions/44586878/get-background-image-url-from-img-tag-and-create-new-img-tag-with-that-url">this one</a>, but none of the answers seem to completely satisfy my second requirement and none of them is about the third.</p>