I used :
var generatedSource = new XMLSerializer().serializeToString(document);
or
document.getElementsByTagName('html')[0].innerHTML; ,
but I'm getting partial content only, page has around 600 lines and I'm just getting around 250 lines.
I used :
var generatedSource = new XMLSerializer().serializeToString(document);
or
document.getElementsByTagName('html')[0].innerHTML; ,
but I'm getting partial content only, page has around 600 lines and I'm just getting around 250 lines.
You need before to load the whole page and only after you can get the whole page:
<script>
window.onload = function() {
var htmlInPage = document.getElementsByTagName('html')[0].outerHTML;
}
</script>
You can use document.documentElement.outerHTML
, which is working in all modern browsers.
Here is an example, which shows that it outputs all the text, scripts, styles etc.
console.log(document.documentElement.outerHTML);
body {
color: darkgreen;
font-weight: bold;
}
Check your console