The headless browser for AI agents and web scraping
docs(render): publish automation guide
SGavrl329514302532
diff --git a/AGENTS.md b/AGENTS.mdindex 91fc1f07..c272a1ef 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -4,15 +4,18 @@ Guidance for AI coding agents and contributors working in the Obscura repo.This is the non-obvious stuff you can't infer from the code; read it beforebuilding, testing, or changing anything.-Obscura is a headless browser engine in Rust. It runs real JavaScript through-V8 (`deno_core`), keeps a real DOM tree, speaks the Chrome DevTools Protocol,-and is a drop-in replacement for headless Chrome with Puppeteer and Playwright.-It targets web scraping and AI-agent automation.+Obscura is a headless browser engine in Rust. It runs JavaScript through V8+(`deno_core`), owns its DOM, layout, and paint pipeline, and speaks the Chrome+DevTools Protocol for Puppeteer and Playwright automation. It targets web+scraping and AI-agent workflows without bundling Chromium.## Build```bash-cargo build --release # binary at ./target/release/obscura+CARGO_INCREMENTAL=0 CARGO_BUILD_JOBS=2 cargo build --release --features render++# Rendering plus the optional stealth transport+CARGO_INCREMENTAL=0 CARGO_BUILD_JOBS=2 cargo build --release --features render,stealth```- The first build compiles V8 from source: ~5 minutes and a few GB of disk.@@ -20,9 +23,9 @@ cargo build --release # binary at ./target/release/obscura- **Iterating on one crate? Scope it:** `cargo build -p obscura-cli`. A bare`cargo build` can re-link the whole workspace; the V8 compile is the cost, soavoid touching it when you don't need to.-- **Stealth:** `cargo build --release --features stealth` pulls in BoringSSL+- **Stealth:** `--features render,stealth` pulls in BoringSSL(`btls-sys`), which builds through CMake, so `cmake` must be installed. The- default build uses rustls and needs neither CMake nor OpenSSL.+ render-only build uses rustls and needs neither CMake nor OpenSSL.- If the vendored OpenSSL build hits an AVX-512 assembler error on your host,build with `OPENSSL_NO_VENDOR=1`.@@ -31,15 +34,16 @@ cargo build --release # binary at ./target/release/obscuraRun tests with **`cargo nextest`, not `cargo test`**:```bash-cargo nextest run --workspace # or: -p <crate> while iterating+cargo nextest run --release --features render -p <crate>+cargo nextest run --release --features render --no-fail-fast````cargo test` runs the whole test binary in one process, but the engine holds asingle V8 isolate per process, so the runtime tests fail under it. `nextest`runs each test in its own process, which is the only supported way.-The authoritative behavioral gate is the **obstacle course** in the companion-repo `obscura-benchmark` (33 capability + speed stages, must stay 33/33):+The obstacle course in the companion `obscura-benchmark` repository is an+additional behavioral gate:```bashOBSCURA_BIN=./target/release/obscura python3 obstacle-course/run.py --runs 1 --warmup 0@@ -53,10 +57,12 @@ pass %, not whole-file pass.For any code change:-1. `cargo build --release` (or `-p <crate>`) compiles clean.-2. `cargo nextest run` for the crates you touched.-3. The obstacle course still reports **33/33**.-4. For stealth changes, re-test with `--stealth` (a non-stealth binary won't+1. Run focused release-mode nextest coverage for the crates and repro involved.+2. Run `cargo nextest run --release --features render --no-fail-fast`.+3. Run the exact release build shown above.+4. For render changes, run deterministic fixtures and broad top/bottom real-site+ captures using the methodology below.+5. For stealth changes, re-test with `--stealth` (a non-stealth binary won'texercise the `wreq` path).Do not bulk-run `cargo fmt`: the tree is not rustfmt-clean, so a blanket format@@ -65,25 +71,59 @@ edit instead.## Architecture-- **obscura-cli** — CLI: `fetch` (`--dump assets|html|text|links|markdown|original|cookies`, `--eval <JS>`), `serve` (CDP server), `scrape`, `mcp`. `--proxy`, `--stealth`, and `--allow-private-network` are global flags: valid before or after the subcommand and applied to `fetch`, `serve`, `scrape`, and `mcp` (a `scrape` run forwards `--stealth` to each worker via `OBSCURA_STEALTH`).+- **obscura-cli** — CLI: `fetch` (`--dump assets|html|text|links|markdown|original|cookies`, `--eval <JS>`, `--screenshot <PNG>`), `serve` (CDP server), `scrape`, `mcp`. `--proxy`, `--stealth`, and `--allow-private-network` are global flags: valid before or after the subcommand and applied to `fetch`, `serve`, `scrape`, and `mcp` (a `scrape` run forwards `--stealth` to each worker via `OBSCURA_STEALTH`).- **obscura-cdp** — Chrome DevTools Protocol server (WebSocket). Sessions are `"{targetId}-session"`.- **obscura-js** — V8/`deno_core` runtime. `js/bootstrap.js` is the DOM/browser shim; `src/ops.rs` bridges JS to Rust DOM ops; `src/runtime.rs` owns the isolate and the per-page `ObscuraState`.- **obscura-dom** — DOM tree (`src/tree.rs`).- **obscura-net** — HTTP client (`client.rs`), stealth client (`wreq_client.rs`), cookie jar, robots cache, tracker blocklist.- **obscura-browser** — the `Page` type, navigation, JS evaluation.+- **obscura-render** — selector cascade, computed style, retained layout,+ scrolling, text shaping, images/SVG/canvas, and CPU-backed paint. The+ `render` feature powers geometry, screenshots, CDP screencasting, and PDF.+- **obscura-mcp** — stateful MCP automation tools. Render builds expose+ `browser_screenshot` and `browser_pdf`; streaming screencasts remain CDP-only.- **obscura** — embeddable Rust library API (git dependency; builds V8 locally, not on crates.io). Public request-interception API on `Page`: `add_preload_script`, `enable_interception` (channel of `InterceptedRequest`, resolved with `InterceptResolution::{Continue, Fulfill, Fail}`), and passive `on_request` / `on_response`. `op_fetch_url` invokes these for JS `fetch()`/XHR, so when touching it keep a `Continue` URL rewrite behind `validate_fetch_url` (the SSRF gate, same as redirects).## Conventions-- **Performance is a hard constraint** (Obscura is ~12x faster and uses ~6x less- memory than headless Chrome on framework pages). Keep native Rust fast paths;- add a JS fallback only for real spec edge cases, and benchmark old-vs-new- interleaved, min-of-N (noise floor is about +-10%).+- **Performance is a hard constraint.** Keep native Rust fast paths and avoid+ repeated full-tree work. Benchmark old and new revisions interleaved with the+ same release build, page, network, viewport, settle policy, and capture path.+ Report distributions and resource use, not a single favorable run.- **Keep ops panic-safe.** `op_dom` is wrapped in `catch_unwind` so a DOM-oppanic returns null instead of aborting the process inside V8's FFI frame. Newops must not unwind into V8.- **Commits/PRs/comments:** short and factual, no em dashes, no AI filler.+## Rendering verification++Use deterministic fixtures before real sites. Put generated output in a+disposable directory outside the repository:++```bash+RUN_ROOT="$(mktemp -d)"+OBSCURA_BIN=./target/release/obscura render-repros/run.sh "$RUN_ROOT/fixtures"+OBSCURA_BIN=./target/release/obscura render-repros/representative-suite/run.sh "$RUN_ROOT/top"+OBSCURA_BIN=./target/release/obscura render-repros/representative-suite/run.sh "$RUN_ROOT/bottom" bottom+```++The harness accepts `BASELINE_BIN` or `CHROMIUM_BIN` for paired output. A+latency-only run may use `SUITE_MODE=latency SETTLE_MS=0`, but zero settle is+not valid fidelity evidence.++Compare the same viewport, device scale, identity, network inputs, settle+policy, scroll position, animation time, and capture boundary. First confirm+both navigations succeeded and both images are nonblank. Then inspect missing+resources, geometry, text flow, structural edges, clipping, fixed/sticky+behavior, and a reduced fixture. Pixel-distance metrics are useful regression+tripwires, not standalone correctness verdicts. Never add hostname-specific+layout, style, or resource behavior.++`render-repros/**` is the tracked public evidence harness. Git-ignored internal+handover notes are private working material: do not edit them, link them from+public documentation, stage them, or commit them. Do not commit generated+screenshots or reports.+## Gotchas- **DOM mutation arg order:** `insertBefore` / `replaceChild` in `bootstrap.js`@@ -122,30 +162,3 @@ adjustments) are privacy-first anti-fingerprinting: they present a normal,consistent browser fingerprint (user agent, timezone, navigator properties, andsimilar surfaces) so ordinary automation traffic is not singled out. Theycontain no bot or automation-abuse payload.--## Recommended proxy provider: NodeMaven--For production scraping you usually want residential or ISP IPs rather than a-datacenter address, since many sites block datacenter ranges. We use-**NodeMaven** and it works well with Obscura: residential/ISP proxies, sticky-sessions, and per-request country/region targeting. A good default if you don't-already have a provider.--Route Obscura through it with the global `--proxy` flag (use your own-credentials):--```bash-# HTTP-obscura --proxy http://USER:[email protected]:8080 fetch https://example.com --dump text--# SOCKS5-obscura --proxy socks5://USER:[email protected]:1080 scrape url1 url2 --concurrency 25-```--The targeting options (country, region, session id) live in the proxy username,-so a sticky session keeps the same exit IP across requests.--Sign up: https://go.nodemaven.com/obscuraagent--Obscura discount codes: `OBSCURA35` (35% off mobile and residential),-`OBSCURA40` (40% off ISP / static).diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex bb73cfbc..5f6ea28c 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -30,14 +30,14 @@ A few notes to keep the project maintainable:## Building```bash-cargo build --release # binary at ./target/release/obscura+cargo build --release --features render # binary at ./target/release/obscura```- The first build compiles V8 from source: roughly 5 minutes and a few GB ofdisk. Incremental builds are seconds.- Iterating on one crate? Scope it: `cargo build -p obscura-cli`.-- **Stealth** (`--features stealth`) pulls in BoringSSL through CMake, so `cmake`- must be installed. The default build uses rustls and needs neither CMake nor+- **Stealth** (`--features render,stealth`) pulls in BoringSSL through CMake, so `cmake`+ must be installed. The render-only build uses rustls and needs neither CMake norOpenSSL.- If the vendored OpenSSL build hits an AVX-512 assembler error on your host,build with `OPENSSL_NO_VENDOR=1`.@@ -47,7 +47,8 @@ cargo build --release # binary at ./target/release/obscuraRun tests with **`cargo nextest`, not `cargo test`**:```bash-cargo nextest run --workspace # or -p <crate> while iterating+cargo nextest run --release --features render -p <crate>+cargo nextest run --release --features render --no-fail-fast````cargo test` runs the whole test binary in one process, but the engine holds a@@ -68,15 +69,21 @@ It serves local fixtures, so it is deterministic and offline.For any code change:-1. `cargo build --release` (or `-p <crate>`) compiles clean.-2. `cargo nextest run` passes for the crates you touched.-3. The obstacle course still reports **33/33**.-4. **Performance is a hard constraint.** Obscura is roughly 12x faster and uses- about 6x less memory than headless Chrome on framework pages. Keep the native- Rust fast paths and add a JS fallback only for real spec edge cases. If your- change could affect performance, benchmark old vs new interleaved, min-of-N- (the noise floor is about plus or minus 10%).-5. For stealth changes, re-test with `--stealth`. A non-stealth binary does not+1. `cargo nextest run --release --features render` passes for the crates you touched.+2. The full render-feature nextest command above passes.+3. `CARGO_INCREMENTAL=0 CARGO_BUILD_JOBS=2 cargo build --release --features render` compiles clean.+4. The obstacle course still reports **33/33**.+5. **Performance is a hard constraint.** Keep native Rust fast paths and avoid+ repeated full-tree work. If your change could affect performance, benchmark+ old and new revisions interleaved with identical release builds, fixtures,+ networks, viewport, settle policy, and capture path. Report a distribution+ and memory use rather than a single favorable run.+6. For rendering changes, run the deterministic `render-repros` fixtures and+ the representative real-site suite at both the top and bottom of pages.+ Confirm resource and navigation success before interpreting image diffs;+ pixel error is a tripwire, not a verdict. Never add hostname-specific layout+ or style behavior.+7. For stealth changes, re-test with `--stealth`. A non-stealth binary does notexercise the `wreq` path.Keep ops panic-safe: a panic in an op must degrade to a null result, neverdiff --git a/README.md b/README.mdindex bcce3f6f..e9994b08 100644--- a/README.md+++ b/README.md@@ -18,21 +18,24 @@----Obscura is a headless browser engine written in Rust, built for web scraping and AI agent automation. It runs real JavaScript via V8, supports the Chrome DevTools Protocol, and acts as a drop-in replacement for headless Chrome with Puppeteer and Playwright.+Obscura is a headless browser engine written in Rust for web scraping and AI-agent automation. It runs JavaScript through V8, owns its DOM, layout, and paint pipeline, and exposes Chrome DevTools Protocol (CDP) compatibility for common Puppeteer and Playwright workflows.### Why Obscura over headless Chrome?Designed for automation at scale, not desktop browsing.-| Metric | Obscura | Headless Chrome |-|--------------|--------------|------------------|-| Memory | **30 MB** | 200+ MB |-| Binary size | **70 MB** | 300+ MB |-| Anti-detect | **Built-in** | None |-| Page load | **85 ms** | ~500 ms |-| Startup | **Instant** | ~2s |-| Puppeteer | **Yes** | Yes |-| Playwright | **Yes** | Yes |+| Capability | Obscura | Headless Chrome |+|------------|---------|-----------------|+| JavaScript and DOM | V8 + native Rust DOM | V8 + Blink |+| Puppeteer / Playwright | CDP compatibility | Native |+| Screenshots | PNG, JPEG, lossless WebP | Yes |+| Screencasting | Activity-driven CDP frames | Yes |+| PDF | Raster-backed print output | Vector/text-aware output |+| Deployment | Single-purpose browser binary | Full browser distribution |++Performance varies substantially by page, hardware, network, build features,+and capture settings. Use the published benchmark suite, or measure your own+workload with identical inputs, before making capacity decisions.## 🎉 10,000 stars and what's next@@ -176,7 +179,7 @@ No Chrome, no Node.js, no dependencies. Release archives include both`obscura` and `obscura-worker`; keep them in the same directory for theparallel `scrape` command.-Default archive names contain the lean binary. Archives ending in+Standard archive names contain the render-enabled rustls binary. Archives ending in`-stealth.tar.gz` or `-stealth.zip` additionally include the wreq/BoringSSLtransport used for TLS impersonation.@@ -189,17 +192,17 @@ usable on common LTS servers with glibc 2.35+.docker run -d --name obscura -p 127.0.0.1:9222:9222 h4ckf0r0day/obscura```-Image on [Docker Hub](https://hub.docker.com/r/h4ckf0r0day/obscura). Multi-stage build on `distroless/cc`, no shell, no package manager, ~57 MB compressed.+Image on [Docker Hub](https://hub.docker.com/r/h4ckf0r0day/obscura). Multi-stage build on `distroless/cc`, with no shell or package manager in the runtime image.### Build from source```bashgit clone https://github.com/h4ckf0r0day/obscura.gitcd obscura-cargo build --release+cargo build --release --features render-# With stealth mode (anti-detection + tracker blocking)-cargo build --release --features stealth+# Rendering plus the optional stealth transport+cargo build --release --features render,stealth```Requires Rust 1.75+ ([rustup.rs](https://rustup.rs)). First build takes ~5 min (V8 compiles from source, cached after).@@ -210,7 +213,7 @@ CMake, Clang, and the libclang/LLVM development libraries. On Ubuntu/Debian:sudo apt-get install build-essential cmake clang libclang-dev llvm-dev```-The default build does not require these additional stealth dependencies.+The render-only build does not require these additional stealth dependencies.## Quick Start@@ -244,8 +247,33 @@ obscura fetch https://example.com --wait-until networkidle0# Bound navigation time for slow or broken pagesobscura fetch https://example.com --timeout 10++# Capture the settled page as PNG+obscura fetch https://example.com --screenshot page.png+```++## Rendering and capture++Official release archives and the Docker image include the rendering engine.+It provides modern CSS layout and paint, viewport and full-page screenshots,+scroll-aware fixed and sticky geometry, activity-driven CDP screencasting, and+raster PDF export without starting Chromium.++```javascript+await page.setViewport({ width: 1440, height: 1000 });+await page.goto('https://example.com', { waitUntil: 'load' });+await page.screenshot({ path: 'page.png', fullPage: true });+await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });```+The engine covers the common block, inline, flex, grid, table, float,+positioning, overflow, transform, text, image, SVG, canvas, background, border,+and animation paths used by modern sites. It remains an evolving independent+engine: long-tail CSS, some Web APIs, media playback, compositor effects, and+platform font rasterization may differ from Chromium. See the+[rendering guide](docs/Rendering-screenshots-screencasting-and-PDF.md) for+scrolling, screencasting, raw CDP, MCP, PDF limits, and comparison methodology.+### Start the CDP server```bash@@ -331,7 +359,7 @@ await page.evaluate(() => {## Benchmarks-Page load:+Historical page-load samples from the benchmark repository:| Page | Obscura | Chrome ||------|---------|--------|@@ -339,11 +367,15 @@ Page load:| JS + XHR + fetch | **84 ms** | ~800 ms || Dynamic scripts | **78 ms** | ~700 ms |-The full benchmark suite (WPT conformance, obstacle course, real-world corpus, and vs-Chrome speed) lives in a separate repo: https://github.com/h4ckf0r0day/obscura-benchmark+These figures are not universal performance guarantees. The full benchmark+suite (WPT conformance, obstacle course, real-world corpus, and comparative+speed tests) lives in a separate repo:+https://github.com/h4ckf0r0day/obscura-benchmark## Stealth Mode-Enable with `--features stealth`.+Build with `--features render,stealth`, then enable the behavior at runtime with+the global `--stealth` flag.### Anti-fingerprinting- Per-session fingerprint randomization (GPU, screen, canvas, audio, battery)@@ -366,7 +398,7 @@ Obscura implements the Chrome DevTools Protocol for Puppeteer/Playwright compati| Domain | Methods ||--------|---------|| **Target** | createTarget, closeTarget, attachToTarget, createBrowserContext, disposeBrowserContext |-| **Page** | navigate, getFrameTree, addScriptToEvaluateOnNewDocument, lifecycleEvents |+| **Page** | navigate, getFrameTree, lifecycleEvents, captureScreenshot, start/stopScreencast, printToPDF || **Runtime** | evaluate, callFunctionOn, getProperties, addBinding || **DOM** | getDocument, querySelector, querySelectorAll, getOuterHTML, resolveNode || **Network** | enable, setCookies, getCookies, setExtraHTTPHeaders, setUserAgentOverride |@@ -417,7 +449,9 @@ Fetch and render a single page.| `--eval` | — | JavaScript expression to evaluate || `--wait-until` | `load` | Wait: `load`, `domcontentloaded`, `networkidle0` || `--timeout` | `30` | Maximum navigation time in seconds |+| `--wait` | adaptive, up to `5` | Post-load settling; an explicit value is a fixed delay in seconds || `--selector` | — | Wait for CSS selector |+| `--screenshot` | — | Write a PNG screenshot (single URL; render-enabled build) || `--stealth` | off | Anti-detection mode || `--output` | — | Write dump or eval output to a file || `--quiet` | off | Suppress banner |@@ -480,9 +514,11 @@ Optional flags (both transports):| Tool | Description ||------|-------------|| `browser_navigate` | Navigate to a URL (`url`, optional `waitUntil`: `load` / `domcontentloaded` / `networkidle0`) |-| `browser_snapshot` | Return the current page URL, title, and body text |-| `browser_click` | Click an element by CSS selector |-| `browser_fill` | Set an input value (triggers `input` + `change` events) |+| `browser_snapshot` | Return the current page URL, title, readable body text, and element references |+| `browser_screenshot` | Return the current page as an MCP PNG image (render-enabled build) |+| `browser_pdf` | Return the current page as an embedded PDF resource (render-enabled build) |+| `browser_click` | Click by current snapshot reference or CSS selector |+| `browser_fill` | Set an input value by reference or selector (triggers `input` + `change`) || `browser_type` | Append text to an input || `browser_press_key` | Dispatch a keyboard event (`key`, optional `selector`) || `browser_select_option` | Select an `<option>` by value or text |@@ -492,6 +528,9 @@ Optional flags (both transports):| `browser_console_messages` | Return console messages logged by the page || `browser_close` | Close the page and reset browser state |+The MCP server exposes still-image and PDF output. Use CDP when you need the+streaming `Page.startScreencast` protocol.+## Integrations- **[Hermes agent plugin](https://github.com/SGavrl/hermes-plugin-obscura)**: run [Hermes](https://github.com/NousResearch/hermes-agent) agent browser tasks on Obscura. The plugin spawns `obscura serve` per session (or connects to an already running server) and drives it over CDP, with optional `--stealth`.diff --git a/RENDER.md b/RENDER.mdindex 0a979f14..f48a64ca 100644--- a/RENDER.md+++ b/RENDER.md@@ -1,98 +1,69 @@-# obscura-render+# Obscura rendering engine-An optional, scoped render layer for Obscura. It adds real CSS box geometry to-the JS surface and rasterizes PNG screenshots, pure Rust, behind an opt-in-feature. The default scraping build is unchanged.+Obscura has an optional pure-Rust layout and paint pipeline for browser+automation. The `render` feature powers live DOM geometry, viewport and+full-page screenshots, CDP screencasting, and raster PDF export without+launching Chromium.-## Why--Obscura's speed and low memory come from not carrying a full browser rendering-pipeline. This layer adds only what scraping and automation need, real box-geometry (so `getBoundingClientRect`, `elementFromPoint`, and-`IntersectionObserver` return true values) and screenshots, without the weight-of a Chromium-class engine.--## Enable+Official release archives and the Docker image are built with rendering. When+building from source, enable it explicitly:```bashcargo build --release --features render-```--The feature propagates from `obscura-cli` through `obscura-browser`,-`obscura-cdp`, and `obscura-js` to `obscura-render`. The default build compiles-it out entirely.--## Use--CLI screenshot of the settled page:--```bash-obscura fetch --screenshot out.png https://example.com/-```-CDP (Puppeteer / Playwright `page.screenshot()`), driving `obscura serve`:--```js-await page.goto('https://example.com/');-await page.screenshot({ path: 'out.png' }); // Page.captureScreenshot+# Rendering plus the optional stealth transport+cargo build --release --features render,stealth```-Real geometry in JS (no screenshot needed):--```js-const r = await page.evaluate(() => document.querySelector('div').getBoundingClientRect());-// r.x, r.y, r.width, r.height are laid-out values, not synthetic-```--## What it renders--- Block, flexbox, and CSS grid box layout via [taffy](https://github.com/dioxusLabs/taffy).-- Inline styles plus a small built-in UA default sheet, parsed for the- layout-relevant properties (display, width/height, margin, padding, border)- and background-color.-- Background colors painted to the pixmap (backgrounds, borders, and text are- staged below).+## Capture surfaces-## Benchmark+- CLI PNG: `obscura fetch https://example.com --screenshot page.png`+- Puppeteer/Playwright: `page.screenshot()` and `page.pdf()` over CDP+- Raw CDP: `Page.captureScreenshot`, `Page.startScreencast`, and+ `Page.printToPDF`+- MCP: `browser_screenshot` and `browser_pdf` in render-enabled builds-Same page, same 1280x720 viewport, warmed, on the same host. Headless Chrome is-`google-chrome --headless=new --screenshot`.+Screencasting is an activity-driven CDP stream. Consumers must acknowledge+each `Page.screencastFrame` with `Page.screencastFrameAck`; it is not a desktop+video-recorder API.-| page | engine | wall | peak RSS | PNG |-| ------------- | -------- | -------- | -------- | ------ |-| local fixture | obscura | ~0.06s | ~33 MB | 5.3 KB |-| local fixture | chrome | ~0.90s | ~195 MB | 4.4 KB |-| example.com | obscura | ~0.10s | ~34 MB | 5.2 KB |-| example.com | chrome | ~0.98s | ~199 MB | 17 KB |+## Implemented rendering coverage-Obscura is roughly 10-15x faster and uses about 6x less memory than headless-Chrome for a screenshot. Chrome's larger PNG on example.com is because it-renders text, which obscura does not yet paint.+The engine includes selector matching and cascade, media queries, inherited+and relative values, block and inline formatting, flexbox, grid, tables,+floats, positioned and sticky elements, overflow and scrolling, transforms,+clipping, backgrounds, borders, shadows, shaped text and web fonts, images,+SVG, canvas, generated content, and animation sampling. Layout is retained and+invalidated by relevant DOM/style/resource mutations so geometry and capture+observe the same page state.-## Limitations and next steps--These are tracked enhancements, not bugs:--- **Text** is not rendered yet (the biggest fidelity gap).-- **Borders and images** are not painted; only background colors.-- **CSS coverage** is the layout-relevant subset. Full cascade (selector- matching, media queries, inheritance of all properties, relative units) is- not implemented.-- The layout cache is computed lazily and cleared on navigation. It is not- invalidated on every DOM mutation, so geometry read mid-script may lag a- frame; reading after settle is reliable.+This is broad browser-rendering support, not a claim that every long-tail CSS,+DOM, compositor, font, or graphics behavior is already identical to Chromium.+Test the sites and workflows that matter to you and report reduced fixtures+for reproducible differences.## Architecture-`obscura-render` is its own workspace crate with two optional capabilities:--- **Layout (default):** `layout_dom(dom, viewport)` walks a `DomTree`, computes- each element's style, builds a taffy tree, and returns border-box geometry- keyed by `NodeId`. Exposed to JS by `op_layout_geometry` (feature-gated).-- **Paint (`paint` feature):** `paint_dom` / `screenshot_png` rasterize the- laid-out tree with [tiny-skia](https://crates.io/crates/tiny-skia) (CPU, pure- Rust, deterministic) to a pixmap or PNG bytes.--The JS surface stays synthetic when the feature is off: `bootstrap.js` probes-`op_layout_geometry` with `typeof` and falls through to the existing synthetic-rect, so the default build is byte-for-byte equivalent.+`obscura-render` consumes the shared DOM and computed style state. Taffy+provides the flex/grid foundation; Obscura layers browser formatting behavior,+text shaping, intrinsic replaced-element sizing, retained layout, and a+CPU-backed paint pipeline on top. `obscura-js` exposes renderer-owned geometry+to browser APIs, `obscura-browser` owns resource preparation and capture, and+`obscura-cdp` maps the result to Chrome DevTools Protocol methods.++PDF output is intentionally raster-backed. It honors print media, backgrounds,+paper size, margins, landscape, scale, and page ranges, but does not yet provide+selectable PDF text, tagged structure, headers/footers, outlines, or complete+CSS paged-media support.++## Verification++Rendering changes are checked with deterministic fixtures first, then a broad+real-site suite against Chromium. Captures must use the same viewport, identity,+settle policy, animation time, scroll position, and output boundary. Pixel+error is a regression tripwire, not a standalone correctness verdict; geometry,+structural edges, missing resources, nonblank output, and reduced repros decide+whether a difference is real.++See [Rendering, screenshots, screencasting, and PDF](docs/Rendering-screenshots-screencasting-and-PDF.md)+for user-facing examples and current limits.diff --git a/docs/Adding-a-CDP-method-or-Web-API.md b/docs/Adding-a-CDP-method-or-Web-API.mdindex 0eed3929..a805c448 100644--- a/docs/Adding-a-CDP-method-or-Web-API.md+++ b/docs/Adding-a-CDP-method-or-Web-API.md@@ -63,7 +63,7 @@ async fn my_domain_do_thing_returns_ok() {Run:```bash-cargo test -p obscura-cdp my_domain+cargo nextest run --release --features render -p obscura-cdp my_domain```## Adding a Web API@@ -131,7 +131,7 @@ sha2 = "0.10"### 5. Smoke test```bash-cargo build --release+cargo build --release --features render./target/release/obscura fetch https://example.com --eval "crypto.subtle.digest('SHA-256', new TextEncoder().encode('hi')).then(buf => Array.from(new Uint8Array(buf)).map(b => b.toString(16).padStart(2, '0')).join(''))diff --git a/docs/Architecture-overview.md b/docs/Architecture-overview.mdindex f0e835c5..29dbdef9 100644--- a/docs/Architecture-overview.md+++ b/docs/Architecture-overview.md@@ -1,4 +1,4 @@-Obscura is a workspace of eight crates.+Obscura is a workspace of nine crates.```obscura-cli CLI entry point. fetch, serve, scrape, mcp.@@ -8,6 +8,7 @@ obscura-js V8 runtime via deno_core. bootstrap.js + Rust ops.obscura-dom DOM tree implementation.obscura-net HTTP client, stealth client, cookie jar, robots cache, tracker blocklist.obscura-mcp Model Context Protocol server.+obscura-render CSS cascade, retained layout, text shaping, and CPU paint.obscura Embeddable Rust library API (Browser, Page, Element, CookieStore).```@@ -41,6 +42,20 @@ obscura-browser/page.rs navigate_with_waitThe dispatcher emits CDP events (`Network.requestWillBeSent`, `Page.frameNavigated`, `Page.lifecycleEvent`) back to the client through the same WebSocket.+## Rendering flow++`obscura-render` consumes the shared DOM and computed style state. Taffy+provides the flex/grid foundation; Obscura adds browser formatting behavior,+text shaping, intrinsic replaced-element sizing, retained geometry, scrolling,+and CPU-backed paint. `obscura-js` exposes renderer-owned geometry to DOM APIs,+`obscura-browser` prepares resources and owns capture, and `obscura-cdp` maps+screenshots, screencast frames, and raster PDF output onto CDP.++Layout is retained between captures and invalidated by relevant DOM, style,+viewport, scroll, animation, font, and resource changes. The same geometry+therefore drives browser APIs and paint instead of maintaining separate+measurement and screenshot models.+## Single V8 isolateAll pages in a process share one V8 isolate. The isolate is single-threaded by design.diff --git a/docs/Build-from-source.md b/docs/Build-from-source.mdindex 10940cb8..40ff9729 100644--- a/docs/Build-from-source.md+++ b/docs/Build-from-source.md@@ -11,15 +11,19 @@ First build takes about 5 minutes. Incremental builds are seconds.```bashgit clone https://github.com/h4ckf0r0day/obscura.gitcd obscura-cargo build --release+cargo build --release --features render```Binary is at `./target/release/obscura`.-## With stealth+This produces the release-capable binary, including geometry, screenshots,+screencasting, and PDF export. A build without `render` remains available for+text/DOM-only deployments.++## With rendering and stealth```bash-cargo build --release --features stealth+cargo build --release --features render,stealth```Adds TLS fingerprint randomization and the tracker blocklist. See [Configure stealth and proxies](Configure-stealth-and-proxies.md).@@ -43,7 +47,7 @@ libc++ while compiling BoringSSL. Use the active SDK for that build:```bashSDK_PATH="$(xcrun --show-sdk-path)"SDKROOT="$SDK_PATH" CXXFLAGS="-isystem $SDK_PATH/usr/include/c++/v1" \- cargo build --release --features stealth+ cargo build --release --features render,stealth```## OpenSSL on older systems@@ -51,7 +55,7 @@ SDKROOT="$SDK_PATH" CXXFLAGS="-isystem $SDK_PATH/usr/include/c++/v1" \If the build fails on the vendored OpenSSL with an AVX-512 assembler error (common on older VPS hosts):```bash-OPENSSL_NO_VENDOR=1 cargo build --release+OPENSSL_NO_VENDOR=1 cargo build --release --features render```Uses the system OpenSSL instead.@@ -66,13 +70,13 @@ Uses the system OpenSSL instead.Install system-wide:```bash-cargo install --path crates/obscura-cli+cargo install --path crates/obscura-cli --features render```## Tests```bash-cargo test --release+cargo nextest run --release --features render --no-fail-fast```Integration suite:@@ -80,3 +84,6 @@ Integration suite:```bashpython3 tests/test_all.py```++Use `cargo nextest`, not `cargo test`: runtime tests require process isolation+because the engine owns a single V8 isolate per process.diff --git a/docs/CLI-reference.md b/docs/CLI-reference.mdindex c7c45413..3e59d2e4 100644--- a/docs/CLI-reference.md+++ b/docs/CLI-reference.md@@ -24,7 +24,7 @@ Load a URL and print its content or an evaluated expression.--dump <FORMAT> html | text | links | markdown | original | assets | cookies(default html)--selector <CSS> Narrow output to a CSS selector- --wait <SECONDS> Extra wait after settle (default 5)+ --wait <SECONDS> Fixed post-load delay; omitted uses adaptive settle (5s cap)--timeout <SECONDS> Navigation timeout (default 30)--wait-until <LEVEL> domcontentloaded | load | networkidle2 | networkidle0(default load)@@ -33,10 +33,20 @@ Load a URL and print its content or an evaluated expression.--stealth Consistent browser fingerprint + tracker blocking (global)-e, --eval <JS> Evaluate JS, print the result as JSON-o, --output <FILE> Write to a file instead of stdout+ --screenshot <FILE> Render the settled page to PNG (single URL)-q, --quiet Suppress info logging-v, --verbose Enable verbose logging```+`--screenshot` requires a render-enabled build. It uses a 1280×720 viewport by+default and may be combined with `--eval`; the expression runs before capture,+which is useful for scrolling or preparing page state. It is not available in+`--file` batch mode.++When `--wait` is omitted, Obscura drives timers and async work until the page+becomes quiescent, with a five-second ceiling. Supplying `--wait N` instead+requests a fixed `N`-second delay. `--timeout` separately bounds navigation.+`--dump` values:| Value | Output |@@ -113,3 +123,6 @@ Run obscura as an MCP server.`--host` only applies with `--http`. The default `127.0.0.1` keeps the server loopback-only; set `0.0.0.0` to bind all interfaces (for example a Docker Compose sidecar) and pair it with `OBSCURA_MCP_ALLOWED_ORIGINS`.Default transport is stdio. See [Use the MCP server](Use-the-MCP-server.md).++Render-enabled builds add `browser_screenshot` and `browser_pdf` to the MCP+tool list. Streaming screencasts are available through CDP rather than MCP.diff --git a/docs/Configure-stealth-and-proxies.md b/docs/Configure-stealth-and-proxies.mdindex 1bc222af..6fa2bee4 100644--- a/docs/Configure-stealth-and-proxies.md+++ b/docs/Configure-stealth-and-proxies.md@@ -16,12 +16,12 @@ What `--stealth` changes:- Bundles webpki roots instead of relying on the system store.Requires a build that includes the stealth feature. The Releases page provides-explicitly named `-stealth` archives alongside the lean default archives, so+explicitly named `-stealth` archives alongside the standard render-enabled archives, sousers who do not need wreq/BoringSSL do not pay its binary-size or RSS cost. Tobuild the stealth variant yourself:```bash-cargo build --release --features stealth+cargo build --release --features render,stealth```## What stealth handlesdiff --git a/docs/Connect-Puppeteer-or-Playwright.md b/docs/Connect-Puppeteer-or-Playwright.mdindex 8d347714..9de78db7 100644--- a/docs/Connect-Puppeteer-or-Playwright.md+++ b/docs/Connect-Puppeteer-or-Playwright.md@@ -78,11 +78,29 @@ await page.goto('https://example.com', { waitUntil: 'load' });- `page.setRequestInterception`, block / modify- `page.exposeFunction`- `page.content`, `page.title`, `page.url`+- `page.screenshot` for viewport, clipped, and full-page capture+- `page.pdf` for raster-backed print output+- raw CDP `Page.startScreencast` with frame acknowledgementsDOM-agent frameworks such as browser-use also connect: obscura implements `DOMSnapshot.captureSnapshot` and `Target.targetInfoChanged` for perception, and `DOM.focus` so a focused field receives `Input.dispatchKeyEvent` keystrokes.-## Not supported+## Capture example-- `page.screenshot`: obscura doesn't render pixels.-- Per-page V8 isolation: pages share one V8 isolate. A heavy script on one page can stall others.-- Cloudflare / Datadome / Akamai bypass: see [Configure stealth and proxies](Configure-stealth-and-proxies.md).+```js+await page.setViewport({ width: 1440, height: 1000 });+await page.screenshot({ path: 'viewport.png' });+await page.screenshot({ path: 'full-page.png', fullPage: true });+await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });+```++Rendering is included in official binaries and requires `--features render`+for source builds. See [Rendering, screenshots, screencasting, and PDF](Rendering-screenshots-screencasting-and-PDF.md)+for scrolling, raw CDP examples, and current output limits.++## Current limits++- Pages share one V8 isolate. CPU-bound JavaScript on one page can delay others.+- PDF output is raster-backed; text is not selectable and tagged PDF,+ headers/footers, outlines, and full CSS paged media are not implemented.+- Service workers, native media playback, some Web APIs, and long-tail CSS or+ compositor effects are still incomplete relative to Chromium.diff --git a/docs/Environment-variables.md b/docs/Environment-variables.mdindex af50c5e9..f42ccf90 100644--- a/docs/Environment-variables.md+++ b/docs/Environment-variables.md@@ -113,7 +113,7 @@ RUST_LOG=obscura_cdp=trace,obscura_browser=debug obscura serveForces `cargo build` to use the system OpenSSL instead of compiling the vendored copy. Set to `1` on hosts where the vendored OpenSSL fails (older VPS with AVX-512 issues).```bash-OPENSSL_NO_VENDOR=1 cargo build --release+OPENSSL_NO_VENDOR=1 cargo build --release --features render```## V8diff --git a/docs/Installation.md b/docs/Installation.mdindex 54624a65..dcb657c5 100644--- a/docs/Installation.md+++ b/docs/Installation.md@@ -48,7 +48,10 @@ yay -S obscura-browserdocker run -d --name obscura -p 127.0.0.1:9222:9222 h4ckf0r0day/obscura```-Image: [h4ckf0r0day/obscura](https://hub.docker.com/r/h4ckf0r0day/obscura). Built on `distroless/cc`, ~57 MB compressed.+Image: [h4ckf0r0day/obscura](https://hub.docker.com/r/h4ckf0r0day/obscura). Built on `distroless/cc`, with no shell or package manager in the runtime image.++Official archives and the Docker image include the rendering engine. Source+builders must pass `--features render`; see [Build from source](Build-from-source.md).## From source@@ -59,17 +62,17 @@ See [Build from source](Build-from-source.md).- `obscura`: CLI and CDP server.- `obscura-worker`: helper for the parallel `scrape` command. Keep both in the same directory.-The standard archive names contain the lean default build. Choose the matching-archive with a `-stealth` suffix when you need the wreq/BoringSSL transport for-TLS impersonation.+Standard archives include rendering. Choose the matching archive with a+`-stealth` suffix when you also need the optional wreq/BoringSSL transport.## Smoke test```bash./obscura fetch https://example.com --eval "document.title"+./obscura fetch https://example.com --screenshot smoke.png```-Expected output: `"Example Domain"`.+Expected output: `"Example Domain"`, followed by a nonempty PNG at `smoke.png`.## Troubleshootingdiff --git a/docs/README.md b/docs/README.mdindex 574e198d..7b634cab 100644--- a/docs/README.md+++ b/docs/README.md@@ -1,16 +1,10 @@-Obscura is an open-source headless browser engine written in Rust. It runs JavaScript via V8, speaks the Chrome DevTools Protocol, and works as a drop-in replacement for headless Chrome with Puppeteer and Playwright.+Obscura is an open-source headless browser engine written in Rust. It runs JavaScript through V8, owns its DOM, layout, and paint pipeline, and speaks the Chrome DevTools Protocol for common Puppeteer and Playwright workflows.-## Versus headless Chrome--| Metric | Obscura | Headless Chrome |-| ----------- | -------- | --------------- |-| Memory | 30 MB | 200+ MB |-| Binary size | 70 MB | 300+ MB |-| Startup | Instant | ~2s |-| Page load | 85 ms | ~500 ms |-| Anti-detect | Built-in | None |-| Puppeteer | Yes | Yes |-| Playwright | Yes | Yes |+The render-enabled release supports screenshots, scroll-aware layout,+activity-driven CDP screencasting, and raster PDF export. Obscura is an+independent engine rather than a bundled Chromium build, so compatibility and+performance should be measured against the pages and automation flows that+matter to you.## Quickstart@@ -22,6 +16,7 @@ Obscura is an open-source headless browser engine written in Rust. It runs JavaS## Guides- [Build from source](Build-from-source.md)+- [Rendering, screenshots, screencasting, and PDF](Rendering-screenshots-screencasting-and-PDF.md)- [Configure stealth and proxies](Configure-stealth-and-proxies.md)- [Markdown extraction](Markdown-extraction.md)- [Use with Puppeteer](Use-with-Puppeteer.md)diff --git a/docs/Rendering-screenshots-screencasting-and-PDF.md b/docs/Rendering-screenshots-screencasting-and-PDF.mdnew file mode 100644index 00000000..8b7fce10--- /dev/null+++ b/docs/Rendering-screenshots-screencasting-and-PDF.md@@ -0,0 +1,199 @@+Rendering is available in official release archives and Docker images. Source+builds must enable the `render` feature:++```bash+cargo build --release --features render+```++Use `--features render,stealth` when the same binary also needs the optional+stealth transport.++## CLI screenshots++Capture the settled page as a PNG:++```bash+obscura fetch https://example.com --screenshot page.png --timeout 30+```++JavaScript supplied with `--eval` runs before capture, so it can prepare or+scroll the page:++```bash+obscura fetch https://example.com \+ --eval "window.scrollTo(0, document.documentElement.scrollHeight)" \+ --screenshot bottom.png+```++The CLI captures one URL and writes PNG. An omitted `--wait` uses adaptive+settling with a five-second cap; an explicit `--wait N` requests a fixed delay+of `N` seconds. Navigation and the capture path prepare discovered images and+fonts within bounded deadlines rather than waiting indefinitely for a broken+resource.++## Puppeteer++Start the render-enabled CDP server:++```bash+obscura serve --port 9222+```++Then use the standard Puppeteer APIs:++```js+import puppeteer from 'puppeteer-core';++const browser = await puppeteer.connect({+ browserWSEndpoint: 'ws://127.0.0.1:9222/devtools/browser',+});+const page = await browser.newPage();+await page.setViewport({ width: 1440, height: 1000, deviceScaleFactor: 1 });+await page.goto('https://example.com', { waitUntil: 'load' });++await page.screenshot({ path: 'viewport.png' });+await page.screenshot({ path: 'full-page.png', fullPage: true });+await page.pdf({+ path: 'page.pdf',+ format: 'A4',+ printBackground: true,+});++await browser.disconnect();+```++## Playwright++Use `connectOverCDP`, not Playwright's native `connect` protocol:++```js+import { chromium } from 'playwright-core';++const browser = await chromium.connectOverCDP('ws://127.0.0.1:9222');+const context = browser.contexts()[0] || await browser.newContext();+const page = await context.newPage();+await page.setViewportSize({ width: 1440, height: 1000 });+await page.goto('https://example.com', { waitUntil: 'load' });++await page.screenshot({ path: 'viewport.png' });+await page.screenshot({ path: 'full-page.png', fullPage: true });+await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });++await browser.close();+```++## Scrolling and capture++Window and nested-element scrolling update renderer-owned geometry and paint.+Fixed and sticky elements are sampled at the live scroll position.++```js+await page.evaluate(() => window.scrollTo(0, 1200));+await page.screenshot({ path: 'scrolled.png' });++await page.evaluate(() => {+ document.querySelector('.overflow-panel')?.scrollTo(0, 600);+});+await page.screenshot({ path: 'nested-scroll.png' });+```++`fullPage: true` captures document space independently of the current viewport+scroll. A normal screenshot captures the currently visible viewport.++## Raw CDP screenshot++`Page.captureScreenshot` supports PNG, JPEG, and lossless WebP, viewport clips,+scaling, full-page capture through `captureBeyondViewport`, device metrics, and+transparent background overrides. `fromSurface: false` is not supported, and+the WebP encoder does not currently accept a quality setting.++```js+import fs from 'node:fs';++const client = await page.createCDPSession();+const { data } = await client.send('Page.captureScreenshot', {+ format: 'png',+ captureBeyondViewport: true,+});+await fs.promises.writeFile('capture.png', Buffer.from(data, 'base64'));+```++## Screencasting++Screencasting is exposed through CDP. Frames are emitted when navigation,+input, timers, animation frames, or visual mutations produce new content.+Clients must acknowledge frames; Obscura bounds unacknowledged work instead of+letting a slow consumer grow memory without limit.++```js+const client = await page.createCDPSession();++client.on('Page.screencastFrame', async ({ data, metadata, sessionId }) => {+ // Consume or forward Buffer.from(data, 'base64') here.+ console.log(metadata.timestamp, metadata.scrollOffsetY);+ await client.send('Page.screencastFrameAck', { sessionId });+});++await client.send('Page.startScreencast', {+ format: 'jpeg',+ quality: 80,+ maxWidth: 1280,+ maxHeight: 720,+ everyNthFrame: 1,+});++// ...navigate and interact...++await client.send('Page.stopScreencast');+```++This is an activity-driven page stream, not desktop/window capture or a+guarantee of a fixed frame rate.++## PDF export++Puppeteer and Playwright `page.pdf()` route to `Page.printToPDF`. Raw CDP can+return Base64 directly or a stream read with `IO.read` and closed with+`IO.close`.++The exporter uses print-media style and supports paper dimensions, margins,+landscape, scale, backgrounds, and page ranges. Output is raster-backed, so+text is not selectable/searchable and tagged PDFs, outlines, headers/footers,+`preferCSSPageSize`, and complete CSS `@page` sizing are not yet available.++## MCP visual output++Render-enabled MCP servers expose:++- `browser_screenshot`: returns the current page as an MCP PNG image content+ block.+- `browser_pdf`: returns the current page as an embedded `application/pdf`+ resource.++The screenshot tool accepts optional CSS-pixel `width` and `height`. The PDF+tool accepts `landscape`, `print_background`, `scale`, `paper_width`,+`paper_height`, and `margin_top` / `margin_bottom` / `margin_left` /+`margin_right`; paper and margin values are inches.++```bash+obscura mcp+# or+obscura mcp --http --host 127.0.0.1 --port 3000+```++Navigate first, then call the visual tool. MCP does not expose streaming+screencast frames; use the CDP API for that workflow.++## Current boundaries++Obscura implements broad modern layout and paint support, including block and+inline formatting, flexbox, grid, tables, floats, positioned/fixed/sticky+boxes, transforms, overflow, text and web fonts, images, SVG, canvas,+backgrounds, borders, clipping, generated content, and animation sampling.++It is still an evolving browser engine. Long-tail CSS, service workers, some+Web APIs, native media playback, GPU/compositor effects, and exact platform+font rasterization can differ from Chromium. Treat visual comparisons as+evidence: confirm both captures succeeded and are nonblank, compare the same+viewport/wait/identity/scroll/animation state, and inspect geometry and missing+resources in addition to pixel error.diff --git a/docs/SUMMARY.md b/docs/SUMMARY.mdindex 4e3bc901..766c563e 100644--- a/docs/SUMMARY.md+++ b/docs/SUMMARY.md@@ -12,6 +12,7 @@## Guides* [Build from source](Build-from-source.md)+* [Rendering, screenshots, screencasting, and PDF](Rendering-screenshots-screencasting-and-PDF.md)* [Configure stealth and proxies](Configure-stealth-and-proxies.md)* [Markdown extraction](Markdown-extraction.md)* [Use with Puppeteer](Use-with-Puppeteer.md)diff --git a/docs/Testing-and-debugging.md b/docs/Testing-and-debugging.mdindex 6b4f3fec..a9a3d46f 100644--- a/docs/Testing-and-debugging.md+++ b/docs/Testing-and-debugging.md@@ -3,22 +3,26 @@### Rust unit and integration```bash-cargo test --release+cargo nextest run --release --features render --no-fail-fast```Crate-scoped:```bash-cargo test -p obscura-cdp-cargo test -p obscura-browser+cargo nextest run --release --features render -p obscura-cdp+cargo nextest run --release --features render -p obscura-browser```By name:```bash-cargo test runtime_click_submit_prevent_default+cargo nextest run --release --features render runtime_click_submit_prevent_default```+Use `cargo nextest`, not `cargo test`. Runtime tests require process isolation+because the engine owns one V8 isolate per process. Render tests must run in+release mode; debug builds are not a fidelity or performance gate.+### CDP parity tests`crates/obscura-cdp/tests/cdp_*.rs` exercise CDP methods end-to-end with a real `dispatch` call and an in-process HTTP server.@@ -100,12 +104,31 @@ The integration suite in `tests/test_all.py` is the fastest path from a one-lineFor Puppeteer / Playwright bug reports, the user's repro script usually drops straight in. Save it as `tests/repro_<issue>.js`, run with `node`, fix until it passes.+### Rendering regressions++Start with the committed deterministic fixtures, then use the representative+real-site suite at both the top and bottom of pages:++```bash+RUN_ROOT="$(mktemp -d)"+OBSCURA_BIN=./target/release/obscura render-repros/run.sh "$RUN_ROOT/fixtures"+OBSCURA_BIN=./target/release/obscura render-repros/representative-suite/run.sh "$RUN_ROOT/top"+OBSCURA_BIN=./target/release/obscura render-repros/representative-suite/run.sh "$RUN_ROOT/bottom" bottom+```++Set `BASELINE_BIN` or `CHROMIUM_BIN` when producing paired captures. Keep the+viewport, user agent, settle policy, scroll position, animation sample, and+capture boundary identical. A pixel-distance score is a regression tripwire,+not a verdict: verify both engines succeeded and produced nonblank output,+then inspect missing resources, geometry, structural edges, and a reduced+fixture. Do not add hostname-specific render branches.+## ProfilingCPU with `perf` and a flamegraph:```bash-cargo build --release+cargo build --release --features renderperf record -F 99 -g -- ./target/release/obscura fetch https://heavy-spa.exampleperf script | flamegraph.pl > flame.svg```@@ -119,7 +142,7 @@ heaptrack ./target/release/obscura serveTokio task inspection:```bash-RUSTFLAGS="--cfg tokio_unstable" cargo build --release+RUSTFLAGS="--cfg tokio_unstable" cargo build --release --features render./target/release/obscura serve# in another shelltokio-consolediff --git a/docs/Use-the-MCP-server.md b/docs/Use-the-MCP-server.mdindex b6af3d09..ce6fb4d7 100644--- a/docs/Use-the-MCP-server.md+++ b/docs/Use-the-MCP-server.md@@ -49,7 +49,8 @@ Navigation and lifecycle:Read the page:-- `browser_snapshot`: accessibility/DOM snapshot of the current page.+- `browser_snapshot`: current URL, title, readable body text, and interactive+ element references. Optional `max_chars` limits the returned text.- `browser_markdown`, `browser_links`, `browser_extract`: page as markdown, link list, or structured content.- `browser_interactive_elements`, `browser_detect_forms`: actionable elements and form fields.- `browser_get_attribute`, `browser_count`, `browser_search`: read an attribute, count matches, find text.@@ -66,6 +67,16 @@ Diagnostics:- `browser_network_requests`, `browser_console_messages`+Visual output (render-enabled builds):++- `browser_screenshot`: current viewport as an MCP `image/png` content block.+- `browser_pdf`: current page as an embedded `application/pdf` resource.++`browser_screenshot` accepts optional positive `width` and `height` values in+CSS pixels and enforces a bounded capture size. `browser_pdf` accepts+`landscape`, `print_background`, `scale`, paper width/height, and top, bottom,+left, and right margins. Paper dimensions and margins are measured in inches.+Cookies and storage:- `browser_get_cookies`, `browser_set_cookie`, `browser_clear_cookies`, `browser_storage_state`, `browser_set_storage_state`@@ -74,6 +85,14 @@ Tabs:- `browser_tab_new`, `browser_tab_list`, `browser_tab_switch`, `browser_tab_close`+Element references describe the current rendered page state and can become+stale after navigation, interaction, scrolling, or a framework rerender. Take+a fresh snapshot or interactive-element listing before acting again.++MCP exposes still-image and PDF output. It does not stream video frames; use+CDP `Page.startScreencast` for activity-driven screencasting. See+[Rendering, screenshots, screencasting, and PDF](Rendering-screenshots-screencasting-and-PDF.md).+## Claude DesktopEdit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):diff --git a/docs/Use-with-Playwright.md b/docs/Use-with-Playwright.mdindex 58f20d2b..f30cbc6c 100644--- a/docs/Use-with-Playwright.md+++ b/docs/Use-with-Playwright.md@@ -96,15 +96,37 @@ await Promise.all([Pages share one V8 isolate. CPU-bound JS on one page blocks the others.+## Screenshots, scrolling, and PDF++```js+await page.setViewportSize({ width: 1440, height: 1000 });+await page.screenshot({ path: 'viewport.png' });++await page.evaluate(() => window.scrollTo(0, 1200));+await page.screenshot({ path: 'scrolled.png' });++await page.screenshot({ path: 'full-page.png', fullPage: true });+await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });+```++A normal screenshot captures the live viewport and scroll position;+`fullPage: true` captures document space. PDF output is raster-backed. For raw+CDP screencasting and detailed limits, see+[Rendering, screenshots, screencasting, and PDF](Rendering-screenshots-screencasting-and-PDF.md).+## Disconnect```jsawait browser.close(); // closes the CDP connection, leaves obscura serve running```-## Not supported+## Current limits-- `page.screenshot()`, `page.pdf()`: no pixel rendering.-- `page.video()`, tracing artifacts that need a real browser.-- `BrowserContext` storage state save/restore: use `--storage-dir` on `obscura serve` instead, see [Persist cookies and storage](Persist-cookies-and-storage.md).-- Service workers.+- Playwright `page.video()` and tracing artifacts that require desktop capture+ are not implemented. Use CDP `Page.startScreencast` for page frames.+- `BrowserContext` storage-state save/restore remains limited; use+ `--storage-dir` on `obscura serve`, as described in+ [Persist cookies and storage](Persist-cookies-and-storage.md).+- Service workers, native media, some Web APIs, long-tail CSS, and compositor+ behavior remain incomplete relative to Chromium.+- PDF text is not selectable/searchable and tagged PDF is not yet available.diff --git a/docs/Use-with-Puppeteer.md b/docs/Use-with-Puppeteer.mdindex 1c686b92..292d8d3c 100644--- a/docs/Use-with-Puppeteer.md+++ b/docs/Use-with-Puppeteer.md@@ -111,14 +111,33 @@ await Promise.all([Pages share one V8 isolate. Concurrent JS execution serializes through a lock. CPU-bound JS on one page blocks the others.+## Screenshots, scrolling, and PDF++```js+await page.setViewport({ width: 1440, height: 1000, deviceScaleFactor: 1 });+await page.screenshot({ path: 'viewport.png' });++await page.evaluate(() => window.scrollTo(0, 1200));+await page.screenshot({ path: 'scrolled.png' });++await page.screenshot({ path: 'full-page.png', fullPage: true });+await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });+```++A normal screenshot captures the live viewport and scroll position;+`fullPage: true` captures document space. PDF output is raster-backed. For raw+CDP screencasting and detailed limits, see+[Rendering, screenshots, screencasting, and PDF](Rendering-screenshots-screencasting-and-PDF.md).+## Disconnect```jsawait browser.disconnect(); // leaves obscura serve running```-## Not supported+## Current limits-- `page.screenshot()` and `page.pdf()`: no pixel rendering.-- `page.emulate()` device emulation: viewport metadata only, no real layout.-- Service workers: not implemented.+- Some device emulation, service-worker, native media, long-tail CSS, and+ compositor behavior remains incomplete relative to Chromium.+- Pages share one V8 isolate; CPU-bound JavaScript serializes across pages.+- PDF text is not selectable/searchable and tagged PDF is not yet available.diff --git a/skills/obscura/SKILL.md b/skills/obscura/SKILL.mdindex fd752821..af651d43 100644--- a/skills/obscura/SKILL.md+++ b/skills/obscura/SKILL.md@@ -1,125 +1,103 @@---name: obscura-description: Use Obscura — a Rust headless browser with a Chrome DevTools Protocol server — for fast page fetches, JS execution, scraping, and CDP automation. Drop-in CDP replacement for Chrome with Puppeteer or Playwright. Trigger on requests to "open a page", "fetch a URL with JS", "scrape a site", "render this page", "automate browser via CDP", or any task where Chrome would be too heavy. Also use when the user mentions stealth fingerprinting, tracker blocking, `navigator.webdriver` masking, or evading basic bot detection.+description: Operate and validate Obscura for JavaScript page loading, screenshots and visual comparison, CDP automation with Puppeteer or Playwright, screencasting, PDF export, MCP browser interaction, and web extraction. Use when running Obscura against deterministic fixtures or real sites, diagnosing render, geometry, or resource failures, or choosing the correct CLI, CDP, or MCP workflow.---# Obscura-Single-developer, open-source Rust headless browser. Boots instantly, ~70 MB binary, ~30 MB RAM at runtime, and serves a Chrome DevTools Protocol port that Puppeteer and Playwright connect to unchanged. **You swap the binary, not the code.**+Use Obscura as an independent Rust headless browser for automation. It embeds+V8, owns the DOM and rendering pipeline, and exposes common Chrome DevTools+Protocol workflows without launching Chromium.-Repo: https://github.com/h4ckf0r0day/obscura+## Build the right binary-## Why pick Obscura over Chrome--| | Obscura | Chrome |-|---|---|---|-| Binary | ~70 MB | ~300 MB |-| RAM | ~30 MB | ~200 MB |-| Cold start | instant | ~2 s |-| Page load (upstream claim) | ~85 ms | varies |--Field measurement on Cloudflare-protected `nairaland.com` (warm fetch): **Obscura ~4.1–4.9 s, returns real HTML body**. Real Chrome over CDP: ~5.1 s warm / 9.3 s cold. `curl`: 0.5–0.9 s but only the CF challenge interstitial.--Obscura is roughly as fast as warm Chrome, ~2× faster cold, parallelizes far better because it doesn't carry Chrome's per-process overhead, and clears Cloudflare's basic JS challenge **without** the stealth feature.--## Build+Official release archives and Docker images include rendering. For a source+checkout, build release mode with the render feature:```bash-git clone https://github.com/h4ckf0r0day/obscura.git-cd obscura-CARGO_TARGET_DIR=/tmp/obscura-target cargo build -p obscura-cli --bin obscura+CARGO_INCREMENTAL=0 CARGO_BUILD_JOBS=2 cargo build --release --features render```-Resulting binary: `/tmp/obscura-target/debug/obscura`--The default build has no stealth and needs no extra tools. Stealth is opt-in (see below) and pulls `wreq` / BoringSSL, so it needs `cmake` locally.--### Stealth build+Add the optional stealth transport only when the task requires it:```bash-CARGO_TARGET_DIR=/tmp/obscura-target cargo build -p obscura-cli --bin obscura --features stealth+CARGO_INCREMENTAL=0 CARGO_BUILD_JOBS=2 cargo build --release --features render,stealth```-What stealth gives you:--- **Consistent browser fingerprint** so cross-layer checks pass: the TLS ClientHello, User-Agent, `navigator` surfaces, and WebGL renderer all agree on one Chrome identity rather than contradicting each other-- **3,520 tracker domains blocked** (built-in blocklist)-- **`navigator.webdriver` masked**-- **Native functions patched** so common automation detectors can't unmask them via `Function.prototype.toString` inspection-- **TLS / HTTP-2 fingerprint** matching real Chromium (defeats most JA3/JA4 + ALPN-ordering bot management)+Use `./target/release/obscura` in the commands below when working from source.-Enable it at runtime with the global `--stealth` flag (works on `fetch`, `serve`, `scrape`, and `mcp`, before or after the subcommand). The flag needs a stealth-feature build for the TLS layer; without it `--stealth` still does tracker blocking.+## Fetch, evaluate, and capture```bash-/tmp/obscura-target/debug/obscura fetch https://example.com/ --stealth --dump text+obscura fetch https://example.com --dump text+obscura fetch https://example.com --eval "document.title"+obscura fetch https://example.com --screenshot page.png+obscura fetch https://example.com \+ --eval "window.scrollTo(0, document.documentElement.scrollHeight)" \+ --screenshot bottom.png```-Use stealth against: Cloudflare Turnstile non-interactive, Akamai BMP, PerimeterX, DataDome.-Stealth still won't clear: hard interactive CAPTCHAs (Turnstile interactive, hCaptcha challenge), and fingerprinters using WebGPU/WebAssembly quirks not yet patched.+The CLI screenshot path writes PNG and accepts one URL. An omitted `--wait`+uses adaptive settling with a five-second cap. An explicit `--wait N` is a+fixed delay of `N` seconds. `--timeout` is also measured in seconds and bounds+navigation separately.-## CLI fetch+Use `--dump original` for a binary or raw HTTP response that should bypass DOM+and JavaScript processing. Use `scrape` for many URLs when the requested output+does not require one screenshot per URL.-```bash-/tmp/obscura-target/debug/obscura fetch https://example.com/ --dump text --quiet-```--Useful flags:-- `--dump text`: visible text only-- `--dump html`: full rendered DOM-- `--dump assets`: every external resource plus `fetch()`/XHR URLs, one JSON object per line-- `--dump cookies`: all cookies as JSON, including HttpOnly-- `--quiet`: suppress progress logs-- `--timeout <ms>`: per-page timeout+## Drive CDP-## CDP server (Puppeteer / Playwright)+Start the server:```bash-/tmp/obscura-target/debug/obscura serve --port 9222+obscura serve --port 9222```-**Playwright:**--```ts-import { chromium } from "playwright-core";--const browser = await chromium.connectOverCDP("ws://127.0.0.1:9222");-const page = await browser.newContext().then((ctx) => ctx.newPage());-await page.goto("https://example.com/");-console.log(await page.title());-await browser.close();-```--**Puppeteer:**--```ts-import puppeteer from "puppeteer-core";--const browser = await puppeteer.connect({- browserWSEndpoint: "ws://127.0.0.1:9222/devtools/browser",-});-const page = await browser.newPage();-await page.goto("https://example.com/");-console.log(await page.title());-await browser.disconnect();-```--## Request interception--Over CDP, `page.setRequestInterception(true)` (Puppeteer) or `page.route` (Playwright) block, modify, or mock requests as usual. Embedding the engine with the `obscura` Rust crate gives the same thing as a native `Page` API: `on_request` / `on_response` callbacks (capture SPA API payloads without reverse-engineering the bundle), an `enable_interception()` channel to block, mock, or rewrite, and `add_preload_script` to run code before the page's own scripts.--## Scaling profile--- ✅ **High concurrency, low resource:** static + lightly-dynamic pages — hundreds of parallel fetches per box.-- ⚠️ **Medium:** JS-rendered SPAs, light bot protection — works but slower than raw HTTP, watch timeouts.-- ❌ **Low / unreliable:** aggressive bot defense (Turnstile interactive, Akamai BMP), real auth-walled apps, anything needing pixel-perfect rendering parity with Chrome.--## Known limits--- Not full Chrome — some browser APIs and CDP methods are incomplete relative to upstream Chromium.-- Screenshot capture is not implemented (no layout/rendering engine).-- Authenticated pages need cookie or session injection via CDP; Obscura won't run interactive logins.-- Hard CAPTCHAs (Turnstile interactive, hCaptcha) require a human or a third-party solver.--## Safety--Treat Obscura like any external Rust crate: `cargo build` runs dependency build scripts (V8, TLS). Build into a disposable target dir (`CARGO_TARGET_DIR=/tmp/obscura-target`) when evaluating new branches.+Connect Puppeteer with `puppeteer-core` or Playwright with+`chromium.connectOverCDP`. Standard `page.screenshot()` supports viewport and+full-page capture; `page.pdf()` produces raster-backed print output. Scroll+with page JavaScript before a viewport capture when the user wants a lower+section of the page.++Use raw CDP for `Page.captureScreenshot`, `Page.startScreencast`, and+`Page.printToPDF`. A screencast client must acknowledge every+`Page.screencastFrame` using `Page.screencastFrameAck`. Frames are driven by+page activity; this is not fixed-frame-rate desktop capture.++PDF output supports paper dimensions, margins, landscape, scale, backgrounds,+and page ranges. It does not currently provide selectable text, tagged PDF,+outlines, headers/footers, or complete CSS paged-media behavior.++## Drive MCP++Run `obscura mcp` for stdio or `obscura mcp --http --port 3000` for HTTP.+Navigate first, then inspect or interact with the current page. Refresh a+snapshot or interactive-element listing after navigation, clicking, scrolling,+or a framework rerender because element references may have changed.++Render-enabled MCP builds expose `browser_screenshot` as an MCP PNG image and+`browser_pdf` as an embedded PDF resource. MCP does not stream screencast+frames; choose CDP for that workflow.++## Validate visual behavior++Start with a deterministic fixture that isolates the behavior. Then test a+broad real-site set at both initial and scrolled positions. For an engine+comparison, keep viewport, device scale, user agent, network inputs, settle+policy, scroll, animation time, and capture boundary identical.++Confirm both engines navigated successfully and produced nonblank images before+interpreting a diff. Treat a pixel metric as a regression tripwire, not a+verdict. Inspect resource completion, box geometry, line wrapping, structural+edges, clipping, and fixed or sticky behavior, then reduce real failures to a+fixture. Do not introduce hostname-specific rendering logic.++## Set expectations accurately++Obscura has broad modern layout and paint coverage but is not a bundled Chrome+build. Long-tail CSS, service workers, some Web APIs, native media, GPU or+compositor effects, PDF structure, and platform font rasterization can differ+from Chromium. Measure performance and fidelity on the user's actual workload;+do not repeat fixed speed, memory, or exact-parity claims without current,+reproducible evidence.