diff --git a/docs/core/subagents.md b/docs/core/subagents.md index 24785145d9..ae0302e231 100644 --- a/docs/core/subagents.md +++ b/docs/core/subagents.md @@ -141,7 +141,7 @@ The available modes are: | Mode | Description | | :----------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `persistent` | **(Default)** Launches Chrome with a persistent profile stored at `~/.cache/chrome-devtools-mcp/`. Cookies, history, and settings are preserved between sessions. | +| `persistent` | **(Default)** Launches Chrome with a persistent profile stored at `~/.gemini/cli-browser-profile/`. Cookies, history, and settings are preserved between sessions. | | `isolated` | Launches Chrome with a temporary profile that is deleted after each session. Use this for clean-state automation. | | `existing` | Attaches to an already-running Chrome instance. You must enable remote debugging first by navigating to `chrome://inspect/#remote-debugging` in Chrome. No new browser process is launched. | diff --git a/packages/core/src/agents/browser/browserManager.test.ts b/packages/core/src/agents/browser/browserManager.test.ts index 2266983e4d..da01928662 100644 --- a/packages/core/src/agents/browser/browserManager.test.ts +++ b/packages/core/src/agents/browser/browserManager.test.ts @@ -157,6 +157,10 @@ describe('BrowserManager', () => { ?.args as string[]; expect(args).not.toContain('--isolated'); expect(args).not.toContain('--autoConnect'); + // Persistent mode should set the default --userDataDir under ~/.gemini + expect(args).toContain('--userDataDir'); + const userDataDirIndex = args.indexOf('--userDataDir'); + expect(args[userDataDirIndex + 1]).toMatch(/cli-browser-profile$/); }); it('should pass headless flag when configured', async () => { diff --git a/packages/core/src/agents/browser/browserManager.ts b/packages/core/src/agents/browser/browserManager.ts index 82062de520..2f17a0db2c 100644 --- a/packages/core/src/agents/browser/browserManager.ts +++ b/packages/core/src/agents/browser/browserManager.ts @@ -22,10 +22,15 @@ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js' import type { Tool as McpTool } from '@modelcontextprotocol/sdk/types.js'; import { debugLogger } from '../../utils/debugLogger.js'; import type { Config } from '../../config/config.js'; +import { Storage } from '../../config/storage.js'; +import * as path from 'node:path'; // Pin chrome-devtools-mcp version for reproducibility. const CHROME_DEVTOOLS_MCP_VERSION = '0.17.1'; +// Default browser profile directory name within ~/.gemini/ +const BROWSER_PROFILE_DIR = 'cli-browser-profile'; + // Default timeout for MCP operations const MCP_TIMEOUT_MS = 60_000; @@ -246,7 +251,7 @@ export class BrowserManager { // Session mode determines how the browser is managed: // - "isolated": Temp profile, cleaned up after session (--isolated) - // - "persistent": Persistent profile at ~/.cache/chrome-devtools-mcp/ (default) + // - "persistent": Persistent profile at ~/.gemini/cli-browser-profile/ (default) // - "existing": Connect to already-running Chrome (--autoConnect, requires // remote debugging enabled at chrome://inspect/#remote-debugging) if (sessionMode === 'isolated') { @@ -261,6 +266,13 @@ export class BrowserManager { } if (browserConfig.customConfig.profilePath) { mcpArgs.push('--userDataDir', browserConfig.customConfig.profilePath); + } else if (sessionMode === 'persistent') { + // Default persistent profile lives under ~/.gemini/cli-browser-profile + const defaultProfilePath = path.join( + Storage.getGlobalGeminiDir(), + BROWSER_PROFILE_DIR, + ); + mcpArgs.push('--userDataDir', defaultProfilePath); } debugLogger.log(