fix(browser): address platform and port review

This commit is contained in:
Tam Nhu Tran
2026-04-16 18:49:24 -04:00
parent 06f6f5485f
commit 8a17410f96
7 changed files with 87 additions and 18 deletions
+3
View File
@@ -74,6 +74,9 @@ export function getEffectiveClaudeBrowserAttachConfig(
overrideActive: false,
userDataDir: configUserDataDir,
devtoolsPort: configPort,
// Config-backed browser attach always keeps an explicit port so launches
// stay aligned with Settings > Browser, even when the effective value is
// the default 9222.
hasExplicitDevtoolsPort: true,
};
}
+4 -9
View File
@@ -2,6 +2,7 @@ import { getBrowserConfig } from '../../config/unified-config-loader';
import { getCodexBinaryInfo } from '../../targets/codex-detector';
import { type BrowserRuntimeEnv, resolveBrowserRuntimeEnv } from './chrome-reuse';
import { getBrowserMcpServerName, getBrowserMcpServerPath } from './mcp-installer';
import { getNodePlatformKey } from './platform';
import {
getEffectiveClaudeBrowserAttachConfig,
getRecommendedBrowserUserDataDir,
@@ -107,7 +108,7 @@ async function buildClaudeBrowserStatus(
state: 'path_missing',
title: 'Claude Browser Attach path is missing.',
detail: message,
nextStep: `Create or choose a Chrome user-data directory, then launch Chrome with attach mode enabled. Example: ${launchCommands[platformKey()]}`,
nextStep: `Create or choose a Chrome user-data directory, then launch Chrome with attach mode enabled. Example: ${launchCommands[getNodePlatformKey()]}`,
};
}
@@ -117,7 +118,7 @@ async function buildClaudeBrowserStatus(
state: 'browser_not_running',
title: 'Claude Browser Attach could not find a running browser session.',
detail: message,
nextStep: `Start Chrome with remote debugging and the configured user-data dir. Example: ${launchCommands[platformKey()]}`,
nextStep: `Start Chrome with remote debugging and the configured user-data dir. Example: ${launchCommands[getNodePlatformKey()]}`,
};
}
@@ -126,7 +127,7 @@ async function buildClaudeBrowserStatus(
state: 'endpoint_unreachable',
title: 'Claude Browser Attach could not reach the DevTools endpoint.',
detail: message,
nextStep: `Restart the attach browser session or confirm the configured port. Example: ${launchCommands[platformKey()]}`,
nextStep: `Restart the attach browser session or confirm the configured port. Example: ${launchCommands[getNodePlatformKey()]}`,
};
}
}
@@ -185,9 +186,3 @@ function buildLaunchCommands(userDataDir: string, devtoolsPort: number): Browser
win32: `chrome.exe --remote-debugging-port=${devtoolsPort} --user-data-dir=${quotedPath}`,
};
}
function platformKey(): keyof BrowserLaunchCommands {
if (process.platform === 'darwin') return 'darwin';
if (process.platform === 'win32') return 'win32';
return 'linux';
}
+9
View File
@@ -0,0 +1,9 @@
export type BrowserPlatformKey = 'darwin' | 'linux' | 'win32';
export function getNodePlatformKey(
platform: NodeJS.Platform = process.platform
): BrowserPlatformKey {
if (platform === 'darwin') return 'darwin';
if (platform === 'win32') return 'win32';
return 'linux';
}