In my Chrome Extension I have a content script that runs and outputs the page's Initial Source HTML. (As seen in VIEW SOURCE)
by simply using document.documentElement.innerHTML
.
But what I need is the Generated Source (Source/Current DOM after all JavaScript has finished executing [As seen in INSPECT ELEMENT])
, I've read various websites, and SO questions relative to this but they only discussed this in terms of a request from an outside source and not a chrome extension. Some of the various options I've read were:
- Run the url through a virtual browser hosted on your server to see how a browser would interpret the source and return the generated source
- Scrape the pages initial source, and somehow listen for and record all JavaScript executions, then execute those commands on the initial source to try and re-create the generated source
Since a Chrome Extension's content scripts presumably run parallel within the open tab's page is there some simpler/more-efficient solution? Can I just wait for all the initial JavaScript to finish executing then grab the current DOM or Source?
NOTE: I don't need to keep track of DOM after any extra JavaScript commands are executed. I just need one snapshot after the JavaScript that executes on every page load is finished.
I apologize in advance if this sounds naive, I'm new to making chrome extensions. Any links to good resources, tutorials, or examples would be greatly appreciated.
Thank you for your time.