# How Agent Reach's `configure --from-browser` Command Extracts Cookies from Chrome and Firefox

> Agent Reach's configure --from-browser command extracts Twitter X XiaoHongShu Bilibili cookies from Chrome Firefox using rookiepy and browser-cookie3.

- Repository: [Pnant/Agent-Reach](https://github.com/Panniantong/Agent-Reach)
- Tags: how-to-guide
- Published: 2026-06-07

---

**Agent Reach's `configure --from-browser` command leverages a dual-library extraction engine in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) that prioritizes the Rust-based `rookiepy` library with a fallback to `browser-cookie3`, reading encrypted browser SQLite databases to capture platform-specific authentication cookies for Twitter/X, XiaoHongShu, Bilibili, and Xueqiu.**

The `agent-reach configure --from-browser` command provides a seamless way to import authentication cookies directly from Chrome, Firefox, Edge, Brave, or Opera into Agent Reach's configuration. This feature eliminates manual cookie extraction by automatically reading the browser's native SQLite databases and decrypting them when necessary. According to the Panniantong/Agent-Reach source code, the implementation bridges browser-specific extraction libraries with an internal filtering system that targets specific social platforms.

## CLI Parsing and Command Dispatch

In [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py), the argument parser defines the `--from-browser` flag with specific choices: **chrome**, **firefox**, **edge**, **brave**, and **opera**. When a user executes `agent-reach configure --from-browser chrome`, the `_cmd_configure` handler detects the flag and immediately dispatches to the `configure_from_browser` function. This handler validates that the specified browser is supported and prepares the configuration context before invoking the extraction routine.

## The Cookie Extraction Engine

The core extraction logic resides in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) within the `extract_all` function. This implementation employs a cascading dependency strategy to maximize compatibility across different environments.

**Primary Extraction via rookiepy**

The function first attempts to import **rookiepy**, a Rust-based library optimized for reading browser cookie stores. When available, the code invokes browser-specific functions such as `rookiepy.chrome` or `rookiepy.firefox` depending on the user-specified browser. These functions handle platform-specific encryption—notably on macOS and Windows—and SQLite database parsing automatically.

**Fallback to browser-cookie3**

If `rookiepy` is not installed, the engine falls back to **browser-cookie3**, invoking equivalent methods like `browser_cookie3.chrome` or `browser_cookie3.firefox`. Both libraries require that the target browser process is **closed** during extraction; the function raises a descriptive error if the browser is still running.

## Platform-Specific Filtering with PLATFORM_SPECS

Once raw cookies are extracted, the `configure_from_browser` function applies intelligent filtering using the global `PLATFORM_SPECS` list defined in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py). This specification table defines four supported platforms:

- **Twitter/X**: Matches domains and extracts specific cookies `auth_token` and `ct0`
- **XiaoHongShu**: Captures all cookies for the domain and concatenates them into a single header string
- **Bilibili**: Extracts `SESSDATA` and optional `bili_jct` cookies
- **Xueqiu**: Captures the full cookie string only if the mandatory `xq_a_token` is present

The filtering algorithm iterates over raw cookie objects, checking if the `domain` attribute ends with any of the spec's defined domain patterns. When a spec defines concrete cookie names, only those specific values are retained; when `cookies` is set to `None`, all matching cookies are aggregated.

## Configuration Persistence and Legacy Sync

After filtering, the results populate Agent Reach's internal configuration through the `Config` class. The `configure_from_browser` function maps extracted values to specific configuration keys:

- Twitter credentials store as `twitter_auth_token` and `twitter_ct0`
- XiaoHongShu's header saves as `xhs_cookie`
- Bilibili tokens store as `bilibili_sessdata` and `bilibili_csrf`
- Xueqiu's string stores conditionally based on token presence

Additionally, for Twitter specifically, the function invokes `_sync_xfetch_session` and `_sync_bird_env` to synchronize credentials with legacy toolchains (`xfetch` and `bird` environments), maintaining backward compatibility with older Agent Reach components.

## Practical Usage Examples

Extract cookies from Chrome and automatically configure Agent Reach:

```bash
$ agent-reach configure --from-browser chrome
Extracting cookies from chrome...

  ✅ Twitter/X: auth_token + ct0
  ✅ XiaoHongShu: 12 cookies
  ✅ Bilibili: SESSDATA + bili_jct
  ✅ Xueqiu: 8 cookies (含 xq_a_token)

✅ Cookies configured! Run `agent-reach doctor` to verify.

```

Programmatically extract cookies using the internal API:

```python
from agent_reach.cookie_extract import extract_all, configure_from_browser
from agent_reach.config import Config

cfg = Config()

# Extract from Firefox (returns raw dict)

raw = extract_all("firefox")
print(raw)

# → {'twitter': {'auth_token': '…', 'ct0': '…'}, 'xhs': {'cookie_string': '…'}, …}

# Let Agent Reach update its config automatically

results = configure_from_browser("firefox", cfg)
for platform, ok, msg in results:
    print(f"{platform}: {'✅' if ok else '❌'} {msg}")

```

## Summary

- The `agent-reach configure --from-browser` command in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) provides a CLI wrapper around the cookie extraction engine
- **rookiepy** serves as the primary extraction library with **browser-cookie3** as the fallback, both reading native browser SQLite databases
- The `PLATFORM_SPECS` table in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) defines domain patterns and specific cookie requirements for Twitter/X, XiaoHongShu, Bilibili, and Xueqiu
- Extracted values persist to specific configuration keys via the `Config` class, with additional legacy synchronization for Twitter credentials
- The browser process must be closed during extraction to prevent database locking errors

## Frequently Asked Questions

### What browsers does Agent Reach support for cookie extraction?

Agent Reach supports Chrome, Firefox, Edge, Brave, and Opera through the `configure_from_browser` function in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py). The implementation accepts these values as the `browser` parameter and maps them to corresponding functions in either `rookiepy` or `browser-cookie3` libraries.

### Why does the command fail when my browser is open?

Both `rookiepy` and `browser-cookie3` require exclusive access to the browser's SQLite cookie database. If the browser process is running, the database remains locked, causing the extraction to fail. The code generates a helpful error message instructing users to close the browser before retrying the command.

### Which specific cookies does Agent Reach extract for each platform?

According to the `PLATFORM_SPECS` definition in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py), the command targets platform-specific credentials: Twitter/X requires `auth_token` and `ct0`; Bilibili uses `SESSDATA` and optionally `bili_jct`; Xueqiu requires `xq_a_token` within its full cookie string; and XiaoHongShu captures all domain cookies as a single concatenated header.

### Can I use the cookie extraction logic in my own Python scripts?

Yes, the `extract_all` and `configure_from_browser` functions in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) are importable. You can call `extract_all("chrome")` to receive a raw dictionary of filtered cookies, or use `configure_from_browser` with a `Config` instance to automatically persist values to Agent Reach's configuration store.