From 02d1a7ad7c9708367e5aca07037d0c408fd7b257 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Sun, 15 Mar 2026 03:32:34 -0500 Subject: [PATCH] Improve postinstall message to detect existing Chrome installations (#815) * Improve postinstall message to detect existing Chrome installations Previously, the npm postinstall script always recommended running `agent-browser install` to download Chrome for Testing, even when users already had a working Chrome installation on their system. This change adds Chrome detection logic to the postinstall script that mirrors the runtime behavior: - Checks for system Chrome installations on macOS, Linux, and Windows - Shows a success message when Chrome is found, indicating it will be used automatically - Only shows the `agent-browser install` warning when no Chrome is detected - Provides platform-specific guidance (Linux `--with-deps` flag, `--executable-path` alternative) The detection logic matches the existing Rust `find_chrome()` implementation to ensure consistency between postinstall messaging and runtime behavior. Fixes #814 * Mention --cdp, --provider, --engine as alternatives in postinstall message --------- Co-authored-by: ctate <366502+ctate@users.noreply.github.com> --- scripts/postinstall.js | 53 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 949acb3..01a8bce 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -128,15 +128,60 @@ async function main() { showInstallReminder(); } +function findSystemChrome() { + const os = platform(); + if (os === 'darwin') { + const candidates = [ + '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', + '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary', + '/Applications/Chromium.app/Contents/MacOS/Chromium', + ]; + return candidates.find(p => existsSync(p)) || null; + } + if (os === 'linux') { + const names = ['google-chrome', 'google-chrome-stable', 'chromium-browser', 'chromium']; + for (const name of names) { + try { + const result = execSync(`which ${name} 2>/dev/null`, { encoding: 'utf8' }).trim(); + if (result) return result; + } catch {} + } + return null; + } + if (os === 'win32') { + const candidates = [ + `${process.env.LOCALAPPDATA}\\Google\\Chrome\\Application\\chrome.exe`, + 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', + 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe', + ]; + return candidates.find(p => p && existsSync(p)) || null; + } + return null; +} + function showInstallReminder() { + const systemChrome = findSystemChrome(); + if (systemChrome) { + console.log(''); + console.log(` ✓ System Chrome found: ${systemChrome}`); + console.log(' agent-browser will use it automatically.'); + console.log(''); + return; + } + console.log(''); - console.log(' To download Chrome, run:'); + console.log(' ⚠ No Chrome installation detected.'); + console.log(' If you plan to use a local browser, run:'); console.log(''); console.log(' agent-browser install'); + if (platform() === 'linux') { + console.log(''); + console.log(' On Linux, include system dependencies with:'); + console.log(''); + console.log(' agent-browser install --with-deps'); + } console.log(''); - console.log(' On Linux, include system dependencies with:'); - console.log(''); - console.log(' agent-browser install --with-deps'); + console.log(' You can skip this if you use --cdp, --provider, --engine, or --executable-path.'); console.log(''); }