Repository navigation
Architecture and Pipeline
SIDHARTH SINGH edited this page Dec 3, 2026
·
1 revision
ONEX avoids dragging browser processes into pure PDF work by splitting cleanly across three zones:
-
Rendering Zone: Manages Playwright contexts, browser epoch tracking (
epochValue), transparent crash recovery (PagePool), font fallback injection, and pixel-budget canvas downsampling. -
Pure-JS PDF Core: Parses xref tables,
/ObjStmstreams, and incremental/Prevchains 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). -
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/puppeteeradapter.
-
One-shot documents (
doc.setContent()/doc.setURL()) spin up a clean isolatedBrowserContextper render and destroy it inside afinallyblock so cookies, DOM globals, and caches never leak between requests. -
Live documents (
doc.goto()/doc.setContentLive()) borrow a persistent context keyed by document insidePagePool. You can fill forms, click buttons, wait for network fetches, evaluate functions under strict CSP via CDPRuntime.callFunctionOn, and print the live DOM cleanly. Live mode automatically bypasses ONEX's deterministic SHA-256 LRU render cache.
- Enters the bounded semaphore (
maxConcurrencyactive,maxQueueSizepending, rejecting overflow immediately withONEX_QUEUE_FULL). - Re-checks URL targets against
checkUrlAsync()right before navigation. - Normalizes legacy Kruti Dev / Chanakya fonts if detected in HTML (
convertLegacyFonts). - Applies
reportModepagination styles (thead/tfootrepeat +break-inside: avoidrows) and runs safepageNumbersfooter templates. - Scans DOM text in three stages so bundled Noto scripts (
Devanagari,Bengali,Tamil,Arabic, and₹) only inject when actually needed. - Downsamples oversized images inside a rendered CSS box budget while keeping transparent pixels intact as PNG.
- Measures continuous
singlePageor thermal receipt height cleanly and caps pages atmaxPages. - Runs
toBuffer()post-processing: optimization (none,fast,balanced,maximum), progressivemaxBytestightening, and archival PDF/A wrapping.
- Home
- Architecture & Render Pipeline
- PDF Internals & Extraction
- Unicode 16, Fonts & Legacy Indic
- Security & SSRF Model
- Digital Signing (
signPdf) - True Redaction (
redactPdf) - Semantic Diff & Redlines (
diffPdfs) - Self-Auditing Renders (
renderVerified) - PDF/A-3b & E-Invoices (
renderEInvoice) - HTTP, MCP, CLI & Puppeteer
Handbook & Deep Analysis: bahubalisid.github.io/onex