From f407c950c30b75da5066d0bcd0fdd9eecda87ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Liu=20=E5=AE=9D=E7=8E=89?= Date: Mon, 16 Mar 2026 20:01:09 -0500 Subject: [PATCH] docs(gemini-web): clarify CDP session reuse --- packages/baoyu-chrome-cdp/src/index.ts | 3 +++ skills/baoyu-danger-gemini-web/SKILL.md | 4 ++++ .../scripts/gemini-webapi/utils/load-browser-cookies.ts | 4 ++-- skills/baoyu-danger-gemini-web/scripts/main.ts | 7 ++++++- .../scripts/vendor/baoyu-chrome-cdp/src/index.ts | 3 +++ .../scripts/vendor/baoyu-chrome-cdp/src/index.ts | 3 +++ .../scripts/vendor/baoyu-chrome-cdp/src/index.ts | 3 +++ .../scripts/vendor/baoyu-chrome-cdp/src/index.ts | 3 +++ .../scripts/vendor/baoyu-chrome-cdp/src/index.ts | 3 +++ .../scripts/vendor/baoyu-chrome-cdp/src/index.ts | 3 +++ 10 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/baoyu-chrome-cdp/src/index.ts b/packages/baoyu-chrome-cdp/src/index.ts index 56f4ebd..0be48c3 100644 --- a/packages/baoyu-chrome-cdp/src/index.ts +++ b/packages/baoyu-chrome-cdp/src/index.ts @@ -271,6 +271,9 @@ export function getDefaultChromeUserDataDirs(channels: ChromeChannel[] = ["stabl return dirs; } +// Best-effort reuse of an already-running local CDP session discovered from +// known Chrome user-data dirs. This is distinct from Chrome DevTools MCP's +// prompt-based --autoConnect flow. export async function discoverRunningChromeDebugPort(options: DiscoverRunningChromeOptions = {}): Promise { const channels = options.channels ?? ["stable", "beta", "canary", "dev"]; const timeoutMs = options.timeoutMs ?? 3_000; diff --git a/skills/baoyu-danger-gemini-web/SKILL.md b/skills/baoyu-danger-gemini-web/SKILL.md index 9552610..ad7269f 100644 --- a/skills/baoyu-danger-gemini-web/SKILL.md +++ b/skills/baoyu-danger-gemini-web/SKILL.md @@ -139,6 +139,10 @@ ${BUN_X} {baseDir}/scripts/main.ts "Hello" --json First run opens browser for Google auth. Cookies cached automatically. +When no explicit profile dir is set, cookie refresh may reuse an already-running local Chrome/Chromium debugging session tied to a standard user-data dir. +Set `--profile-dir` or `GEMINI_WEB_CHROME_PROFILE_DIR` to force a dedicated profile and skip existing-session reuse. +This is a best-effort CDP session reuse path, not the Chrome DevTools MCP prompt-based `--autoConnect` flow described in Chrome's official docs. + Supported browsers (auto-detected): Chrome, Chrome Canary/Beta, Chromium, Edge. Force refresh: `--login` flag. Override browser: `GEMINI_WEB_CHROME_PATH` env var. diff --git a/skills/baoyu-danger-gemini-web/scripts/gemini-webapi/utils/load-browser-cookies.ts b/skills/baoyu-danger-gemini-web/scripts/gemini-webapi/utils/load-browser-cookies.ts index 6c06051..97cbb0b 100644 --- a/skills/baoyu-danger-gemini-web/scripts/gemini-webapi/utils/load-browser-cookies.ts +++ b/skills/baoyu-danger-gemini-web/scripts/gemini-webapi/utils/load-browser-cookies.ts @@ -105,7 +105,7 @@ async function fetch_cookies_from_existing_chrome( const discovered = await discoverRunningChromeDebugPort(); if (discovered === null) return null; - if (verbose) logger.info(`Found existing Chrome on port ${discovered.port}. Connecting via WebSocket...`); + if (verbose) logger.info(`Found reusable Chrome debugging session on port ${discovered.port}. Connecting via WebSocket...`); let cdp: CdpConnection | null = null; let targetId: string | null = null; @@ -167,7 +167,7 @@ async function fetch_cookies_from_existing_chrome( if (verbose) logger.debug(`Existing Chrome did not yield valid cookies. Last keys: ${Object.keys(last).join(', ')}`); return null; } catch (e) { - if (verbose) logger.debug(`Failed to connect to existing Chrome: ${e instanceof Error ? e.message : String(e)}`); + if (verbose) logger.debug(`Failed to connect to existing Chrome debugging session: ${e instanceof Error ? e.message : String(e)}`); return null; } finally { if (cdp) { diff --git a/skills/baoyu-danger-gemini-web/scripts/main.ts b/skills/baoyu-danger-gemini-web/scripts/main.ts index 7286ec0..4ad860d 100644 --- a/skills/baoyu-danger-gemini-web/scripts/main.ts +++ b/skills/baoyu-danger-gemini-web/scripts/main.ts @@ -101,7 +101,12 @@ Options: -h, --help Show help Env overrides: - GEMINI_WEB_DATA_DIR, GEMINI_WEB_COOKIE_PATH, GEMINI_WEB_CHROME_PROFILE_DIR, GEMINI_WEB_CHROME_PATH`); + GEMINI_WEB_DATA_DIR, GEMINI_WEB_COOKIE_PATH, GEMINI_WEB_CHROME_PROFILE_DIR, GEMINI_WEB_CHROME_PATH + +Notes: + By default cookie refresh may reuse an already-running local Chrome/Chromium debugging session. + Set --profile-dir or GEMINI_WEB_CHROME_PROFILE_DIR to force a dedicated profile and skip existing-session reuse. + This reuse path is separate from Chrome DevTools MCP's prompt-based --autoConnect flow.`); } function parseArgs(argv: string[]): CliArgs { diff --git a/skills/baoyu-danger-gemini-web/scripts/vendor/baoyu-chrome-cdp/src/index.ts b/skills/baoyu-danger-gemini-web/scripts/vendor/baoyu-chrome-cdp/src/index.ts index 56f4ebd..0be48c3 100644 --- a/skills/baoyu-danger-gemini-web/scripts/vendor/baoyu-chrome-cdp/src/index.ts +++ b/skills/baoyu-danger-gemini-web/scripts/vendor/baoyu-chrome-cdp/src/index.ts @@ -271,6 +271,9 @@ export function getDefaultChromeUserDataDirs(channels: ChromeChannel[] = ["stabl return dirs; } +// Best-effort reuse of an already-running local CDP session discovered from +// known Chrome user-data dirs. This is distinct from Chrome DevTools MCP's +// prompt-based --autoConnect flow. export async function discoverRunningChromeDebugPort(options: DiscoverRunningChromeOptions = {}): Promise { const channels = options.channels ?? ["stable", "beta", "canary", "dev"]; const timeoutMs = options.timeoutMs ?? 3_000; diff --git a/skills/baoyu-danger-x-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts b/skills/baoyu-danger-x-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts index 56f4ebd..0be48c3 100644 --- a/skills/baoyu-danger-x-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts +++ b/skills/baoyu-danger-x-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts @@ -271,6 +271,9 @@ export function getDefaultChromeUserDataDirs(channels: ChromeChannel[] = ["stabl return dirs; } +// Best-effort reuse of an already-running local CDP session discovered from +// known Chrome user-data dirs. This is distinct from Chrome DevTools MCP's +// prompt-based --autoConnect flow. export async function discoverRunningChromeDebugPort(options: DiscoverRunningChromeOptions = {}): Promise { const channels = options.channels ?? ["stable", "beta", "canary", "dev"]; const timeoutMs = options.timeoutMs ?? 3_000; diff --git a/skills/baoyu-post-to-wechat/scripts/vendor/baoyu-chrome-cdp/src/index.ts b/skills/baoyu-post-to-wechat/scripts/vendor/baoyu-chrome-cdp/src/index.ts index 56f4ebd..0be48c3 100644 --- a/skills/baoyu-post-to-wechat/scripts/vendor/baoyu-chrome-cdp/src/index.ts +++ b/skills/baoyu-post-to-wechat/scripts/vendor/baoyu-chrome-cdp/src/index.ts @@ -271,6 +271,9 @@ export function getDefaultChromeUserDataDirs(channels: ChromeChannel[] = ["stabl return dirs; } +// Best-effort reuse of an already-running local CDP session discovered from +// known Chrome user-data dirs. This is distinct from Chrome DevTools MCP's +// prompt-based --autoConnect flow. export async function discoverRunningChromeDebugPort(options: DiscoverRunningChromeOptions = {}): Promise { const channels = options.channels ?? ["stable", "beta", "canary", "dev"]; const timeoutMs = options.timeoutMs ?? 3_000; diff --git a/skills/baoyu-post-to-weibo/scripts/vendor/baoyu-chrome-cdp/src/index.ts b/skills/baoyu-post-to-weibo/scripts/vendor/baoyu-chrome-cdp/src/index.ts index 56f4ebd..0be48c3 100644 --- a/skills/baoyu-post-to-weibo/scripts/vendor/baoyu-chrome-cdp/src/index.ts +++ b/skills/baoyu-post-to-weibo/scripts/vendor/baoyu-chrome-cdp/src/index.ts @@ -271,6 +271,9 @@ export function getDefaultChromeUserDataDirs(channels: ChromeChannel[] = ["stabl return dirs; } +// Best-effort reuse of an already-running local CDP session discovered from +// known Chrome user-data dirs. This is distinct from Chrome DevTools MCP's +// prompt-based --autoConnect flow. export async function discoverRunningChromeDebugPort(options: DiscoverRunningChromeOptions = {}): Promise { const channels = options.channels ?? ["stable", "beta", "canary", "dev"]; const timeoutMs = options.timeoutMs ?? 3_000; diff --git a/skills/baoyu-post-to-x/scripts/vendor/baoyu-chrome-cdp/src/index.ts b/skills/baoyu-post-to-x/scripts/vendor/baoyu-chrome-cdp/src/index.ts index 56f4ebd..0be48c3 100644 --- a/skills/baoyu-post-to-x/scripts/vendor/baoyu-chrome-cdp/src/index.ts +++ b/skills/baoyu-post-to-x/scripts/vendor/baoyu-chrome-cdp/src/index.ts @@ -271,6 +271,9 @@ export function getDefaultChromeUserDataDirs(channels: ChromeChannel[] = ["stabl return dirs; } +// Best-effort reuse of an already-running local CDP session discovered from +// known Chrome user-data dirs. This is distinct from Chrome DevTools MCP's +// prompt-based --autoConnect flow. export async function discoverRunningChromeDebugPort(options: DiscoverRunningChromeOptions = {}): Promise { const channels = options.channels ?? ["stable", "beta", "canary", "dev"]; const timeoutMs = options.timeoutMs ?? 3_000; diff --git a/skills/baoyu-url-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts b/skills/baoyu-url-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts index 56f4ebd..0be48c3 100644 --- a/skills/baoyu-url-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts +++ b/skills/baoyu-url-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts @@ -271,6 +271,9 @@ export function getDefaultChromeUserDataDirs(channels: ChromeChannel[] = ["stabl return dirs; } +// Best-effort reuse of an already-running local CDP session discovered from +// known Chrome user-data dirs. This is distinct from Chrome DevTools MCP's +// prompt-based --autoConnect flow. export async function discoverRunningChromeDebugPort(options: DiscoverRunningChromeOptions = {}): Promise { const channels = options.channels ?? ["stable", "beta", "canary", "dev"]; const timeoutMs = options.timeoutMs ?? 3_000;