Metadata-Version: 2.5
Name: foxfetch
Version: 0.1.0
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.**

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.

---

## 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

```bash
pip install foxfetch
python -m foxfetch doctor          # python, ruyijs, mcp, chromium, artifacts
```

Then wire it into a host — see [SETUP.md](SETUP.md) for the per-host steps. The short version:

```bash
# Pi, Claude Code, Codex and other MCP clients
php -r '' 2>/dev/null; # (no shell hook needed) — add an mcpServers entry:
#   "command": "python", "args": ["-m", "foxfetch", "serve"]

# DeepSeek Harness: install the plugin in dsh/, which forwards to the same service
```

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

## 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_REMIND_AFTER` | 600 | Seconds before tool results start mentioning pending artifacts (0 disables) |
| `FOXFETCH_PY` | — | Interpreter the DSH plugin should use |

## 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.

## Development

```bash
pip install -e '.[dev]'
pytest -q
mypy src
```

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,
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.
