mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-05 13:15:24 +02:00
fix: Chrome requires --user-data-dir for remote debugging
Chrome refuses --remote-debugging-port without an explicit --user-data-dir. Add userDataDir to BrowserBinary registry (macOS Application Support paths) and pass it in both auto-launch and manual restart instructions. Fix double-quoting in CLI manual restart instructions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,14 +19,18 @@ export interface BrowserBinary {
|
||||
binary: string;
|
||||
appName: string; // for osascript 'tell application "X"'
|
||||
aliases: string[];
|
||||
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'] },
|
||||
{ name: 'Chrome', binary: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', appName: 'Google Chrome', aliases: ['chrome', 'google-chrome'] },
|
||||
{ name: 'Arc', binary: '/Applications/Arc.app/Contents/MacOS/Arc', appName: 'Arc', aliases: ['arc'] },
|
||||
{ name: 'Brave', binary: '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser', appName: 'Brave Browser', aliases: ['brave'] },
|
||||
{ name: 'Edge', binary: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge', appName: 'Microsoft Edge', aliases: ['edge'] },
|
||||
{ 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` },
|
||||
];
|
||||
|
||||
// ─── CDP Probe ─────────────────────────────────────────────────
|
||||
@@ -200,7 +204,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} --restore-last-session`,
|
||||
command: `"${browser.binary}" --remote-debugging-port=${port} --user-data-dir="${browser.userDataDir}" --restore-last-session`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -217,7 +221,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} --restore-last-session`,
|
||||
command: `"${browser.binary}" --remote-debugging-port=${port} --user-data-dir="${browser.userDataDir}" --restore-last-session`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -232,9 +236,10 @@ export async function launchWithCdp(
|
||||
}
|
||||
}
|
||||
|
||||
// Launch with CDP flag
|
||||
// Launch with CDP flag + explicit user-data-dir (Chrome requires this for remote debugging)
|
||||
const child = spawn(browser.binary, [
|
||||
`--remote-debugging-port=${port}`,
|
||||
`--user-data-dir=${browser.userDataDir}`,
|
||||
'--restore-last-session',
|
||||
], {
|
||||
detached: true,
|
||||
|
||||
+2
-2
@@ -389,10 +389,10 @@ Refs: After 'snapshot', use @e1, @e2... as selectors:
|
||||
console.log(`To connect, quit ${result.browser.name} and restart it with CDP enabled:\n`);
|
||||
console.log(` 1. Quit ${result.browser.name} (Cmd+Q)`);
|
||||
console.log(` 2. Open Terminal and run:`);
|
||||
console.log(` "${result.command}"`);
|
||||
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(` alias chrome-cdp='"${result.command}"'\n`);
|
||||
console.log(` alias chrome-cdp='${result.command}'\n`);
|
||||
|
||||
// Wait and poll — user might restart Chrome while we're printing
|
||||
console.log(`Waiting for CDP on port ${result.port}...`);
|
||||
|
||||
Reference in New Issue
Block a user