cookie-sync

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cookie 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
browse
CLI to open authenticated sessions with that context.
Supports domain filtering (only sync cookies you need) and context reuse (refresh cookies without creating a new context).
将本地Chrome中的Cookie导出并保存至Browserbase的持久化上下文中。同步完成后,即可使用
browse
CLI通过该上下文打开已认证的会话。
支持域名过滤(仅同步所需Cookie)和上下文复用(无需创建新上下文即可刷新Cookie)。

Prerequisites

前置条件

  • Chrome (or Chromium, Brave, Edge) with remote debugging enabled
  • If your browser build exposes
    chrome://flags/#allow-remote-debugging
    , enable it and restart the browser
  • Otherwise, launch with
    --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug
    and set
    CDP_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-debug
    命令启动浏览器,并设置环境变量
    CDP_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 install

Usage

使用方法

Basic — sync all cookies

基础用法 — 同步所有Cookie

bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs
Creates 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.com
Matches the domain and all subdomains (e.g.
google.com
matches
accounts.google.com
,
mail.google.com
, etc.)
bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --domains google.com,github.com
匹配指定域名及其所有子域名(例如
google.com
会匹配
accounts.google.com
mail.google.com
等)。

Refresh cookies in an existing context

刷新现有上下文中的Cookie

bash
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --context ctx_abc123
Re-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 --stealth
Enables 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:
"City,ST,Country"
(state is 2-letter code). Helps match your local IP's geolocation so auth cookies aren't rejected.
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
browse
CLI with the context ID:
bash
browse open https://mail.google.com --context-id <ctx-id> --persist
The
--persist
flag saves any new cookies or state changes back to the context, keeping the session fresh for next time.
Full workflow example:
bash
undefined
同步完成后,使用
browse
CLI并指定上下文ID:
bash
browse open https://mail.google.com --context-id <ctx-id> --persist
--persist
参数会将新生成的Cookie或状态变更保存回上下文,保持会话在下次使用时仍有效。
完整工作流示例:
bash
undefined

Step 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
undefined
browse open https://x.com/messages --context-id ctx_abc123 --persist browse snapshot browse screenshot browse stop
undefined

Reusing Contexts for Scheduled Jobs

复用上下文用于定时任务

Contexts persist across sessions, making them ideal for scheduled/recurring tasks:
  1. Once (laptop open): Run cookie-sync → get a context ID
  2. Scheduled jobs: Use
    browse open <url> --context-id <ctx-id> --persist
    — no local Chrome needed
  3. Re-sync as needed: When cookies expire, run cookie-sync again with
    --context <ctx-id>
    to refresh
上下文可跨会话持久化保存,非常适合用于定时/周期性任务:
  1. 一次性操作(电脑开机状态): 运行cookie-sync → 获取上下文ID
  2. 定时任务: 使用
    browse open <url> --context-id <ctx-id> --persist
    — 无需本地Chrome
  3. 按需重新同步: 当Cookie过期时,再次运行cookie-sync并加上
    --context <ctx-id>
    参数以刷新

Troubleshooting

故障排查

  • "No DevToolsActivePort found" → Enable
    chrome://flags/#allow-remote-debugging
    if your browser build exposes it, or launch with
    --remote-debugging-port=9222
    and set
    CDP_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
    --context <id>
    to refresh
  • Auth rejected by site → Try adding
    --stealth
    and/or
    --proxy
    with a location near you
  • "No DevToolsActivePort found" → 如果浏览器版本支持,启用
    chrome://flags/#allow-remote-debugging
    ,或者使用
    --remote-debugging-port=9222
    启动浏览器并设置
    CDP_URL=ws://127.0.0.1:9222
  • "No open page targets found" → 在Chrome中至少打开一个标签页
  • "WebSocket error" → Chrome可能已挂起;强制退出后重新打开
  • 上下文中的Cookie已过期 → 重新运行cookie-sync并加上
    --context <id>
    参数以刷新
  • 网站拒绝认证 → 尝试添加
    --stealth
    和/或
    --proxy
    参数,设置靠近你所在位置的代理