Metadata-Version: 2.5
Name: foxfetch
Version: 0.1.1
Summary: Fetch pages through a real Firefox engine (ruyijs) for AI agents: pass bot checks, run the page's own JavaScript, then hand the identity to Chromium when a screenshot is needed.
Project-URL: Homepage, https://github.com/zhuchongba-01/foxfetch
Project-URL: Repository, https://github.com/zhuchongba-01/foxfetch
Project-URL: Issues, https://github.com/zhuchongba-01/foxfetch/issues
Project-URL: Changelog, https://github.com/zhuchongba-01/foxfetch/commits/master
License: MIT License
        
        Copyright (c) 2026 foxfetch contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
        Note: `ruyijs`, the Firefox engine this package drives, is a separate project
        under AGPL-3.0. foxfetch only imports and calls it; no ruyijs code is bundled.
License-File: LICENSE
Keywords: agent,anti-bot,firefox,mcp,playwright,ruyijs,scraping
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
Requires-Python: >=3.10
Requires-Dist: mcp<2,>=1.30
Requires-Dist: ruyijs>=0.4.5
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# foxfetch

**Read a page the way a browser does — only when plain HTTP is not enough.**

[![PyPI](https://img.shields.io/pypi/v/foxfetch?logo=pypi&label=PyPI)](https://pypi.org/project/foxfetch/)
[![Python](https://img.shields.io/pypi/pyversions/foxfetch?logo=python&logoColor=white)](https://pypi.org/project/foxfetch/)
[![npm plugin](https://img.shields.io/npm/v/dsh-foxfetch?logo=npm&label=dsh-foxfetch)](https://www.npmjs.com/package/dsh-foxfetch)
[![License](https://img.shields.io/pypi/l/foxfetch)](LICENSE)
[![MCP](https://img.shields.io/badge/protocol-MCP-6f42c1)](https://modelcontextprotocol.io)
[![install](https://img.shields.io/badge/install-INSTALL.md-blueviolet)](INSTALL.md)

foxfetch drives a real Firefox engine (SpiderMonkey + Necko, no window, no renderer) to run a
site's own JavaScript: pass a bot check, read a DOM that only exists after the scripts run, find
the signature and the real API host. When a screenshot or a click is needed, it hands the
identity it earned to Chromium.

It speaks the Model Context Protocol, so one service serves every agent host — Pi, Claude Code,
Codex, DeepSeek Harness.

```bash
pip install foxfetch
python -m foxfetch doctor
```

---

## The rule that saves the most time

| Situation | Use |
|---|---|
| Static HTML, JSON endpoints, RSS | **plain HTTP** — do not call foxfetch |
| Content appears after JS runs | `run` |
| 403 / Cloudflare / DataDome / Kasada | `probe`, then `run` |
| Someone needs to *see* the page | `handoff` → the generated Playwright script |

`probe` answers the first two questions with evidence, so the choice is not a guess:

```
probe("https://shop.example/item")
→ verdict: blocked
  evidence: HTTP 403, DataDome (matched 'datadome'), 512 bytes, 0 visible text
  suggestion: use run — the engine's TLS and JS profile match a real Firefox
```

Most pages do not need the engine. Reaching for it anyway costs ~90 MB of RAM and ~3 s per open,
and buys nothing on a document `curl` could have fetched.

## Tools

| Tool | What it does |
|---|---|
| `probe` | Classify a URL: `plain_http` / `needs_engine` / `blocked`, with the evidence |
| `run` | Evaluate JavaScript in the engine; returns the value, console and request log |
| `net` | Read the request log and console of a live context |
| `handoff` | Export cookies (including HttpOnly), localStorage, UA; write a Playwright script |
| `close` | Close one context (by id or origin) or all of them |
| `cleanup` | Delete every artifact except the ones in `keep`, close contexts, sweep temp scratch dirs |
| `status` | Live contexts, artifact usage, environment check |

## Contexts

One engine world per origin, kept alive between calls so a multi-step flow is several small
calls instead of one giant script:

```python
run("window.step = 1", url="https://x.test")      # opens the page
run("window.step + 1")                            # → 2, same document
run("fetch('/api/me').then(r => r.text())",
    advance_ms=800, read="window.__last")         # carries the cookies earned above
```

A context dies on `close`, after `FOXFETCH_IDLE_SECONDS` (default 60) of silence, or when the
pool exceeds `FOXFETCH_MAX_CONTEXTS` (default 2) — the least recently used goes first.

## Install

Two pieces, always two: the **service** (all the logic, from PyPI) and a **host entry** (how
your agent finds it). The service is the same everywhere; only the wiring differs.

```bash
pip install foxfetch          # or: python -m pip install --upgrade foxfetch
python -m foxfetch doctor     # exits non-zero and prints fixes when something is missing
```

`doctor` reports Python, `ruyijs`, `mcp`, Chromium and the artifact directory:

```
{ "ok": true,
  "python":   { "version": "3.14.6",  "ok": true },
  "ruyijs":   { "version": "0.4.5",   "ok": true },
  "mcp":      { "version": "1.30.0",  "ok": true },
  "chromium": { "found": true, "path": "…/chrome-headless-shell.exe" },
  "fixes":    [] }
```

Chromium is optional: without it `handoff` still exports the identity, it just cannot write the
screenshot script.

Then pick your host — **one entry per host, never two**, or the model sees the same seven tools
twice:

| Host | Where the entry goes |
|---|---|
| **Pi** | `~/.pi/agent/mcp.json` → `mcpServers.foxfetch` |
| **Claude Code** | `claude mcp add foxfetch -- python -m foxfetch serve` |
| **Codex** | `~/.codex/config.toml` → `[mcp_servers.foxfetch]` |
| **DeepSeek Harness** | `pnpm add dsh-foxfetch` in the profile, then add it to `dsh.profile.bundles` |
| anything else | a stdio server: `python` + `["-m", "foxfetch", "serve"]` |

```json
// Pi / Claude Code / Codex — the same shape everywhere
{
  "mcpServers": {
    "foxfetch": {
      "command": "python",
      "args": ["-m", "foxfetch", "serve"],
      "timeout": 180
    }
  }
}
```

**Every step, per host, with the exact commands and a verification call: [INSTALL.md](INSTALL.md).**
[SETUP.md](SETUP.md) is the version written for an agent doing the install on a fresh machine
(it detects which hosts exist instead of asking).

The DSH plugin holds no logic; upgrading `foxfetch` on PyPI upgrades what the plugin can do.

## Verify it works

Ask the host, not a shell:

```
foxfetch_run(js="navigator.userAgent", url="https://example.com")
→ Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:160.0) Gecko/20100101 Firefox/160.0
```

`Python-urllib` or `HeadlessChrome` in that string means the call never reached the engine.

## Configuration

| Variable | Default | Meaning |
|---|---|---|
| `FOXFETCH_HOME` | `%LOCALAPPDATA%\foxfetch` | Artifact root (credentials pass through it) |
| `FOXFETCH_MAX_CONTEXTS` | 2 | Live engine contexts before LRU eviction |
| `FOXFETCH_IDLE_SECONDS` | 60 | Silence before a context is killed |
| `FOXFETCH_TIMEOUT_MS` | 30000 | Default navigation budget |
| `FOXFETCH_MAX_BYTES` | 65536 | Output cap before spilling to a file |
| `FOXFETCH_ARTIFACT_TTL` | 86400 | Seconds before an artifact is deleted automatically |
| `FOXFETCH_ARTIFACT_MAX` | 67108864 | Artifact directory byte budget |
| `FOXFETCH_REMIND_AFTER` | 600 | Seconds before tool results start mentioning pending artifacts (0 disables) |
| `FOXFETCH_PY` | — | Interpreter the DSH plugin should start |

## Safety

`handoff` writes **live credentials** — cookies including the HttpOnly ones page script cannot
read. They land under `FOXFETCH_HOME`, owner-only, and expire after `FOXFETCH_ARTIFACT_TTL`.
Call `cleanup` when the task is delivered, and pass `keep=[...]` for the screenshot or token the
user still needs to look at.

You do not have to remember on your own: **every tool response carries the artifact state**, and
once a file is older than `FOXFETCH_REMIND_AFTER` (default 600 s) the response grows a `reminder`
saying how many files are still on disk and that they may hold credentials. The field vanishes
the moment `cleanup` runs, so a stale reminder is a visible bug, not a silent one.

## What it is not

- Not a screenshot tool, not a clicker, not a layout engine — Chromium does that, once it has
  the identity `handoff` exported.
- Not a session store. Every context is fresh; nothing survives `close`, and `handoff` output is
  meant to be deleted.
- Not a fingerprint randomiser. Guessing a profile that matches nobody is worse than sending a
  real Firefox.

## Development

```bash
pip install -e '.[dev]'
pytest -q          # 45 tests, no network
mypy src           # strict
python tools/push_via_api.py --repo <owner>/<name> --dry-run   # push when github.com:443 is reset
```

The tests encode the bugs this rewrite exists to prevent: a clip that split UTF-8 sequences, a
URL compare that ignored the trailing slash, `sameSite: "Default"` rejected by Playwright, a
`cleanup` that only deleted expired files, and a runaway browser left behind when the screenshot
threw.

## Licence

MIT. The engine (`ruyijs`) is a separate project under AGPL-3.0; foxfetch only calls it — no
ruyijs code is bundled.
