chore: add verbose browser console logs for PDF export diagnostics

This commit is contained in:
2026-03-08 10:59:10 +01:00
parent 519a896ec1
commit a12c5666ea

View File

@@ -498,15 +498,25 @@ function closeAiModal(){
} }
async function downloadPdf(){ async function downloadPdf(){
console.log('[PDF] click');
const openPrintFallback = (msg='') => { const openPrintFallback = (msg='') => {
console.warn('[PDF] fallback print', msg || '(no message)');
if (msg) alert(msg); if (msg) alert(msg);
const w = window.open('', '_blank'); const w = window.open('', '_blank');
if (!w) return; if (!w) {
console.error('[PDF] fallback window blocked');
return;
}
w.document.write(`<!doctype html><html><head><meta charset="utf-8"><title>Coachingcards PDF</title></head><body>${app.innerHTML}</body></html>`); w.document.write(`<!doctype html><html><head><meta charset="utf-8"><title>Coachingcards PDF</title></head><body>${app.innerHTML}</body></html>`);
w.document.close(); w.document.close();
w.onload = () => setTimeout(() => w.print(), 200); w.onload = () => setTimeout(() => w.print(), 200);
}; };
console.log('[PDF] libs', {
html2canvas: !!window.html2canvas,
jspdf: !!(window.jspdf && window.jspdf.jsPDF)
});
if (!window.html2canvas || !window.jspdf?.jsPDF) { if (!window.html2canvas || !window.jspdf?.jsPDF) {
openPrintFallback('PDF-Bibliotheken fehlen Druckdialog als Fallback.'); openPrintFallback('PDF-Bibliotheken fehlen Druckdialog als Fallback.');
return; return;
@@ -525,6 +535,7 @@ async function downloadPdf(){
try { try {
const cards = [...root.querySelectorAll('.card-size')]; const cards = [...root.querySelectorAll('.card-size')];
console.log('[PDF] cards found', cards.length);
if (!cards.length) throw new Error('Keine Karten sichtbar'); if (!cards.length) throw new Error('Keine Karten sichtbar');
const { jsPDF } = window.jspdf; const { jsPDF } = window.jspdf;
@@ -536,6 +547,7 @@ async function downloadPdf(){
const usableH = pageH - margin * 2; const usableH = pageH - margin * 2;
for (let i = 0; i < cards.length; i++) { for (let i = 0; i < cards.length; i++) {
console.log('[PDF] rendering card', i + 1, '/', cards.length);
const canvas = await Promise.race([ const canvas = await Promise.race([
window.html2canvas(cards[i], { scale: 2, useCORS: true, backgroundColor: '#ffffff', logging: false }), window.html2canvas(cards[i], { scale: 2, useCORS: true, backgroundColor: '#ffffff', logging: false }),
new Promise((_, rej) => setTimeout(() => rej(new Error('Render timeout')), 15000)) new Promise((_, rej) => setTimeout(() => rej(new Error('Render timeout')), 15000))
@@ -550,16 +562,19 @@ async function downloadPdf(){
pdf.addImage(img, 'JPEG', x, y, drawW, drawH, undefined, 'FAST'); pdf.addImage(img, 'JPEG', x, y, drawW, drawH, undefined, 'FAST');
} }
pdf.save(`coachingcards-${new Date().toISOString().slice(0,10)}.pdf`); const filename = `coachingcards-${new Date().toISOString().slice(0,10)}.pdf`;
console.log('[PDF] saving', filename);
pdf.save(filename);
console.log('[PDF] save triggered');
} catch (e) { } catch (e) {
console.error('PDF export failed', e); console.error('[PDF] export failed', e);
openPrintFallback('PDF-Download fehlgeschlagen nutze Druckdialog als Fallback.'); openPrintFallback('PDF-Download fehlgeschlagen nutze Druckdialog als Fallback. Schau in die Browser-Konsole.');
} finally { } finally {
root.remove(); root.remove();
console.log('[PDF] cleanup done');
} }
} }
async function syncActiveJob(){ async function syncActiveJob(){
const r = await fetch('/api/generate/active'); const r = await fetch('/api/generate/active');
const j = await r.json(); const j = await r.json();