title: How do I run Chrome extension content script after a site's javascript has finished building page?
body: <p>I know that I can use run_at: document end to run a script after a page is loaded, but most sites now inject most of their content through some kind of js framework. From what I can tell the content.js script is running before those can finish.</p>
  
  <p>I have some ideas on how to do this, but I'm not really if they really make sense, or even how to do them if they did.</p>
  
  <ol>
  <li><p>Run my script every time the DOM updates so that if a hyperlink is added I can just remove the hrefs again.</p>
  
  <p>I found this <a href="https://github.com/gorhill/uBlock/blob/master/src/js/contentscript.js#L179" rel="nofollow noreferrer">domwatcher thing in uBlock origin</a>, I assume he's doing something like this in order to remove any ads that show up, but it's really complex and I'm not sure what things I would or wouldn't need.</p></li>
  <li><p>Run the extension every second or two. This seems really clumsy, but maybe it's a standard thing? I'm not sure. I also don't know how I would get a content script to repeat, something this simple couldn't cause performance issues right?</p></li>
  <li><p>Javascript scripts are executed in order when they are listed in html right? So maybe I add the script to the end of all those? But they run asynchronously anyway right so that probably wouldn't work. Either way, some way to run my script after all the others are done. Can I put them in promises?</p></li>
  </ol>
  
  <p>Also here is my <a href="https://github.com/draav/remove-hyperlink-hrefs" rel="nofollow noreferrer">GitHub page with all the code</a>.</p>
  
  <p>The relevant manifest:</p>
  
  <pre><code> "content_scripts": [
      {
      "matches": [
          "http://*/*",
          "https://*/*"
          ],
      "js": ["content.js"],
      "run_at": "document_end"
      }
  ]
  </code></pre>
  
  <p>And content.js:</p>
  
  <pre><code>chrome.storage.sync.get('isEnabled', function (data) {
      if(!data.isEnabled) {
          return;
      }
  
      for (let link of document.links) {
          link.removeAttribute('href');
          console.log(link);
      }
  });
  </code></pre>