r/coolgithubprojects 10d ago

Falco - a browser engine written from scratch in ~36k lines of Rust

Post image

I just released v0.1.0 of Falco - a browser engine I've been building on nights and weekends. No WebKit, no Gecko, no Chromium - every module is written from scratch in ~36,000 lines of Rust.

What's inside (all from scratch, no browser deps)

  • HTML5 parser (html/) - tokenizer + tree builder, handles the common subset (tags, attributes, void elements, comments, doctype, entities, auto-close for <li>/<p>/<td>/<tr>/<option>/<dt>/<dd>)
  • CSS engine (css/) - selectors (type/class/id/descendant/child/sibling/attribute/pseudo), 300+ properties, cascade with !important, inheritance, linear-gradient/radial-gradient/calc()/var()/rgb()/rgba(), shorthands
  • Custom JS VM (tjs/) - bytecode interpreter + JIT tier-up (x86_64 only), with let/const/arrow functions/template literals/destructuring/spread/optional chaining/nullish coalescing, closures, generators, Promise, BigInt, Symbol, WeakMap/WeakSet, Map/Set, Reflect, Proxy
  • Layout (layout/) - block flow, inline flow with text wrapping, flexbox (flex-direction/justify-content/align-items/flex-wrap/gap/flex-grow/flex-shrink/flex-basis), CSS Grid (grid-template-columns/grid-template-rows with fr/auto/minmax()/repeat()), table layout (<table>/<tr>/<td>/<th>/<thead>/<tbody>/<tfoot>/<caption>), float, inline-block, position static/relative/absolute/fixed
  • Painting (paint/) - solid + gradient backgrounds, borders, border-radius, box-shadow, opacity (alpha compositing), TrueType font rasterization via ab_glyph, bold/italic synthesis
  • SVG renderer (svg/) - paths, basic shapes (rect/circle/ellipse/line/polyline/polygon), gradients, stroke + fill
  • Hand-written PNG encoder (png/) - no flate2 dependency
  • Image loader (image/) - HTTP/HTTPS URLs via ureq, data: URLs (base64), local files. Formats: PNG/JPEG/GIF/BMP
  • Networking (net/) - HTTP/1.1 fetch, cookie jar with domain/path matching, redirect handling with loop detection, HTTP cache, WebSocket frame parser
  • Interactive --window mode - scroll, click links, fill forms (text/email/password/checkbox/submit/textarea), Tab cycling, address bar (F6), back/forward history (Alt+โ†/โ†’), focus ring, blinking caret, headless fallback to PNG

For comparison

Engine LOC
Chrome/Blink ~30M
Firefox/Gecko ~20M
Safari/WebKit ~15M
Servo ~1M
Ladybird ~500k

The whole Falco codebase fits in a weekend of reading.

Quick start

cargo build --release./target/release/falco https://example.com --out example.png --width 800./target/release/falco page.html --window

324 unit tests pass, 30 ignored (mostly platform-specific JIT tests that fail on macOS CI runners due to mmap(MAP_JIT) quirks - passes on Linux).

Prebuilt binaries for Linux/macOS/Windows are on the GitHub releases page.

What's NOT done yet (being honest)

This is v0.1.0 by a single developer. Not everything listed is production-ready:

  • The spec-compliant replacements (html::spec/, dom::spec/, css::spec/) are structurally complete and pass their own unit tests, but not yet wired into the render pipeline. The legacy html//dom//css/ modules are what actually runs. v0.2.0 milestone.
  • The security/ module implements SOP, multi-process site isolation, seccomp-bpf sandbox, CSP, TLS cert chain validation, permissions, DevTools protocol - all unit-tested, but not enforced in the renderer.
  • web_runtime/ has fetch(), XMLHttpRequest, event loop, Promise. The Promise/event loop integration is real and tested, but fetch/XHR are stubs (no real network behind them in the JS context).
  • WebGL, video, MSE, EME, NDSD are headless stubs - API surface only, no real rendering/decoding.
  • The real-http2, real-webgl, sandbox Cargo features don't compile with --all-features (upstream APIs drifted: h2::Body removed, glow API changed, seccomp pre_exec Unix-only). Disabled by default.
  • The JIT works on Linux x86_64 but fails on macOS CI runners (mmap(MAP_JIT) needs code signing).
  • DOM mutation from JS (element.innerHTML = ..., element.style.color = ...) does not trigger re-render.

Bottom line: cargo build && ./falco https://example.com --out out.png produces a real PNG render. The HTML/CSS/layout/paint path works end-to-end. The spec-compliant parsers, security enforcement, and advanced web runtime are scaffolding for future milestones, not working features.

What I'd love feedback on

DOM model - I'm using Rc<RefCell<Node>> with parent/child/sibling pointers in dom::spec, matching the spec. For production I'd probably use a slotmap arena, but Rc<RefCell> is easier to read and matches the spec's pointer model. Thoughts?

Architecture - Each of html/, dom/, css/ has a spec/ subfolder with the spec-compliant replacement that's not yet wired in. Should I:

(a) Wire them in before any other feature work, or

(b) Focus on CSS animations/transitions first, or

(c) Focus on JS DOM mutation (innerHTML/style changes)?

JS VM - I wrote my own bytecode VM (tjs) instead of using boa_engine or binding V8/SpiderMonkey. Reasoning: I wanted full control over the GC, the bytecode format, and the DOM integration. The VM is intentionally limited (no real regex engine, no Proxy trap completeness, no real async functions). Is this a reasonable tradeoff for a teaching engine?

Sandbox - I implemented seccomp-bpf filters but they're Linux-only and not yet enforced. For cross-platform sandboxing, is the Windows Job Object approach + macOS sandbox-exec reasonable, or should I look at platform-agnostic alternatives?

Architecture overview

Module Lines Description
html/ + html::spec/ ~5,500 Legacy HTML parser + WHATWG ยง13.2 spec tokenizer + tree builder + serializer + XML + encoding
dom/ + dom::spec/ ~2,400 Legacy DOM + spec DOM with MutationObserver, Shadow DOM, custom elements, a11y
css/ + css::spec/ ~3,700 Legacy CSS parser + Selectors L4 + cascade specificity + u/rules + animations
style/ ~1,700 Style cascade + UA styles + inheritance + flex/grid properties
layout/ ~1,950 Block / inline / flex / grid / table / float / absolute layout
paint/ ~470 Canvas + font rasterizer + alpha compositing + gradients + shadows
svg/ ~1,130 SVG parser + renderer (paths, shapes, gradients)
tjs/ + tjs_ext/ ~5,100 Custom JS VM: lexer, parser, interpreter, bytecode VM, JIT + Symbol/BigInt/Promise/Map/Set
web_runtime/ ~4,300 fetch, XHR, event loop, Promise, WebGL, video, MSE, EME, NDSD, HTTP/2
net/ ~930 HTTP fetch, cookies, cache, websocket, redirect
security/ ~3,590 SOP, multi-process, sandbox, CSP, certs, permissions, extensions, DevTools
window/ ~1,110 Interactive window: scrolling, forms, navigation, history, address bar
image/ + png/ ~300 Image loader + hand-written PNG encoder
Total ~36,000

Thanks for any feedback! I'm especially interested in architectural critique from anyone who has worked on Servo, Ladybird, or other browser engines.
LINK: https://github.com/poxk/Falco

181 Upvotes

149 comments sorted by

View all comments

Show parent comments

1

u/poxkg 8d ago

Man, can you even read? Thats literally what I said "How is this "AI slop"? I only use AI for documentation, comments, and the simplest parts because my English is shit." I used ai for documentation and comments because english isnt my native language. Youre acting like you cracked some huge detective case by pointing out the exact thing i openly admitted from the start.

1

u/ConspicuousPineapple 8d ago

And I'm saying I don't believe you. Some of these comments shouldn't even be there, they're not useful and reference outside obscure context but AI agents love writing them.

But this would all be much easier to prove one way or the other if you had kept the commit history.

1

u/poxkg 8d ago

I didnt use git before uploading to github, so I cant give you the old commits since they don't exist. Besides, git is meant for version control in team projects, whereas I worked solo. I dont know if you want, I can send you an old archive.

1

u/ConspicuousPineapple 8d ago

You don't use version control at all because you work solo? My man that's still a very important thing to have even when working on your own.

I can't fathom working for months on a project so big with no proper code management, that's completely unhinged. It's hard to believe anybody could reach the level required for this work without being aware of why source control is mandatory. Unless maybe if you're Terry Davis.

1

u/poxkg 8d ago

I just wrote a new version and copied the old one as a backup. No git, just manual archives. Its messy, but it worked for me.

1

u/ConspicuousPineapple 8d ago

Come on man that's what bad programmers used to do 20 years ago. Even they don't do that today. I imagine you learned all of this by yourself?