Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting DOM element while page is loading, not afterwards

I am working on a chrome extension, that inserts a div into the body element of the dom. Right now I am creating an event handler that fires on load to create the element. This means of course that the page loads completely, and then my div is inserted, which means the user sees the page without the div until loading is complete, and then the div pops up. I would like the div to be there while the page is loading. Is there a way to hijack the body element before any other elements have been written? Or do I have to somehow hide the content until everything has loaded, which of course would mean that the user sees a blank screen for a while.

If at all possible, I would like to avoid jQuery.

like image 548
DudeOnRock Avatar asked Nov 12 '22 15:11

DudeOnRock


1 Answers

I'm not 100% sure, but looking at the Chrome extension developer guide, it looks like if you are using a Content Script and specify the run_at field in your extension's manifest as document_start, then it should inject the files before the DOM is constructed.

like image 86
David Lewis Avatar answered Nov 15 '22 05:11

David Lewis