-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 ?

4
  • 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. Commented Sep 20, 2022 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". Commented Sep 20, 2022 at 20:12
  • 1
    Any reason you can't just use document.querySelector('html').innerHTML? Commented Sep 20, 2022 at 20:12
  • 1
    Checkout this resource. It shows details of different ways of achieving your results: stackoverflow.com/questions/4196971/… Commented Sep 20, 2022 at 20:35

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.