I believe you can get this by just stringifying the document.body.outerHTML.
try this:
document.body.style.backgroundColor = "red";
alert(JSON.stringify(document.body.outerHTML));
You should see that the backgroundColor has been set (which means you're seeing the modified dom).
If you're changing an input value, and you want to see it in the dom, you have to set it two ways. First the .value attribute actually sets the value for the field that is read when a form submits. Then you can do a setAttribute("value", "...") to set it visibly in the stringify.
document.getElementById("changeDom").addEventListener("click", function() {
document.getElementById("try").value="xyz"; // sets visible value
document.getElementById("try").setAttribute("value","xyz"); // sets dom value
});
document.getElementById("showDom").addEventListener("click", function() {
alert(JSON.stringify(document.body.outerHTML));
});
<input type="text" id="try"/>
<button id="changeDom">Change</button>
<button id="showDom">Show</button>
If you don't want to set it twice, you can just add an event listener for when the value changes to do the setAttribute for you. JQuery makes this pretty easy. It would look something like this (pseudocode warning):
$(document).on("keypress", "#try", function() { $(this).attr("value",$(this).val()); })'