iframer-toolkit 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Eduardo Verona
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,280 @@
1
+ # iframer-toolkit
2
+
3
+ Browser access for AI agents when normal fetching fails. Give Claude, Codex, or any MCP-compatible agent a real browser — with session persistence, stealth fingerprinting, encrypted credential storage, and automatic captcha solving.
4
+
5
+ Ships as:
6
+ - **CLI** (`iframer-toolkit` / `iframer`) — browse, screenshot, credentials, sessions, reverse-engineer APIs
7
+ - **MCP server** — plugs directly into Claude Code or Codex so agents can drive the browser themselves
8
+ - **Self-hosted Docker server** (optional) — adds live headful browsing over noVNC for remote/multi-user setups
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ npm install -g iframer-toolkit
14
+ ```
15
+
16
+ Then pull in the runtime dependencies (Chrome for Testing + MCP registration):
17
+
18
+ ```sh
19
+ iframer-toolkit install deps
20
+ ```
21
+
22
+ This is shorthand for:
23
+
24
+ ```sh
25
+ iframer-toolkit install chromium # downloads Chrome for Testing to ~/.iframer
26
+ iframer-toolkit install-mcp # registers the MCP server in ~/.claude.json and ~/.codex/config.toml
27
+ ```
28
+
29
+ Restart Claude Code or Codex and the `iframer` tools will be available.
30
+
31
+ > **Note:** If you prefer, your agent can run `iframer-toolkit install deps` for you — it'll figure the rest out.
32
+
33
+ ## Quick start
34
+
35
+ Once installed, you can either drive the browser via the CLI directly, or ask your agent (Claude Code / Codex) to do it for you via the MCP.
36
+
37
+ **CLI:**
38
+
39
+ ```sh
40
+ iframer-toolkit status # system + browser modes
41
+ iframer-toolkit browse https://example.com --extract 'document.title'
42
+ iframer-toolkit screenshot https://news.ycombinator.com -o /tmp/hn.png
43
+ iframer-toolkit credentials add github.com # interactive masked prompt
44
+ iframer-toolkit reverse-engineer https://some-spa.com # capture the APIs it calls
45
+ iframer-toolkit --cache # list cached domains
46
+ ```
47
+
48
+ **From Claude Code or Codex** (after `install-mcp`):
49
+
50
+ > "Log into my account on example.com and extract the latest invoice."
51
+
52
+ The agent will call `knowledge` first (to see if a direct-API path is cached), fall back to `credentials` + `execute` if not, auto-escalate browser modes if a site blocks headless, and return the result. No copying cookies, no proxies, no manual login.
53
+
54
+ ## How it works
55
+
56
+ ```
57
+ Claude / Codex (MCP) ──→ iframer MCP server ──→ Iframer (local)
58
+ ├─ patchright (stealth Chromium)
59
+ ├─ Chrome for Testing
60
+ └─ SQLite at ~/.iframer — one file for
61
+ encrypted credentials, session state,
62
+ and per-domain knowledge cache
63
+ ```
64
+
65
+ By default, `install-mcp` runs in **local mode**: no Docker needed. The MCP spawns a stealth-patched Chromium (via [patchright](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright)) on your machine. `install-mcp` registers the server in both Claude Code (`~/.claude.json`) and Codex (`~/.codex/config.toml`).
66
+
67
+ **One credential store for every browser mode.** Stored credentials, session cookies/localStorage, and the knowledge cache all live in a single SQLite file at `~/.iframer/iframer.db`. Store a password once (via CLI or MCP) and every mode — `headless`, `binary-headful`, `docker-headful` — uses the same row. No split-brain between modes.
68
+
69
+ **Auto-escalation.** When a pipeline is blocked in `headless` (bot detection, captcha), iframer transparently retries in `binary-headful` and then `docker-headful` without a round-trip to the agent. The mode that worked is recorded in `~/.iframer/domain-modes.json` so the next run on that domain starts at the right mode.
70
+
71
+ **Knowledge cache.** After every successful run, iframer writes a per-domain markdown file at `~/.iframer/knowledge/<domain>.md` recording which cookies / localStorage keys / headers the site uses for auth, plus any API endpoints observed along the way. Next time the agent needs data from that domain, it reads the cache first — if there's a direct-API path, it skips the browser entirely. See [Knowledge cache](#knowledge-cache) below.
72
+
73
+ For live remote viewing, multi-user, or Linux server deployments, see [Self-hosting with Docker](#self-hosting-with-docker) below.
74
+
75
+ ## CLI reference
76
+
77
+ ```
78
+ iframer-toolkit <command> [args]
79
+
80
+ Pipeline:
81
+ execute <pipeline.json|json> Run a pipeline of browser steps
82
+ --mode <mode> Force browser mode (headless|binary-headful|docker-headful)
83
+ --capture-api Record XHR/fetch requests during execution
84
+ --continue-on-error Don't stop on step failure
85
+ --timeout <ms> Stale-state timeout (default: 20000)
86
+
87
+ Quick actions:
88
+ browse <url> Headless fetch with JS rendering
89
+ --extract <js> Evaluate JS and return result
90
+ --html Return full page HTML
91
+ --wait-for <selector> Wait for element before extracting
92
+ --sessionless Skip session persistence
93
+ screenshot <url> Take a screenshot of a URL
94
+ --annotate Overlay element badges with refs
95
+ -o, --output <path> Output file path
96
+ reverse-engineer <url|file> Capture API calls a site makes
97
+ --output <dir> Save directory
98
+ --typed Generate TypeScript
99
+
100
+ Session:
101
+ session stop Stop and save cookies/localStorage
102
+ session clear Wipe stored session data
103
+ session status Check session state
104
+
105
+ Credentials:
106
+ credentials add <domain> Store login credentials (encrypted)
107
+ --username <user> Username or email
108
+ --password <pass> Password (interactive masked prompt if omitted)
109
+ --totp-secret <secret> TOTP secret for 2FA
110
+ credentials list List domains with stored credentials
111
+ credentials remove <domain> Delete credentials for a domain
112
+
113
+ Knowledge cache:
114
+ --cache List all cached domains
115
+ --cache <domain> Print the cached knowledge for one domain
116
+ --clear-cache Wipe all cached knowledge
117
+ --clear-cache <domain> Wipe one domain's cache
118
+ knowledge list Same as --cache
119
+ knowledge get <domain> Same as --cache <domain>
120
+ knowledge clear [domain] Same as --clear-cache [domain]
121
+
122
+ Setup:
123
+ install chromium Download Chrome for Testing
124
+ install mcp Register MCP server in Claude Code and Codex
125
+ install deps Run both of the above
126
+ install-mcp [--dev] Same as `install mcp`
127
+ remove-mcp [--dev] Remove iframer MCP from Claude Code and Codex
128
+
129
+ Browser:
130
+ modes Show available browser modes
131
+ status Show system status
132
+ ```
133
+
134
+ The binary is available as either `iframer-toolkit` (full name) or `iframer` (short alias). `npx iframer-toolkit ...` also works without a global install.
135
+
136
+ ## MCP tools
137
+
138
+ Once the MCP is registered, the agent has access to:
139
+
140
+ - **`status`** — system health, session state, stored credentials, available browser modes
141
+ - **`knowledge`** — read / list / clear the per-domain knowledge cache. Agents are told to check this **before** every `execute` or `browse` — if the cache has a direct-API path for the data, the browser doesn't launch at all.
142
+ - **`execute`** — run a pipeline of browser steps (navigate, click, fill, human-click, human-type, scroll, wait, evaluate, extract, keyboard, login, solve-captcha, screenshot, snapshot, find). Each step has a 20s stale-state timeout. On failure, returns the exact step, error type, and a screenshot of the page at the point of failure. Auto-escalates browser modes transparently on bot-block.
143
+ - **`browse`** — fast headless fetch with session persistence for pages that don't need a full pipeline
144
+ - **`reverse-engineer`** — capture the APIs a site calls (feeds into the knowledge cache so future runs can skip the browser)
145
+ - **`session`** — `stop` (save state) or `clear` (wipe)
146
+ - **`credentials`** — `store` (secure form via MCP elicitation), `list`. The `store` action will **refuse to overwrite** existing credentials unless explicitly told to (`force: true`) — this blocks the common "login failed, re-ask for password" anti-pattern when the real problem is browser mode / bot detection.
147
+
148
+ ## Session persistence
149
+
150
+ Session data (cookies + localStorage) and credentials are stored in SQLite at `~/.iframer/iframer.db` and encrypted with AES-256-GCM. Data is automatically re-injected on the next `execute` or `browse` so agents stay logged in across restarts — and across browser modes: a session captured in `binary-headful` will transparently load into `headless` on the next run.
151
+
152
+ The encryption key lives at `~/.iframer/secret` (0600 permissions), generated on first `install-mcp`. Set `IFRAMER_SECRET` in your environment to override it — useful if you want to synchronize the key across multiple machines.
153
+
154
+ ## Knowledge cache
155
+
156
+ Every successful `execute` run updates a plain markdown file at `~/.iframer/knowledge/<domain>.md` — human-readable, grep-able, and editable. Each file captures:
157
+
158
+ - Which cookies, localStorage keys, and headers are load-bearing for authentication (names only — values stay encrypted in the session store)
159
+ - Which API endpoints the site called during the run (with method, path, example curl, and status code)
160
+ - Which browser mode last worked for the domain
161
+ - Notes about captcha/bot-detection behavior
162
+
163
+ The MCP `knowledge` tool exposes this to the agent with `get`, `list`, and `clear` actions. Agents are instructed to call it **before** every browser-touching tool — if the cache already knows a direct-API path for the data the user is asking about, the agent hits the API directly and never launches a browser. First request takes seconds; repeat requests on the same domain take milliseconds.
164
+
165
+ Inspect the cache yourself:
166
+
167
+ ```sh
168
+ iframer-toolkit --cache # list all cached domains
169
+ iframer-toolkit --cache figma.com # print the markdown for one domain
170
+ iframer-toolkit --clear-cache # wipe all cached knowledge
171
+ iframer-toolkit --clear-cache figma.com # wipe one domain
172
+ ```
173
+
174
+ ## Captcha solving
175
+
176
+ iframer auto-detects and solves reCAPTCHA and hCaptcha using Claude's vision API. Use the `solve-captcha` step in a pipeline:
177
+
178
+ ```json
179
+ { "type": "solve-captcha" }
180
+ ```
181
+
182
+ Requires `ANTHROPIC_API_KEY` in your environment.
183
+
184
+ ## Environment variables
185
+
186
+ | Variable | Required | Description |
187
+ |---------------------|----------|-------------|
188
+ | `ANTHROPIC_API_KEY` | For captcha | Used for vision-based captcha solving |
189
+ | `IFRAMER_SECRET` | No | Encryption key for sessions & credentials. Defaults to the value at `~/.iframer/secret` (auto-generated on first `install-mcp`). Override in the shell or in `.env` to pin a specific key. |
190
+ | `IFRAMER_DATA_DIR` | No | Override the data directory. Default: `~/.iframer`. The Docker container sets this to `/iframer-data` so a bind mount makes host and container share one database. |
191
+ | `IFRAMER_MODE` | No | `local` (default) or `docker`. Force a mode regardless of what's running. |
192
+ | `IFRAMER_URL` | No | Docker API URL when self-hosting (default: `http://localhost:3021`). |
193
+
194
+ ## Self-hosting with Docker
195
+
196
+ The Docker server adds a live headful browsing mode over noVNC (watch the agent drive the browser in real time) and lets multiple clients share one browser pool. The Docker path is only used when the pipeline explicitly requests `mode: "docker-headful"` — `headless` and `binary-headful` always run directly on the host even when Docker is up, so host-stored credentials are always visible.
197
+
198
+ The `docker-compose.yml` bind-mounts `~/.iframer` from the host into the container as `/iframer-data` and sets `IFRAMER_DATA_DIR=/iframer-data`, so **container and host share the same SQLite file**. Credentials stored via the CLI or MCP on the host are immediately visible to `docker-headful` without any copy step.
199
+
200
+ **1. Clone and configure**
201
+
202
+ ```sh
203
+ git clone https://github.com/EduardoFazolo/iframer-toolkit.git
204
+ cd iframer-toolkit
205
+ cp .env.example .env
206
+ # Edit .env — set ANTHROPIC_API_KEY (for captcha) and IFRAMER_SECRET (for auth)
207
+ ```
208
+
209
+ **2. Start**
210
+
211
+ ```sh
212
+ bun run start:docker # docker compose up --build -d
213
+ bun run logs:docker # tail container logs
214
+ bun run stop:docker # stop containers
215
+ ```
216
+
217
+ **3. Point the MCP at it (remote host only)**
218
+
219
+ If you're running Docker on a remote machine and the MCP on a different machine, install the MCP with the remote URL:
220
+
221
+ ```sh
222
+ IFRAMER_URL=https://your-host:3021 iframer-toolkit install-mcp --dev
223
+ ```
224
+
225
+ When Docker is on the same host as the MCP, no extra setup is needed — the local MCP server will auto-detect the Docker API on `localhost:3021` and route only `docker-headful` requests through it.
226
+
227
+ **4. Watch the browser live**
228
+
229
+ When a `docker-headful` session is active, open noVNC:
230
+
231
+ ```
232
+ http://your-host:6080
233
+ ```
234
+
235
+ Or run `iframer-toolkit watch` to auto-open it.
236
+
237
+ ## Architecture
238
+
239
+ | Component | Technology |
240
+ |--------------------|------------|
241
+ | Browser engine | [patchright](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright) (stealth-patched Playwright fork) |
242
+ | Browser binary | Chrome for Testing (downloaded to `~/.iframer/chrome/`) |
243
+ | Stealth | Fingerprint injection, WebRTC leak prevention, worker patching |
244
+ | Credential store | SQLite at `~/.iframer/iframer.db`, AES-256-GCM encrypted, shared by every browser mode |
245
+ | Session persistence| Same SQLite file — cookies + localStorage re-injected across runs and modes |
246
+ | Knowledge cache | Plain markdown at `~/.iframer/knowledge/<domain>.md` |
247
+ | Captcha solving | Anthropic vision API (`@anthropic-ai/sdk`) |
248
+ | Live viewing | Xvfb + x11vnc + noVNC + websockify (Docker mode only) |
249
+ | MCP server | `@modelcontextprotocol/sdk` |
250
+ | Runtime | Node.js ≥18 (Bun for development) |
251
+
252
+ ## Development
253
+
254
+ ```sh
255
+ git clone https://github.com/EduardoFazolo/iframer-toolkit.git
256
+ cd iframer-toolkit
257
+ bun install
258
+
259
+ # Run the CLI from source (no build needed — bun runs .ts directly)
260
+ bun run bin/cli.js status
261
+
262
+ # Run the MCP server from source
263
+ bun run src/mcp/server.ts
264
+
265
+ # Run the Docker API server from source (no Docker)
266
+ bun run start # bun run index.ts
267
+
268
+ # Rebuild the distributable bundles (dist/cli.cjs + dist/mcp-server.cjs)
269
+ bun run build
270
+
271
+ # Install the locally-built package globally for testing
272
+ npm pack
273
+ npm install -g ./iframer-toolkit-*.tgz
274
+ ```
275
+
276
+ `prepublishOnly` runs `bun run build` automatically, so `npm publish` always ships a fresh bundle.
277
+
278
+ ## License
279
+
280
+ MIT