new XMLSerializer().serializeToString(document.doctype)+'\n'+document.documentElement.outerHTML
this works as it pulls the doctype string then adds the outer HTML