1

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.

Louis Barranqueiro
  • 10,058
  • 6
  • 42
  • 52

2 Answers2

1

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>
gaetanoM
  • 41,594
  • 6
  • 42
  • 61
0

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
Yeldar Kurmangaliyev
  • 33,467
  • 12
  • 59
  • 101