diff --git a/.changeset/new-pots-walk.md b/.changeset/new-pots-walk.md new file mode 100644 index 00000000..9444bde5 --- /dev/null +++ b/.changeset/new-pots-walk.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +This fix adds the --user-data-dir flag when launching Chrome with the remote debugging port, which resolves the 'Chrome was launched but debug port is not responding' error. diff --git a/src/services/browser/BrowserSession.ts b/src/services/browser/BrowserSession.ts index 19fb10d5..360c78a7 100644 --- a/src/services/browser/BrowserSession.ts +++ b/src/services/browser/BrowserSession.ts @@ -16,6 +16,7 @@ import { discoverChromeInstances, testBrowserConnection, isPortOpen } from "./Br import * as chromeLauncher from "chrome-launcher" import { Controller } from "@core/controller" import { telemetryService } from "@/services/posthog/telemetry/TelemetryService" +import os from "os" interface PCRStats { puppeteer: { launch: typeof launch } @@ -123,45 +124,20 @@ export class BrowserSession { } async relaunchChromeDebugMode(controller: Controller) { - const result = await vscode.window.showWarningMessage( - "This will close your existing Chrome tabs and relaunch Chrome in debug mode. Are you sure?", - { modal: true }, - "Yes", - ) - - if (result !== "Yes") { - controller?.postMessageToWebview({ - type: "browserRelaunchResult", - success: false, - text: "Operation cancelled by user", - }) - return - } - try { - // Chrome-launcher's killAll only kills instances it launched - // We need to handle system Chrome processes separately - await this.killAllChromeBrowsers() - - // Wait a moment for Chrome to fully shut down - await new Promise((resolve) => setTimeout(resolve, 500)) - - // Instead of using any default flags, use a minimal set to ensure session persistence - // This closely mimics running "google-chrome-stable --remote-debugging-port=9222" from the CLI - const chromeFlags = [ - "--remote-debugging-port=" + DEBUG_PORT, - "--disable-notifications", - // Do not add any flags that might interfere with profile data - ] - + const userDataDir = path.join(os.tmpdir(), "chrome-debug-profile") const installation = chromeLauncher.Launcher.getFirstInstallation() if (!installation) { throw new Error("Could not find Chrome installation on this system") } console.info("chrome installation", installation) - // Prepare the command arguments - const args = [`--remote-debugging-port=${DEBUG_PORT}`, "--disable-notifications", "chrome://newtab"] + const args = [ + `--remote-debugging-port=${DEBUG_PORT}`, + `--user-data-dir=${userDataDir}`, + "--disable-notifications", + "chrome://newtab", + ] // Spawn Chrome as a detached process const chromeProcess = spawn(installation, args, { diff --git a/webview-ui/src/components/settings/BrowserSettingsSection.tsx b/webview-ui/src/components/settings/BrowserSettingsSection.tsx index 05c3cb5d..1699dbde 100644 --- a/webview-ui/src/components/settings/BrowserSettingsSection.tsx +++ b/webview-ui/src/components/settings/BrowserSettingsSection.tsx @@ -462,7 +462,7 @@ export const BrowserSettingsSection: React.FC = () => { {shouldShowRelaunchButton && (
- {debugMode ? "Relaunching Browser..." : "Relaunch Browser with Debug Mode"} + {debugMode ? "Launching Browser..." : "Launch Browser with Debug Mode"}
)}