-1

I have search all over internet if get the full code of an html document in javascript including dynamically injected html or scripts or css and cannot find any clue.

So is it possible ? If yes any code snippet ?

user310291
  • 36,946
  • 82
  • 271
  • 487
  • Not sure if this is what you mean, but you can just save a webpage from the browser. On Chrome I am able to download the css, js, and assets as well as the HTML document. – zemaj Sep 20 '22 at 20:11
  • 1
    *"dynamically injected html"* - Do you mean, for example, changes to the DOM performed by the JavaScript code being executed on that page? If so then the search term you're looking for is probably "headless browser". – David Sep 20 '22 at 20:12
  • 1
    Any reason you can't just use `document.querySelector('html').innerHTML`? – Rocky Sims Sep 20 '22 at 20:12
  • 1
    Checkout this resource. It shows details of different ways of achieving your results: https://stackoverflow.com/questions/4196971/how-to-get-the-html-tag-html-with-javascript-jquery – Sikeh Japhet Sep 20 '22 at 20:35

1 Answers1

1
document.documentElement.outerHTML

would give you the entire HTML of the current DOM state, including changes made by JavaScript. Not sure what you mean by "including CSS".

If you use it, don't forget to add

<!DOCTYPE html>

at the top

Noam
  • 1,317
  • 5
  • 16