# How to Automatically Extract Cookies from Chrome or Firefox for Platform Authentication in Agent-Reach

> Easily extract authentication cookies from Chrome or Firefox for Agent-Reach. Utilize the built-in cookie extract utility for seamless platform integration.

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

---

**Agent-Reach provides a built-in utility in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) that extracts authentication cookies from Chrome, Firefox, Edge, Brave, or Opera using `rookiepy` or `browser_cookie3`, then stores them in `~/.agent-reach/config.yaml` for seamless platform integration.**

The Agent-Reach repository simplifies social media automation by automatically extracting cookies from Chrome or Firefox for platform authentication. This eliminates manual cookie copying by pulling credentials directly from your local browser profiles and securely storing them for Twitter/X, XiaoHongShu, Bilibili, and Xueqiu integrations.

## How Browser Cookie Extraction Works in Agent-Reach

The core implementation resides in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py), which orchestrates the entire extraction pipeline. The system validates your browser choice, attempts to retrieve cookies using Rust-based or Python-based backends, filters them according to platform-specific rules, and writes the results to your local configuration.

### The PLATFORM_SPECS Configuration

Lines 15-41 define **`PLATFORM_SPECS`**, a static list that maps supported platforms to their required cookie patterns:

- **`name`**: Human-readable platform label
- **`domains`**: Cookie domain patterns to match against browser data
- **`cookies`**: Specific cookie names to extract (e.g., `auth_token`, `ct0` for Twitter), or `None` to grab all cookies for that domain (used for XiaoHongShu and Xueqiu)
- **`config_key`**: The key used when storing data in the Agent-Reach config

### Backend Cookie Retrieval Libraries

The extraction logic implements a priority-based fallback strategy:

1. **Primary**: `rookiepy` (Rust-based extractor) — faster and more robust
2. **Fallback**: `browser_cookie3` (Python-based)
3. **Error**: If neither is available, the code raises `RuntimeError: Cookie extraction requires rookiepy or browser-cookie3.`

## Using the CLI Command to Extract Cookies Automatically

The simplest method uses the CLI entry point defined in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py):

```bash
agent-reach configure --from-browser chrome

```

Supported browsers include `chrome`, `firefox`, `edge`, `brave`, and `opera`. This command iterates through the `PLATFORM_SPECS`, attempts to match domains and cookie names from your browser's SQLite stores, and writes the formatted results to `~/.agent-reach/config.yaml`.

## Programmatic Cookie Extraction from Python

For custom workflows, import the extraction functions directly from `agent_reach/cookie_extract`.

### Configuring via configure_from_browser()

The **`configure_from_browser(browser, config)`** function (lines 25-90) handles the full pipeline:

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

cfg = Config()  # Loads existing config or creates new one

results = configure_from_browser("firefox", cfg)

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

```

This method also syncs Twitter credentials to legacy tools via `_sync_xfetch_session` and `_sync_bird_env` where applicable.

### Direct Raw Cookie Extraction with extract_all()

To retrieve cookies without updating the configuration file:

```python
from agent_reach.cookie_extract import extract_all

cookies = extract_all("chrome")
print(cookies["twitter"]["auth_token"])   # Specific token

print(cookies["xhs"]["cookie_string"])    # Full header string

```

The function returns a dictionary mapping each `config_key` to a sub-dictionary of extracted values. For platforms where `spec["cookies"]` is `None`, the value is a concatenated string (`name=value; ...`) suitable for direct HTTP header usage.

## Handling Dependencies and Missing Libraries

If you attempt to extract cookies without installing the required dependencies, you'll encounter:

```

RuntimeError: Cookie extraction requires rookiepy or browser-cookie3.
Install: pip install rookiepy  (recommended)
     or: pip install browser-cookie3

```

Install `rookiepy` for optimal performance, or `browser-cookie3` as a fallback.

## Summary

- Agent-Reach automatically extracts authentication cookies from Chrome, Firefox, Edge, Brave, and Opera via [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py)
- The system uses `PLATFORM_SPECS` to filter cookies by domain and name for Twitter/X, XiaoHongShu, Bilibili, and Xueqiu
- Implementation tries `rookiepy` first, then falls back to `browser_cookie3`, raising a clear error if neither is present
- Use `agent-reach configure --from-browser <browser>` for CLI-based extraction or `configure_from_browser()` for programmatic access
- Extracted credentials are stored in `~/.agent-reach/config.yaml` and optionally synced to legacy tool environments

## Frequently Asked Questions

### Which browsers does Agent-Reach support for cookie extraction?

Agent-Reach supports Chrome, Firefox, Edge, Brave, and Opera. The browser name is normalized to lowercase and validated against supported backends in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py).

### What Python libraries are required to extract cookies from Chrome or Firefox?

You must install either `rookiepy` (recommended, Rust-based) or `browser_cookie3` (Python-based). The code attempts to import `rookiepy` first; if unavailable, it falls back to `browser_cookie3`. If neither is found, a `RuntimeError` prompts you to install one.

### How does Agent-Reach handle different cookie formats for various platforms?

The `PLATFORM_SPECS` dictionary in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) defines platform-specific rules. For Twitter/X and Bilibili, it extracts specific named cookies like `auth_token` and `SESSDATA`. For XiaoHongShu and Xueqiu, it concatenates all domain cookies into a single `cookie_string` formatted as `name=value; name2=value2`.

### Where does Agent-Reach store extracted browser cookies?

Cookies are written to the Agent-Reach configuration file at `~/.agent-reach/config.yaml`. The `configure_from_browser()` function in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) handles this integration, optionally syncing Twitter credentials to legacy tools like `xfetch` and `bird` CLI environments.