DEV Community

Query Filter
Query Filter

Posted on

exec-2

(() => {
  // Capture the full live DOM including html tag and doctype
  const doctype = document.doctype 
    ? new XMLSerializer().serializeToString(document.doctype) + '\n' 
    : '';
  const fullHTML = doctype + document.documentElement.outerHTML;

  // Create a blob and trigger a direct file download
  const blob = new Blob([fullHTML], { type: 'text/html' });
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = `live_page_${new Date().toISOString().slice(0,10)}.html`;
  document.body.appendChild(a);
  a.click();

  // Cleanup object URL and temporary node
  document.body.removeChild(a);
  URL.revokeObjectURL(url);
  console.log('Live DOM successfully exported!');
})();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)