Exploring the idea of generated web rendering engine.
genera docs content-scoped-engine.md

Content-scoped engines #

The proof of concept for "modular, fit for purpose" (README.md → "Goals") and Phase 4's configurable builds (roadmap.md → "Phase 4 — Configurable engine builds"): analyse a body of web content, find exactly which platform features it uses, and build the smallest engine that renders it correctly. Only the Stage 0 analyser's static half is built.

content captureURLs, site dir, archivefeature extractionstatic + dynamicdependency closureengine configurationcargo featuresverificationvotes, WPT subset,negative checkmanifest + coveragereport + build metadata

Use case #

  • Single-app embedders (a game client, an internal tool, a point-of-sale screen) that today bundle all of Chromium or write native UI.
  • Kiosks, fixed-function devices, e-readers: known content, constrained hardware.
  • Documentation and email renderers: wide but boundable content.
  • Archival replay: frozen content, so the needed surface is computable in advance.

They get a smaller attack surface and cheaper verification: the three-engine vote, the WPT subset and the trace vote only have to cover a bounded feature set. Content outside the analysed set is expected to fail — loudly, by design.

Pipeline #

Content capture #

Inputs: a URL list, a static site directory, or a web archive. Which subresources count (stylesheets, scripts, fonts, images, iframes, workers) is undecided. The oracle today supplies content inline through page.setContent (docs/dump-format.md → "Origin"), or serves one script-and-markup pair per trace request; capturing real sites needs navigation (page.goto) and a way to feed a whole site through the oracle. Archive format (WARC, HAR, MHTML) is undecided.

Feature extraction #

Static analysis. Parse without executing and map to browser-compat-data keys: HTML elements and attributes to html.*; CSS properties, values, selectors and at-rules to css.*; JavaScript identifiers and property accesses to api.* and javascript.*. Static JavaScript analysis cannot see computed access, eval, runtime-injected code, or whether a referenced API is ever called — a fast approximation, not ground truth.

Dynamic tracing. Load the content in the three oracle browsers with IDL-level instrumentation installed through the trace recorder's hook (context.addInitScript, docs/dump-format.md → "The recorder"): wrap interface prototypes so every property get and method call is logged. Not built. Applied CSS can come from the style-subset dump (docs/dump-format.md → "Style subset") extended to every property the page touches.

Roll-up to web-features. Compat keys roll up to web-features identifiers through crates/wpt-votes/src/features.rs WebFeatures, inverted: join_features.rs goes feature → key, this goes key → feature (WebFeatures::feature_ids_for_compat_key).

Dependency closure #

Flex implies block layout and the DOM core; fetch implies URL and streams. Where the dependency data comes from is undecided: hand-curated per feature; derived from webref's cross-reference graph (fine-grained enough is untested); or left implicit inside the always-present set.

Engine configuration #

Map the closed feature set to crates and cargo features using Phase 4's boundaries: globals-attached APIs (WebRTC, WebGL, IndexedDB, Web Audio) as units, and formatting contexts (flex, grid, table, multicol, positioned) behind a dispatch trait so an excluded one compiles out. Neither boundary exists yet; this would be their first consumer. Always present: the HTML parser, the DOM core, Stylo, and the hand-written substrate (box tree, fragment tree, style storage, invalidation, event loop).

Verification #

  • Three-engine votes on the target content itself (compare::vote, trace::vote), same 1/60 px tolerance and comparison order (docs/dump-format.md → "Comparison").
  • The WPT subset for exactly the features in the set, from crates/wpt-votes's tables, including the held-out partition (wpt_votes::partition::is_held_out, FNV-1a of the test path, hash % 100 < 20), which is never trained against (roadmap.md → "WPT supplies inputs, never expected outputs").
  • A negative check: content using an excluded feature must fail loudly. Undecided how: a runtime trap in the substrate; a build-time guarantee that excluded code paths do not exist; or a pre-check rejecting content whose feature closure is not inside the manifest.

Output artefacts #

  • A feature manifest per corpus (sketch, details undecided):

    {
      "corpus": {"id": "...", "source": "url-list | static-site | web-archive", "documents": 0},
      "features": {
        "bcd_keys": {"html.elements.div": {"source": ["static"]}, "css.properties.flex": {"source": ["static", "dynamic"]}},
        "web_features": ["flexbox", "..."]
      },
      "dependency_closure": {"added_keys": ["..."], "source": "hand-curated | spec-derived | undecided"},
      "engine_config": {
        "always_present": ["parser", "dom", "style"],
        "cargo_features": ["layout-flex", "api-webaudio"]
      },
      "verification": {
        "geometry_vote": {"cases": 0, "agree": 0},
        "wpt_subset": {"table": "corpus/wpt-votes/<rev>/table.tsv", "keys": 0, "held_out_included": true, "pass_rate": 0.0},
        "negative_check": "undecided"
      }
    }
    
  • A coverage report: feature counts and the share of compat data or web-features each corpus touches.

  • Engine build metadata: enabled cargo features, included crates, engine version — the build-level analogue of a provenance record.

Proof-of-concept targets, staged by what the engine can do #

  • Stage 0 — no generation needed. The analyser alone over a few real corpora, reporting feature counts and platform share. Measures the thesis that most content uses a small slice of the platform. Static half done (below).
  • Stage 1 — content within today's engine. Block layout the engine already passes (roadmap.md → "Phase 1"); realistically synthetic or very plain pages. Exit: the corpus's closed feature set is inside what Phase 1 covers and the geometry vote passes.
  • Later stages grow with generation (inline and text, flex, …), each gated on the matching docs/platform-areas.md row becoming generated and on the vote and WPT subset clearing that category's bar.

Success measures #

  • Features used against the platform: of roughly 17,300 engine-relevant compat entries or 1,210 web-features identifiers (docs/platform-economics.md → "Method").
  • Engine size and build time against a full build (not yet measured).
  • Pass rates on the target content and on the WPT subset, held-out partition reported separately.
  • Analysis cost. The only baseline is the oracle's synthetic 13 documents/s per engine; real content with subresources and JavaScript needs its own figure.

Risks and open questions #

  • Dynamic JavaScript hides feature use, and the recorder has no interaction driver (it stops at trace.done() or 5000 ms).
  • Feature detection (if ('IntersectionObserver' in window)) looks like use under naive tracing; treat any access as a dependency, or trace branches — undecided.
  • User-agent sniffing: content may serve the oracle's real browsers different code than it would serve this engine.
  • Third-party embeds change their feature use independently of the site.
  • Content changes: re-analysis is manual, scheduled or diff-triggered — undecided.
  • An under-inclusive dependency closure passes its own corpus and breaks on real variation.

Next steps #

Stage 0 continues: JavaScript API use and dynamic tracing, mapping SVG, MathML and ARIA (outside compat data's html.* tree), and more corpora. The oracle enters only with dynamic tracing, reusing the recorder's context.addInitScript hook.

Stage 0 results (static HTML and CSS) #

crates/content-analyser: bin/fetch_urls fetches a URL list once; bin/analyse walks .html/.htm and .css files with html5ever and cssparser, maps elements, attributes, <style> and style="..." declarations, selectors, pseudo-classes and at-rules to compat keys (Bcd::load, crates/content-analyser/src/bcd.rs, reading the package's own html and css trees), and rolls them up through WebFeatures::feature_ids_for_compat_key. Pinned: browser-compat-data 8.1.2, web-features 3.39.0. Fetched content and manifests are gitignored under corpus/content-analyser/.

corpus documents browser-compat-data keys used html keys css keys web-features ids
mdn-docs 5 210 96 / 824 (11.65%) 114 / 4071 (2.80%) 108
danluu-blog 5 95 57 / 824 (6.92%) 38 / 4071 (0.93%) 45

mdn-docs is five MDN reference pages (component-heavy: React chrome, declarative shadow DOM, inline SVG); danluu-blog is five pages of near-plain hand-written HTML and CSS. Both touch a small slice of the platform, the plain blog about half as much.

What the static pass cannot see:

  • Anything outside html.* and css.*: SVG, MathML and ARIA are walked but never matched (3534 unmapped attribute uses on mdn-docs, 7 on danluu-blog, printed by bin/analyse but not in the manifest).
  • Which declarations apply: present counts, applied does not; that needs the dynamic half.
  • Custom properties and computed values: var(), calc() and keywords compat data does not enumerate count as the property alone.
  • Cross-origin stylesheets that fetch_urls did not fetch.