whatsapp_bridge/server.js aktualisiert

1.3.1 FIX Lade Client error
This commit is contained in:
2026-06-15 08:11:39 +00:00
parent 4f1098bf95
commit 60007e5c4f

View File

@@ -12,10 +12,8 @@ let lastQr = "";
let isReady = false; let isReady = false;
let isInitializing = true; let isInitializing = true;
// Fester Speicherort für die Session außerhalb flüchtiger Docker-Verzeichnisse
const SESSION_DATA = '/data/auth'; const SESSION_DATA = '/data/auth';
// Sauberes Herunterfahren bei Abstürzen, um Dateikorruption der Session zu verhindern
async function handleCrash(errorContext) { async function handleCrash(errorContext) {
console.error(`💥 CRITICAL ERROR CAUGHT: ${errorContext}`); console.error(`💥 CRITICAL ERROR CAUGHT: ${errorContext}`);
isReady = false; isReady = false;
@@ -33,7 +31,6 @@ async function handleCrash(errorContext) {
process.exit(1); process.exit(1);
} }
// Sicherheitsnetz für ungefangene Puppeteer/Browser-Fehler
process.on('uncaughtException', async (err) => { process.on('uncaughtException', async (err) => {
if (err.message.includes('ProtocolError') || err.message.includes('Runtime.callFunctionOn') || err.message.includes('Target closed')) { if (err.message.includes('ProtocolError') || err.message.includes('Runtime.callFunctionOn') || err.message.includes('Target closed')) {
await handleCrash('Puppeteer Protocol Timeout / Crash'); await handleCrash('Puppeteer Protocol Timeout / Crash');
@@ -50,7 +47,6 @@ process.on('unhandledRejection', async (reason, promise) => {
} }
}); });
// Client-Definition mit fixierter Client-ID gegen Session-Verlust
const client = new Client({ const client = new Client({
authStrategy: new LocalAuth({ authStrategy: new LocalAuth({
dataPath: SESSION_DATA, dataPath: SESSION_DATA,
@@ -66,18 +62,13 @@ const client = new Client({
'--disable-setuid-sandbox', '--disable-setuid-sandbox',
'--disable-dev-shm-usage', '--disable-dev-shm-usage',
'--disable-gpu', '--disable-gpu',
'--no-first-run',
'--no-zygote', '--no-zygote',
'--single-process', '--single-process',
'--disable-extensions', '--disable-extensions'
'--disable-background-timer-throttling',
'--disable-backgrounding-occluded-windows',
'--disable-renderer-backgrounding'
] ]
} }
}); });
// QR Code Handling
client.on('qr', (qr) => { client.on('qr', (qr) => {
lastQr = qr; lastQr = qr;
isReady = false; isReady = false;
@@ -89,7 +80,7 @@ client.on('ready', () => {
isReady = true; isReady = true;
lastQr = ""; lastQr = "";
isInitializing = false; isInitializing = false;
console.log('WhatsApp ist bereit! Session wurde erfolgreich geladen/gespeichert.'); console.log('WhatsApp ist bereit!');
}); });
client.on('disconnected', async (reason) => { client.on('disconnected', async (reason) => {
@@ -127,7 +118,6 @@ app.get('/api/status', async (req, res) => {
} }
}); });
// Logout & Session-Löschung (Nur bei explizitem Klick auf "Account wechseln")
app.post('/auth/logout', async (req, res) => { app.post('/auth/logout', async (req, res) => {
try { try {
console.log("Manueller Logout über Web-UI..."); console.log("Manueller Logout über Web-UI...");
@@ -140,7 +130,6 @@ app.post('/auth/logout', async (req, res) => {
} }
}); });
// Factory Reset
app.delete('/system/reset', async (req, res) => { app.delete('/system/reset', async (req, res) => {
try { try {
await client.destroy().catch(() => {}); await client.destroy().catch(() => {});
@@ -152,7 +141,6 @@ app.delete('/system/reset', async (req, res) => {
} }
}); });
// Sende-Schnittstelle
app.post('/send', async (req, res) => { app.post('/send', async (req, res) => {
const { number, message } = req.body; const { number, message } = req.body;
if (!isReady) return res.status(503).json({ error: 'Client nicht bereit' }); if (!isReady) return res.status(503).json({ error: 'Client nicht bereit' });