update: extension has been released! Named Dump Dom
chrome store
github source
I found a better way to dump the current dom tree to a html file ( to persist your changes to the dom tree in the element tab ),just paste the code below to the console, and a dom.html file would be downloaded.
filename = "dom"; var html = '', node = document.firstChild while (node) { switch (node.nodeType) { case Node.ELEMENT_NODE: html += node.outerHTML break case Node.TEXT_NODE: html += node.nodeValue break case Node.CDATA_SECTION_NODE: html += '<![CDATA[' + node.nodeValue + ']]>' break case Node.COMMENT_NODE: html += '<!--' + node.nodeValue + '-->' break case Node.DOCUMENT_TYPE_NODE: // (X)HTML documents are identified by public identifiers html += '<!DOCTYPE ' + node.name + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '') + (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>\n' break } node = node.nextSibling } var file = new Blob([html], { type: 'text/html' }); if (window.navigator.msSaveOrOpenBlob) // IE10+ window.navigator.msSaveOrOpenBlob(file, filename); else { // Others var a = document.createElement("a"), url = URL.createObjectURL(file); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); setTimeout(function () { document.body.removeChild(a); window.URL.revokeObjectURL(url); }, 0); }
Inspired from this project: https://github.com/wingleung/save-page-state. And I would develop an extention to make on-click-dump functional later.