diff --git a/whatsapp_bridge/server.js b/whatsapp_bridge/server.js index d3db972..f5534f1 100644 --- a/whatsapp_bridge/server.js +++ b/whatsapp_bridge/server.js @@ -121,22 +121,47 @@ function initWhatsApp() { console.log('[WA] Initializing WhatsApp client using LocalAuth...'); clientReady = false; + const fs = require('fs'); + const puppeteerConfig = { + headless: 'new', + args: [ + '--no-sandbox', + '--disable-setuid-sandbox', + '--disable-dev-shm-usage', + '--disable-accelerated-2d-canvas', + '--no-first-run', + '--no-zygote', + '--single-process', + '--disable-gpu', + ], + }; + + const possiblePaths = [ + process.env.CHROME_BIN, + '/usr/bin/chromium', + '/usr/bin/chromium-browser', + '/usr/bin/google-chrome', + '/usr/bin/google-chrome-stable' + ]; + + let detectedPath = null; + for (const p of possiblePaths) { + if (p && fs.existsSync(p)) { + detectedPath = p; + break; + } + } + + if (detectedPath) { + console.log(`[WA] Detected system chromium at: ${detectedPath}`); + puppeteerConfig.executablePath = detectedPath; + } else { + console.log('[WA] No system chromium found. Falling back to bundled Puppeteer chromium...'); + } + waClient = new Client({ authStrategy: new LocalAuth({ clientId: 'whatsapp-bridge' }), - puppeteer: { - executablePath: process.env.CHROME_BIN || '/usr/bin/chromium', - headless: 'new', - args: [ - '--no-sandbox', - '--disable-setuid-sandbox', - '--disable-dev-shm-usage', - '--disable-accelerated-2d-canvas', - '--no-first-run', - '--no-zygote', - '--single-process', - '--disable-gpu', - ], - }, + puppeteer: puppeteerConfig, }); // QR Code received -> send to all WS clients