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>
This commit is contained in:
+49
-4
@@ -128,15 +128,60 @@ async function main() {
|
|||||||
showInstallReminder();
|
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() {
|
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('');
|
||||||
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('');
|
||||||
console.log(' agent-browser install');
|
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('');
|
||||||
console.log(' On Linux, include system dependencies with:');
|
console.log(' You can skip this if you use --cdp, --provider, --engine, or --executable-path.');
|
||||||
console.log('');
|
|
||||||
console.log(' agent-browser install --with-deps');
|
|
||||||
console.log('');
|
console.log('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user