diff --git a/src/App.vue b/src/App.vue index 38a69d1..f51be59 100644 --- a/src/App.vue +++ b/src/App.vue @@ -275,32 +275,66 @@ watch( ); // Handle Cmd+P / Ctrl+P to print the iframe content -const handlePrint = (event) => { +const handlePrint = async (event) => { if ((event.metaKey || event.ctrlKey) && event.key === 'p') { event.preventDefault(); const frame = activeFrame.value; if (frame && frame.contentDocument) { - // Get the full HTML content of the iframe - const content = frame.contentDocument.documentElement.outerHTML; + const doc = frame.contentDocument; - // Open a new window with the content + // Collect all styles (inline and from stylesheets) + let allStyles = ''; + + // Get inline + + ${bodyContent} + + `; + + // Open print window const printWindow = window.open('', '_blank'); - printWindow.document.write(content); + printWindow.document.write(printContent); printWindow.document.close(); - // Wait for content to load then print - printWindow.onload = () => { + // Wait for rendering then print + setTimeout(() => { printWindow.print(); printWindow.close(); - }; - - // Fallback if onload doesn't fire - setTimeout(() => { - if (!printWindow.closed) { - printWindow.print(); - printWindow.close(); - } - }, 500); + }, 100); } } };