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
  • 9,390
  • 6
  • 39
  • 51

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
  • 40,728
  • 6
  • 37
  • 54
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
  • 32,279
  • 11
  • 59
  • 94