fix: auto-detect system Chromium for puppeteer on Linux servers

Puppeteer's bundled Chrome often fails on Linux servers due to
architecture mismatches. Now auto-detects system-installed Chromium
at common paths (/usr/bin/chromium-browser, /usr/bin/chromium), or
honors PUPPETEER_EXECUTABLE_PATH env var.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-03 11:05:53 -05:00
parent c12ad94b7f
commit 467fdd2a6c

View File

@@ -402,9 +402,20 @@ async function main() {
let browser: Browser | null = null; let browser: Browser | null = null;
try { try {
// Use system Chromium if PUPPETEER_EXECUTABLE_PATH is set,
// or auto-detect common locations on Linux servers.
const executablePath =
process.env.PUPPETEER_EXECUTABLE_PATH ||
['/usr/bin/chromium-browser', '/usr/bin/chromium', '/usr/bin/google-chrome'].find(
(p) => { try { require('fs').accessSync(p); return true; } catch { return false; } },
) ||
undefined;
console.log('\nLaunching headless browser...'); console.log('\nLaunching headless browser...');
if (executablePath) console.log(`Using browser: ${executablePath}`);
browser = await puppeteer.launch({ browser = await puppeteer.launch({
headless: true, headless: true,
executablePath,
args: [ args: [
'--no-sandbox', '--no-sandbox',
'--disable-setuid-sandbox', '--disable-setuid-sandbox',