fix: Chrome must be fully quit before launching with --remote-debugging-port

Chrome refuses to enable CDP on its default profile when another instance
is running (even with explicit --user-data-dir). The only reliable path:
fully quit Chrome first, then relaunch with the flag.

Updated instructions to emphasize this clearly with verification step.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-03-21 12:32:21 -07:00
parent 65cc48c885
commit 0c207529f5
2 changed files with 16 additions and 16 deletions
+8 -12
View File
@@ -22,15 +22,12 @@ export interface BrowserBinary {
userDataDir: string; // required for --remote-debugging-port
}
const HOME = process.env.HOME || '/tmp';
const APP_SUPPORT = `${HOME}/Library/Application Support`;
export const BROWSER_BINARIES: BrowserBinary[] = [
{ name: 'Comet', binary: '/Applications/Comet.app/Contents/MacOS/Comet', appName: 'Comet', aliases: ['comet', 'perplexity'], userDataDir: `${APP_SUPPORT}/Comet` },
{ name: 'Chrome', binary: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', appName: 'Google Chrome', aliases: ['chrome', 'google-chrome'], userDataDir: `${APP_SUPPORT}/Google/Chrome` },
{ name: 'Arc', binary: '/Applications/Arc.app/Contents/MacOS/Arc', appName: 'Arc', aliases: ['arc'], userDataDir: `${APP_SUPPORT}/Arc/User Data` },
{ name: 'Brave', binary: '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser', appName: 'Brave Browser', aliases: ['brave'], userDataDir: `${APP_SUPPORT}/BraveSoftware/Brave-Browser` },
{ name: 'Edge', binary: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge', appName: 'Microsoft Edge', aliases: ['edge'], userDataDir: `${APP_SUPPORT}/Microsoft Edge` },
{ name: 'Comet', binary: '/Applications/Comet.app/Contents/MacOS/Comet', appName: 'Comet', aliases: ['comet', 'perplexity'], userDataDir: '' },
{ name: 'Chrome', binary: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', appName: 'Google Chrome', aliases: ['chrome', 'google-chrome'], userDataDir: '' },
{ name: 'Arc', binary: '/Applications/Arc.app/Contents/MacOS/Arc', appName: 'Arc', aliases: ['arc'], userDataDir: '' },
{ name: 'Brave', binary: '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser', appName: 'Brave Browser', aliases: ['brave'], userDataDir: '' },
{ name: 'Edge', binary: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge', appName: 'Microsoft Edge', aliases: ['edge'], userDataDir: '' },
];
// ─── CDP Probe ─────────────────────────────────────────────────
@@ -204,7 +201,7 @@ export async function launchWithCdp(
reason: runtime === 'conductor'
? `Conductor can't restart ${browser.name} due to macOS App Management security. You need to restart it manually.`
: `This runtime can't restart ${browser.name}. You need to restart it manually.`,
command: `"${browser.binary}" --remote-debugging-port=${port} --user-data-dir="${browser.userDataDir}" --restore-last-session`,
command: `"${browser.binary}" --remote-debugging-port=${port} --restore-last-session`,
};
}
@@ -221,7 +218,7 @@ export async function launchWithCdp(
browser,
port,
reason: `Failed to quit ${browser.name} via osascript. You need to restart it manually.`,
command: `"${browser.binary}" --remote-debugging-port=${port} --user-data-dir="${browser.userDataDir}" --restore-last-session`,
command: `"${browser.binary}" --remote-debugging-port=${port} --restore-last-session`,
};
}
@@ -236,10 +233,9 @@ export async function launchWithCdp(
}
}
// Launch with CDP flag + explicit user-data-dir (Chrome requires this for remote debugging)
// Launch with CDP flag — Chrome must NOT already be running (same profile can't have two instances)
const child = spawn(browser.binary, [
`--remote-debugging-port=${port}`,
`--user-data-dir=${browser.userDataDir}`,
'--restore-last-session',
], {
detached: true,
+8 -4
View File
@@ -386,12 +386,16 @@ Refs: After 'snapshot', use @e1, @e2... as selectors:
// Handle manual restart needed (Conductor / sandboxed apps)
if (isManualRestart(result)) {
console.log(`\n${result.reason}\n`);
console.log(`To connect, quit ${result.browser.name} and restart it with CDP enabled:\n`);
console.log(`To connect, FULLY QUIT ${result.browser.name} first (no processes running), then relaunch with CDP:\n`);
console.log(` 1. Quit ${result.browser.name} (Cmd+Q)`);
console.log(` 2. Open Terminal and run:`);
console.log(` 2. Wait 3 seconds for all processes to exit`);
console.log(` 3. Verify: pgrep -f "${result.browser.appName}" should return nothing`);
console.log(` 4. Open Terminal and run:`);
console.log(` ${result.command}`);
console.log(` 3. Then run: $B connect ${result.browser.name.toLowerCase()}\n`);
console.log(`Or add this to your shell profile to always launch with CDP:`);
console.log(` 5. Then run: $B connect ${result.browser.name.toLowerCase()}\n`);
console.log(`IMPORTANT: Chrome must be fully quit before step 4. If Chrome is already`);
console.log(`running, it ignores --remote-debugging-port and opens in the existing session.\n`);
console.log(`Pro tip — add to your shell profile to always launch with CDP:`);
console.log(` alias chrome-cdp='${result.command}'\n`);
// Wait and poll — user might restart Chrome while we're printing