diff --git a/lib/seo-report.ts b/lib/seo-report.ts index 33fb035..b1021a3 100644 --- a/lib/seo-report.ts +++ b/lib/seo-report.ts @@ -240,14 +240,26 @@ export function downloadSeoReport(d: SeoAuditData, format: "html" | "pdf") { document.body.removeChild(a); URL.revokeObjectURL(url); } else { - const blob = new Blob([html], { type: "text/html" }); - const url = URL.createObjectURL(blob); - const win = window.open(url, "_blank"); - if (win) { - win.addEventListener("load", () => { - setTimeout(() => win.print(), 300); - }); + const iframe = document.createElement("iframe"); + iframe.style.position = "fixed"; + iframe.style.right = "0"; + iframe.style.bottom = "0"; + iframe.style.width = "0"; + iframe.style.height = "0"; + iframe.style.border = "none"; + document.body.appendChild(iframe); + const doc = iframe.contentDocument || iframe.contentWindow?.document; + if (doc) { + doc.open(); + doc.write(html); + doc.close(); + iframe.onload = () => { + setTimeout(() => { + iframe.contentWindow?.focus(); + iframe.contentWindow?.print(); + setTimeout(() => document.body.removeChild(iframe), 5000); + }, 600); + }; } - setTimeout(() => URL.revokeObjectURL(url), 60000); } }