Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting real source code with javascript?

OK I don't use js enough to know, but is there a way to get the real source code of the page with it?

document.body.innerHTML for example gives some kind of "fixed up" version where malformed tags have been removed.

I'm guessing using XMLHttpRequest on the original page might work, but seems kind of stupid.

like image 727
graw Avatar asked Jan 22 '23 17:01

graw


1 Answers

This happens because browsers parse the DOM and don't keep the HTML in memory. What is returned to you is the browser's conversion of the current DOM back to HTML, which is the reason for the uppercase tags and lack of self closing tags where applicable.

An XMLHttpRequest would be the best way to go. In most cases, assuming the server doesn't send the no-cache header, and the HTML page has finished downloading, the XMLHttpRequest would be almost instant because the file is fetched from the cache.

like image 163
Andy E Avatar answered Feb 01 '23 22:02

Andy E