fix: Puppeteer nutzt System-Chromium direkt, kein @sparticuz

This commit is contained in:
2026-06-12 11:06:00 +02:00
parent c83f78595f
commit 589cb18f8c
2 changed files with 33 additions and 12 deletions

View File

@@ -174,17 +174,39 @@ router.post('/pdf', authenticate, async (req, res) => {
const tmpFile = path.join('/tmp', `pwk_${crypto.randomBytes(8).toString('hex')}.pdf`);
try {
let puppeteer, chromium;
try { puppeteer = require('puppeteer-core'); chromium = require('@sparticuz/chromium'); }
catch { try { puppeteer = require('puppeteer'); chromium = null; }
let puppeteer;
try { puppeteer = require('puppeteer-core'); }
catch { try { puppeteer = require('puppeteer'); }
catch { return res.status(500).json({ error: 'PDF-Rendering nicht verfügbar' }); } }
const launchOptions = chromium
? { args: [...chromium.args, '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
defaultViewport: { width: 1280, height: 900 },
executablePath: process.env.CHROMIUM_PATH || await chromium.executablePath(),
headless: true }
: { headless: 'new', args: ['--no-sandbox', '--disable-setuid-sandbox'] };
// System-Chromium aus Alpine nutzen (via CHROMIUM_PATH env oder bekannte Pfade)
const executablePath = process.env.CHROMIUM_PATH
|| (() => {
const candidates = [
'/usr/bin/chromium-browser',
'/usr/bin/chromium',
'/usr/bin/google-chrome',
'/usr/bin/google-chrome-stable',
];
const fs2 = require('fs');
return candidates.find(p => { try { fs2.accessSync(p); return true; } catch { return false; } })
|| '/usr/bin/chromium-browser';
})();
const launchOptions = {
executablePath,
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-gpu',
'--disable-software-rasterizer',
'--single-process',
'--no-zygote',
],
defaultViewport: { width: 1280, height: 900 },
};
browser = await puppeteer.launch(launchOptions);
const page = await browser.newPage();