# How to Import XiaoHongShu (XHS) Cookies from Your Browser in Agent-Reach

> Easily import XiaoHongShu XHS cookies from Chrome Firefox Edge Brave or Opera into Agent-Reach for seamless API access. Learn how to extract and store your authentication cookies.

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

---

**Agent-Reach extracts XiaoHongShu authentication cookies directly from Chrome, Firefox, Edge, Brave, or Opera and stores them under the `xhs_cookie` configuration key, enabling seamless API access without manual cookie copying.**

The Agent-Reach framework automates social media interactions through dedicated channel implementations, including a first-class integration for XiaoHongShu (XHS). Rather than requiring you to copy-paste cookie strings from browser developer tools, the toolkit provides automated extraction capabilities that harvest your existing browser session. This guide explains how to import XiaoHongShu cookies from your browser using both the command-line interface and the Python API.

## How Cookie Extraction Works in Agent-Reach

The extraction logic lives in [[`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py)](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py), which interfaces with browser-specific SQLite databases using the `rookiepy` or `browser_cookie3` libraries. This module defines platform-specific specifications that map target domains to configuration keys, allowing the harvest of authentication tokens from sites like XiaoHongShu.

### The XiaoHongShu Cookie Specification

Within [[`cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/cookie_extract.py)](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py), lines 24-28 define the XHS extraction profile:

```python
{
    "name": "XiaoHongShu",
    "domains": [".xiaohongshu.com"],
    "cookies": None,           # None → grab all cookies for the domain

    "config_key": "xhs",
}

```

This configuration instructs the extractor to capture **all** cookies for the `.xiaohongshu.com` domain and associate them with the `"xhs"` configuration key. When invoked, the extractor concatenates these into a single `cookie_string` (e.g., `a=1; b=2; …`) suitable for HTTP headers.

### Storage Mechanism

After extraction, the `configure_from_browser()` function (lines 59-65 in [[`cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/cookie_extract.py)](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py)) writes the cookie string into Agent-Reach’s YAML configuration under the key `xhs_cookie`. This makes the authentication data available to all downstream channels without hardcoding sensitive values.

## Import Methods

You can import XHS cookies using either the CLI convenience wrapper or programmatically via the Python API.

### CLI Import via `configure --from-browser`

The fastest method uses the built-in CLI command:

```bash

# Import from Chrome (default). Replace with firefox, edge, brave, or opera.

agent-reach configure --from-browser chrome

```

This command invokes `configure_from_browser()`, which executes `extract_all("chrome")`, filters for the XiaoHongShu domain specification, and persists the results to your configuration file.

### Programmatic Import via Python API

For custom workflows or integration into larger automation scripts, import the extraction functions directly:

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

# 1. Pull cookies from Chrome (returns dict keyed by config_key)

cookies = extract_all("chrome")

# 2. Initialize config manager

cfg = Config()

# 3. Store XHS cookies if found

if "xhs" in cookies:
    cfg.set("xhs_cookie", cookies["xhs"]["cookie_string"])
    print("XHS cookies imported successfully.")
else:
    print("No XHS cookies found — ensure you are logged in to xiaohongshu.com")

```

The `extract_all()` function attempts to use `rookiepy` first, falling back to `browser_cookie3` if necessary, ensuring compatibility across different Python environments.

## How XiaoHongShuChannel Uses Imported Cookies

The [`XiaoHongShuChannel`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/xiaohongshu.py) implementation (lines 29-39) retrieves the stored cookie string through the central configuration object passed during initialization. The channel validates the presence of the external `xhs-cli` binary and passes the authentication cookies when executing search, read, comment, or post operations.

Because the channel relies on the generic `config` object, any cookies imported via `cookie_extract` are automatically available for all XHS operations without additional code changes.

## Summary

- **Automated extraction**: [[`cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/cookie_extract.py)](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) harvests cookies from Chrome, Firefox, Edge, Brave, or Opera using `rookiepy` or `browser_cookie3`.
- **Domain targeting**: The XHS specification captures all `.xiaohongshu.com` cookies and stores them under the `xhs` configuration key.
- **CLI workflow**: Run `agent-reach configure --from-browser <browser>` for one-click import.
- **API workflow**: Use `extract_all()` and `cfg.set("xhs_cookie", ...)` for programmatic control.
- **Channel integration**: [`XiaoHongShuChannel`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/xiaohongshu.py) automatically consumes the imported cookies via the configuration object to authenticate `xhs-cli` calls.

## Frequently Asked Questions

### Which browsers are supported for importing XiaoHongShu cookies?

Agent-Reach supports **Chrome**, **Firefox**, **Edge**, **Brave**, and **Opera**. The underlying `cookie_extract` module accesses each browser’s SQLite cookie store directly. Note that some browsers may require you to close the application before the database can be read, depending on file-locking behavior on your operating system.

### Do I need to install additional dependencies for cookie extraction?

The [[`cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/cookie_extract.py)](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) module attempts to use `rookiepy` first, falling back to `browser_cookie3` if the former is unavailable. Ensure your Python environment has one of these packages installed to enable browser cookie reading; Agent-Reach does not bundle them as hard requirements.

### Why does my XiaoHongShu channel show authentication errors after importing cookies?

Verify that you have an **active login session** open in your chosen browser before extraction. The extraction specification uses `"cookies": None`, which captures whatever cookies exist for `.xiaohongshu.com`. If you are logged out or the session has expired, the extracted string will be empty or contain invalid tokens, causing `xhs-cli` operations to fail.

### Can I manually specify cookies instead of importing from a browser?

Yes. While the recommended path uses `extract_all()`, you can manually set the configuration value using `cfg.set("xhs_cookie", "your_cookie_string_here")`. Ensure the string follows the standard HTTP header format (`key1=value1; key2=value2`) so that [`XiaoHongShuChannel`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/xiaohongshu.py) can pass it correctly to the underlying `xhs-cli` binary.