Skip to content

Architecture and Pipeline

SIDHARTH SINGH edited this page Dec 3, 2026 · 1 revision

Architecture & Render Pipeline

ONEX avoids dragging browser processes into pure PDF work by splitting cleanly across three zones:

  1. Rendering Zone: Manages Playwright contexts, browser epoch tracking (epochValue), transparent crash recovery (PagePool), font fallback injection, and pixel-budget canvas downsampling.
  2. Pure-JS PDF Core: Parses xref tables, /ObjStm streams, and incremental /Prev chains in pure TypeScript (src/pdf/), compacts objects semantically (src/optimize/), extracts coordinates (src/extract/), enforces PDF/A (src/compliance/), redacts streams (src/redact/), and compares PDFs (src/inspect/diff.ts).
  3. Delivery Surfaces: Exposes the same engine and guarantees across Node API, 17 HTTP endpoints, 18 MCP JSON-RPC tools, 25 CLI commands, and the onex-pdf/puppeteer adapter.

One-Shot vs Live Sessions

  • One-shot documents (doc.setContent() / doc.setURL()) spin up a clean isolated BrowserContext per render and destroy it inside a finally block so cookies, DOM globals, and caches never leak between requests.
  • Live documents (doc.goto() / doc.setContentLive()) borrow a persistent context keyed by document inside PagePool. You can fill forms, click buttons, wait for network fetches, evaluate functions under strict CSP via CDP Runtime.callFunctionOn, and print the live DOM cleanly. Live mode automatically bypasses ONEX's deterministic SHA-256 LRU render cache.

How Printing Works Step by Step

  1. Enters the bounded semaphore (maxConcurrency active, maxQueueSize pending, rejecting overflow immediately with ONEX_QUEUE_FULL).
  2. Re-checks URL targets against checkUrlAsync() right before navigation.
  3. Normalizes legacy Kruti Dev / Chanakya fonts if detected in HTML (convertLegacyFonts).
  4. Applies reportMode pagination styles (thead/tfoot repeat + break-inside: avoid rows) and runs safe pageNumbers footer templates.
  5. Scans DOM text in three stages so bundled Noto scripts (Devanagari, Bengali, Tamil, Arabic, and ₹) only inject when actually needed.
  6. Downsamples oversized images inside a rendered CSS box budget while keeping transparent pixels intact as PNG.
  7. Measures continuous singlePage or thermal receipt height cleanly and caps pages at maxPages.
  8. Runs toBuffer() post-processing: optimization (none, fast, balanced, maximum), progressive maxBytes tightening, and archival PDF/A wrapping.

Clone this wiki locally