oxibrowser 0.11.0

Headless browser engine with CDP support
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<div align="center">

# 🌐 OxiBrowser

**The headless browser built in pure Rust for AI agents.**

Not a Chromium fork. Not a C++ wrapper. A browser engine written from scratch in Rust,
designed from day one for automation, web scraping, and AI-driven workflows.

[![crates.io](https://img.shields.io/crates/v/oxibrowser?style=flat-square&logo=rust&color=orange)](https://crates.io/crates/oxibrowser)
[![docs.rs](https://img.shields.io/docsrs/oxibrowser?style=flat-square&color=blue)](https://docs.rs/oxibrowser)
[![License: AGPL-3.0](https://img.shields.io/badge/license-AGPL--3.0-blue?style=flat-square)](https://github.com/a7garden/oxibrowser/blob/main/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/a7garden/oxibrowser?style=flat-square&logo=github&color=yellow)](https://github.com/a7garden/oxibrowser/stargazers)
[![CI](https://img.shields.io/github/actions/workflow/status/a7garden/oxibrowser/ci.yml?branch=main&style=flat-square&logo=github)](https://github.com/a7garden/oxibrowser/actions)
[![Rust](https://img.shields.io/badge/rust-1.82%2B-orange?style=flat-square&logo=rust)](https://www.rust-lang.org/)

[Report Bug](https://github.com/a7garden/oxibrowser/issues) Β· [Request Feature](https://github.com/a7garden/oxibrowser/issues) Β· [Read the Docs](https://github.com/a7garden/oxibrowser/blob/main/docs/ARCHITECTURE.md) Β· [Discord](https://discord.gg/oxibrowser)

</div>

---

<div align="center">

<table>
<tr>
<td align="center"><strong>21 MB</strong><br><sub>Single static binary</sub></td>
<td align="center"><strong>~50 ms</strong><br><sub>Cold start time</sub></td>
<td align="center"><strong>~8 MB</strong><br><sub>Base memory</sub></td>
<td align="center"><strong>279 tests</strong><br><sub>Full coverage</sub></td>
<td align="center"><strong>Zero C deps</strong><br><sub>Pure Rust</sub></td>
</tr>
</table>

<table>
<tr>
<th>OxiBrowser</th>
<th>Headless Chrome</th>
<th>Lightpanda</th>
</tr>
<tr>
<td align="center">21 MB binary</td>
<td align="center">~400 MB install</td>
<td align="center">~80 MB binary</td>
</tr>
<tr>
<td align="center">~8 MB RAM base</td>
<td align="center">~200 MB RAM base</td>
<td align="center">~30 MB RAM base</td>
</tr>
<tr>
<td align="center">~50 ms startup</td>
<td align="center">~800 ms startup</td>
<td align="center">~10 ms startup</td>
</tr>
<tr>
<td align="center">Pure Rust (boa)</td>
<td align="center">C++ (V8)</td>
<td align="center">Zig (V8)</td>
</tr>
<tr>
<td align="center">AGPL-3.0-only</td>
<td align="center">BSD / ToS</td>
<td align="center">AGPL-3.0</td>
</tr>
</table>

</div>

---

## ✨ Why OxiBrowser?

**You're building AI agents that need to browse the web.** You don't need a full browser with GPU rendering, audio output, and extension support. You need something fast, small, and programmable.

OxiBrowser is built for exactly that use case:

- πŸ€– **AI-Agent First** β€” Native `OXI` CDP domain with `getMarkdown()`, `getPageInfo()`, and text-first rendering
- ⚑ **Blazing Fast** β€” Cold starts in ~50ms, no Chromium overhead, no Node.js required
- πŸ¦€ **Pure Rust** β€” Zero C dependencies. `boa_engine` for JS (no V8). Single static binary. Memory-safe.
- πŸ”Œ **CDP Compatible** β€” Puppeteer, Playwright, and any Chrome DevTools Protocol client works out of the box
- πŸ›‘οΈ **Secure by Default** β€” SSRF protection with CIDR blocking, `robots.txt` respect, no sandbox escape surface
- πŸ“¦ **Tiny Footprint** β€” 21 MB binary, ~8 MB base memory. Run 100 instances without breaking a sweat

---

## πŸš€ Quick Start

### Install

**Cargo (all platforms)**

```bash
cargo install oxibrowser
```

**Build from source**

```bash
git clone https://github.com/a7garden/oxibrowser.git
cd oxibrowser
cargo build --release
# Binary at ./target/release/oxibrowser
```

**Use as a library**

```toml
# Cargo.toml
[dependencies]
oxibrowser-core = "0.7"
```

### Fetch a page

```bash
oxibrowser fetch https://example.com
```

### Start CDP server

```bash
oxibrowser serve --port 9222
```

Then connect with Puppeteer:

```javascript
import puppeteer from 'puppeteer-core';

const browser = await puppeteer.connect({
  browserWSEndpoint: 'ws://127.0.0.1:9222',
});

const page = await browser.newPage();
await page.goto('https://news.ycombinator.com');

// Get markdown β€” OxiBrowser's AI-native feature
const md = await page.evaluate(() => {
  // OXI domain available in evaluate context
});

console.log(await page.title());
await browser.close();
```

### Rust API

```rust
use oxibrowser_core::Browser;
use oxibrowser_core::config::BrowserConfig;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let browser = Browser::new(BrowserConfig::default()).await?;
    let session = browser.new_session().await?;
    
    session.navigate("https://example.com").await?;
    
    let title = session.evaluate("document.title").await?;
    println!("Title: {:?}", title);
    
    Ok(())
}
```

---

## πŸ— Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚            Puppeteer / Playwright / Rust CDP          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ CDP WebSocket
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 CDP Server (10 domains)               β”‚
β”‚  Browser Β· DOM Β· Fetch Β· Input Β· Network             β”‚
β”‚  OXI Β· Page Β· Runtime Β· Target                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚          Browser β†’ Session β†’ Page β†’ Frame            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  WebAPI  β”‚  Network β”‚  JS Runtime  β”‚  CSS Rendering  β”‚
β”‚  DOM     β”‚  HTTP    β”‚  boa_engine  β”‚  PNG screenshot β”‚
β”‚  Tree    β”‚  Cookies β”‚  ES2024+     β”‚  ASCII/Unicode  β”‚
│  Storage │  SSRF    │  persistent  │  text→image     │
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   html5ever Β· encoding_rs Β· reqwest Β· image Β· boa    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Crate Structure

| Crate | Lines | Purpose |
|-------|-------|---------|
| [`oxibrowser`]crates/oxibrowser/ | 1,233 | Binary + CLI (`fetch`, `serve`, `version`) |
| [`oxibrowser-core`]crates/oxibrowser-core/ | 12,953 | Browser engine: Session, Page, Frame, JS Runtime |
| [`oxibrowser-cdp`]crates/oxibrowser-cdp/ | 4,392 | CDP WebSocket server with 10 domain handlers |
| [`oxibrowser-webapi`]crates/oxibrowser-webapi/ | 1,549 | DOM tree, CSS selectors, Markdown conversion |
| **Total** | **20,127** | |

---

## 🌟 Features

### JavaScript Runtime (ES2024+)

Powered by [`boa_engine`](https://boajs.dev/) β€” pure Rust, no V8 dependency:

| Web API | Status |
|---------|--------|
| `document.querySelector` / `querySelectorAll` | βœ… Full |
| `document.createElement` / `createTextNode` | βœ… Full |
| `element.appendChild` / `removeChild` / `insertBefore` | βœ… Full |
| `element.getAttribute` / `setAttribute` / `removeAttribute` | βœ… Full |
| `element.cloneNode` / `remove()` | βœ… Full |
| `element.style` (CSSStyleDeclaration) | βœ… Property accessor |
| `element.classList` (DOMTokenList) | βœ… Property accessor |
| `element.textContent` / `innerHTML` | βœ… Read/Write |
| `element.addEventListener` / `dispatchEvent` | βœ… Full |
| `element.click()` | βœ… With event handlers |
| `fetch()` | βœ… Full (channel bridge) |
| `XMLHttpRequest` | βœ… Full with callbacks |
| `localStorage` | βœ… Persistent |
| `MutationObserver` | βœ… observe/disconnect/takeRecords |
| `setTimeout` / `setInterval` | βœ… TokioJobQueue |
| `console.log/warn/error` | βœ… With formatting |
| `URL` / `URLSearchParams` | βœ… Full |
| `crypto.getRandomValues` | βœ… Pseudo-random |
| `TextEncoder` / `TextDecoder` | βœ… UTF-8 |
| `atob` / `btoa` | βœ… Base64 |
| `requestAnimationFrame` | βœ… Polyfill |

### CDP Protocol (Chrome DevTools Protocol)

10 domain handlers β€” Puppeteer and Playwright compatible:

| Domain | Key Methods |
|--------|------------|
| **Browser** | `getVersion`, `close` |
| **DOM** | `getDocument`, `describeNode`, `querySelector`, `querySelectorAll` |
| **Fetch** | `enable/disable`, `continueRequest`, `failRequest`, `fulfillRequest`, `getResponseBody` |
| **Input** | `dispatchKeyEvent`, `dispatchMouseEvent`, `insertText` |
| **Network** | `enable/disable`, `setExtraHTTPHeaders`, `getResponseBody` |
| **OXI** πŸ€– | `getMarkdown`, `getPageInfo` β€” AI-native extensions |
| **Page** | `navigate`, `captureScreenshot`, `getFrameTree`, `getTitle` |
| **Runtime** | `evaluate`, `callFunctionOn`, `enable`, `consoleAPICalled` |
| **Target** | `getTargets`, `attachToTarget`, `detachFromTarget` |

### OXI Domain β€” Built for AI Agents

The `OXI` CDP domain provides AI-optimized APIs that no other browser offers:

```python
import websockets, json, asyncio

async def ai_scrape():
    ws = await websockets.connect('ws://localhost:9222/ws')
    
    # Navigate
    await ws.send(json.dumps({
        "id": 1, "method": "Page.navigate",
        "params": {"url": "https://news.ycombinator.com"}
    }))
    await asyncio.sleep(2)
    
    # Get clean markdown β€” perfect for LLM ingestion
    await ws.send(json.dumps({
        "id": 2, "method": "OXI.getMarkdown"
    }))
    resp = json.loads(await ws.recv())
    print(resp['result']['markdown'])  # Clean markdown output
    
    # Get structured page info
    await ws.send(json.dumps({
        "id": 3, "method": "OXI.getPageInfo"
    }))
    info = json.loads(await ws.recv())
    print(info['result'])  # title, url, status, content-type, etc.
```

### Network Layer

| Feature | Description |
|---------|-------------|
| **HTTP Client** | `reqwest` with cookie persistence, redirect following |
| **Cookie Jar** | Domain-scoped cookie storage with `Set-Cookie` parsing |
| **SSRF Protection** | CIDR blocking for private network ranges |
| **robots.txt** | RFC 9309 compliant parser, `--obey-robots` flag |
| **Network Interception** | Pause, modify, or block any request via Fetch domain |
| **Custom Headers** | Per-session and per-request header injection |
| **Charset Detection** | `encoding_rs` for automatic charset detection and conversion |

### CSS Text Rendering

- **ASCII/Unicode text output** β€” Render DOM to readable text with proper indentation
- **Markdown conversion** — Full HTML→Markdown with heading, link, and list support
- **PNG screenshots** β€” Built-in 8Γ—16 bitmap font, renders text content as images
- **No external dependencies** β€” Font data embedded in binary

---

## πŸ§ͺ Testing

```bash
# Run all 279 tests
cargo test --workspace

# E2E CDP tests (23 tests with real WebSocket)
cargo test -p oxibrowser-cdp

# Integration tests (real websites, --ignored)
cargo test --workspace -- --ignored

# Puppeteer smoke tests
cargo test -p oxibrowser --test smoke
```

---

## πŸ“‹ CLI Reference

```
oxibrowser 0.7.0
Headless browser with CDP support

USAGE:
    oxibrowser <COMMAND>

COMMANDS:
    fetch     Fetch and render a URL
    serve     Start CDP WebSocket server
    version   Print version information

FETCH OPTIONS:
    <URL>                  URL to fetch
    --dump <FORMAT>        Output format: text, html, markdown [default: text]

SERVE OPTIONS:
    --host <HOST>          Bind address [default: 127.0.0.1]
    --port <PORT>          Bind port [default: 9222]
    --obey-robots          Respect robots.txt
    --log-level <LEVEL>    Log level: trace, debug, info, warn, error [default: info]
```

---

## πŸ”§ Advanced Usage

### Custom Browser Configuration

```rust
use oxibrowser_core::{Browser, config::BrowserConfig};
use std::time::Duration;

let config = BrowserConfig {
    user_agent: "MyBot/1.0".to_string(),
    timeout: Duration::from_secs(30),
    obey_robots: true,
    max_redirects: 10,
    ..Default::default()
};

let browser = Browser::new(config).await?;
```

### Request Interception

```javascript
// With Puppeteer
const client = await page.target().createCDPSession();

await client.send('Fetch.enable', {
    patterns: [{ urlPattern: '*ads*' }]
});

client.on('Fetch.requestPaused', async ({ requestId }) => {
    // Block ad requests
    await client.send('Fetch.failRequest', {
        requestId,
        reason: 'BlockedByClient'
    });
});
```

### Screenshot Capture

```javascript
// PNG screenshot via CDP
const { data } = await client.send('Page.captureScreenshot', {
    format: 'png'
});
// data is base64-encoded PNG
```

---


## 🀝 Contributing

Contributions are welcome! Whether it's:

- πŸ› **Bug reports** β€” [Open an issue]https://github.com/a7garden/oxibrowser/issues
- πŸ’‘ **Feature requests** β€” [Start a discussion]https://github.com/a7garden/oxibrowser/issues
- πŸ”§ **Pull requests** β€” Fork, branch, PR. All PRs need passing tests.
- πŸ“– **Documentation** β€” Fix typos, add examples, improve guides

### Development Setup

```bash
git clone https://github.com/a7garden/oxibrowser.git
cd oxibrowser
cargo build
cargo test --workspace
cargo clippy --workspace -- -D warnings
```

---

## πŸ“„ License

OxiBrowser is a derivative work of [Lightpanda](https://github.com/lightpanda-io/browser) (AGPL-3.0).
As such, OxiBrowser is licensed under the [GNU Affero General Public License v3](LICENSE).

See [NOTICE.md](NOTICE.md) for detailed attribution.

---

## πŸ™ Acknowledgments

- [Lightpanda]https://github.com/lightpanda-io/browser β€” Architecture inspiration (Browser β†’ Session β†’ Page β†’ Frame hierarchy)
- [boa_engine]https://boajs.dev/ β€” Pure Rust JavaScript engine (ES2024+)
- [html5ever]https://github.com/servo/html5ever β€” HTML parser from the Servo project
- [reqwest]https://github.com/seanmonstar/reqwest β€” Ergonomic HTTP client for Rust
- [tokio]https://tokio.rs/ β€” Async runtime powering the entire networking stack

---

<div align="center">

**[⬆ Back to Top](#-oxibrowser)**

Made with πŸ¦€ in Rust

</div>