Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing DomNodeInserted to rewrite HTML before it finishes loading
    primarykey
    data
    text
    <p>I feel like this will probably be immediately obvious to any of the non-amateurs out there, but I've been stumped on this for days.</p> <p>I am writing a Chrome Extension that executes a script at document start. I want to rewrite the HTML of specific DIVs as they load, but before they are displayed to the user (so the user doesn't see the site's HTML before it is unceremoniously replaced by my custom HTML). The method I am trying to use looks like this.</p> <pre><code>addEventListener('DOMNodeInserted', function(event){ if(event.relatedNode.innerHTML.indexOf("contentArea")&gt;-1){ writeContentArea(); } }, false); function writeContentArea(){ var divtowrite = document.getElementById('contentArea'); include(divtowrite,"contentArea.html"); //my AJAX include function } </code></pre> <p>Now, the problem is, when the page loads and the JS executes, the div will still load before it is replaced. The weird thing is when I try this with a different div, like a sidebar, it works as expected; i.e., the div is replaced before it is displayed to the user. I can't figure out why it works for some divs and not for others.</p> <p>I don't know if this is relevant, but on the Chrome side I have:</p> <pre><code>chrome.tabs.getSelected(null, function(tab) { if(tab.url.indexOf("search.php") &gt; -1){ chrome.tabs.executeScript(null, {file: "fhrun.js", allFrames: false, runAt: "document_start"} ); } }); </code></pre> <p>Any ideas of why this isn't working, or a better method that I should be using? Thanks!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload