cookie-sync
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCookie Sync — Local Chrome → Browserbase Context
Cookie 同步 — 本地Chrome → Browserbase 上下文
Exports cookies from your local Chrome and saves them into a Browserbase persistent context. After syncing, use the CLI to open authenticated sessions with that context.
browseSupports domain filtering (only sync cookies you need) and context reuse (refresh cookies without creating a new context).
将本地Chrome中的Cookie导出并保存至Browserbase的持久化上下文中。同步完成后,即可使用 CLI通过该上下文打开已认证的会话。
browse支持域名过滤(仅同步所需Cookie)和上下文复用(无需创建新上下文即可刷新Cookie)。
Prerequisites
前置条件
- Chrome (or Chromium, Brave, Edge) with remote debugging enabled
- If your browser build exposes , enable it and restart the browser
chrome://flags/#allow-remote-debugging - Otherwise, launch with and set
--remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debugCDP_URL=ws://127.0.0.1:9222 - At least one tab open in Chrome
- Node.js 22+
- Environment variable:
BROWSERBASE_API_KEY
- 已启用远程调试的Chrome(或Chromium、Brave、Edge)
- 如果你的浏览器版本支持,请启用该选项并重启浏览器
chrome://flags/#allow-remote-debugging - 若不支持上述选项,请使用命令启动浏览器,并设置环境变量
--remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debugCDP_URL=ws://127.0.0.1:9222 - Chrome中至少打开一个标签页
- Node.js 22及以上版本
- 环境变量:
BROWSERBASE_API_KEY
Setup
设置步骤
Install dependencies before first use:
bash
cd .claude/skills/cookie-sync && npm install首次使用前先安装依赖:
bash
cd .claude/skills/cookie-sync && npm installUsage
使用方法
Basic — sync all cookies
基础用法 — 同步所有Cookie
bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjsCreates a persistent context with all your Chrome cookies. Outputs a context ID.
bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs创建包含所有Chrome Cookie的持久化上下文,输出上下文ID。
Filter by domain — only sync specific sites
按域名过滤 — 仅同步指定网站
bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --domains google.com,github.comMatches the domain and all subdomains (e.g. matches , , etc.)
google.comaccounts.google.commail.google.combash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --domains google.com,github.com匹配指定域名及其所有子域名(例如会匹配、等)。
google.comaccounts.google.commail.google.comRefresh cookies in an existing context
刷新现有上下文中的Cookie
bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --context ctx_abc123Re-injects fresh cookies into a previously created context. Use this when cookies have expired.
bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --context ctx_abc123将新的Cookie重新注入到已创建的上下文中,适用于Cookie过期的场景。
Advanced stealth mode
高级隐身模式
bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --stealthEnables Browserbase's advanced stealth mode to reduce bot detection. Recommended for sites like Google that fingerprint browsers.
bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --stealth启用Browserbase的高级隐身模式,减少被检测为机器人的概率。推荐用于Google等会对浏览器进行指纹识别的网站。
Residential proxy with geolocation
带地理位置的住宅代理
bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --proxy "San Francisco,CA,US"Routes through a residential proxy in the specified location. Format: (state is 2-letter code). Helps match your local IP's geolocation so auth cookies aren't rejected.
"City,ST,Country"bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --proxy "San Francisco,CA,US"通过指定位置的住宅代理进行路由,格式为(州为两位代码)。有助于匹配本地IP的地理位置,避免认证Cookie被拒绝。
"城市,州代码,国家代码"Combine flags
组合参数使用
bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --domains github.com,google.com --stealth --proxy "San Francisco,CA,US"bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --domains github.com,google.com --stealth --proxy "San Francisco,CA,US"Browsing Authenticated Sites
浏览已认证网站
After syncing, use the CLI with the context ID:
browsebash
browse open https://mail.google.com --context-id <ctx-id> --persistThe flag saves any new cookies or state changes back to the context, keeping the session fresh for next time.
--persistFull workflow example:
bash
undefined同步完成后,使用 CLI并指定上下文ID:
browsebash
browse open https://mail.google.com --context-id <ctx-id> --persist--persist完整工作流示例:
bash
undefinedStep 1: Sync cookies for Twitter
步骤1:同步Twitter的Cookie
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --domains x.com,twitter.com
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --domains x.com,twitter.com
Output: Context ID: ctx_abc123
输出:Context ID: ctx_abc123
Step 2: Browse authenticated Twitter
步骤2:浏览已认证的Twitter
browse open https://x.com/messages --context-id ctx_abc123 --persist
browse snapshot
browse screenshot
browse stop
undefinedbrowse open https://x.com/messages --context-id ctx_abc123 --persist
browse snapshot
browse screenshot
browse stop
undefinedReusing Contexts for Scheduled Jobs
复用上下文用于定时任务
Contexts persist across sessions, making them ideal for scheduled/recurring tasks:
- Once (laptop open): Run cookie-sync → get a context ID
- Scheduled jobs: Use — no local Chrome needed
browse open <url> --context-id <ctx-id> --persist - Re-sync as needed: When cookies expire, run cookie-sync again with to refresh
--context <ctx-id>
上下文可跨会话持久化保存,非常适合用于定时/周期性任务:
- 一次性操作(电脑开机状态): 运行cookie-sync → 获取上下文ID
- 定时任务: 使用— 无需本地Chrome
browse open <url> --context-id <ctx-id> --persist - 按需重新同步: 当Cookie过期时,再次运行cookie-sync并加上参数以刷新
--context <ctx-id>
Troubleshooting
故障排查
- "No DevToolsActivePort found" → Enable if your browser build exposes it, or launch with
chrome://flags/#allow-remote-debuggingand set--remote-debugging-port=9222CDP_URL=ws://127.0.0.1:9222 - "No open page targets found" → Open at least one tab in Chrome
- "WebSocket error" → Chrome may be hung; force quit and reopen it
- Cookies expired in context → Re-run cookie-sync with to refresh
--context <id> - Auth rejected by site → Try adding and/or
--stealthwith a location near you--proxy
- "No DevToolsActivePort found" → 如果浏览器版本支持,启用,或者使用
chrome://flags/#allow-remote-debugging启动浏览器并设置--remote-debugging-port=9222CDP_URL=ws://127.0.0.1:9222 - "No open page targets found" → 在Chrome中至少打开一个标签页
- "WebSocket error" → Chrome可能已挂起;强制退出后重新打开
- 上下文中的Cookie已过期 → 重新运行cookie-sync并加上参数以刷新
--context <id> - 网站拒绝认证 → 尝试添加和/或
--stealth参数,设置靠近你所在位置的代理--proxy