Skip to content

About

Modular, security-first web browser engine built from scratch in Rust featuring custom DOM, CSSOM, JS VM, and wgpu compositor.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

69 Commits

Folders and files

Repository files navigation

Browser Engine

Crates.io Documentation CI License: AGPL v3 Language: Rust 2021 Graphics: wgpu Security: rustls

A modular, GPU-accelerated, security-first web browser engine built completely from scratch in pure Rust.

The engine does not rely on Chromium, WebKit, or Gecko internals. It implements its own HTML tokenizer, arena-based DOM tree, CSSOM cascade resolver, box-model layout calculator, hardware-accelerated paint pipeline via wgpu, custom stack-based JavaScript bytecode VM, native TLS 1.3 networking, and multi-process security architecture.


Kestrel Browser Engine Shell & Renderer Preview

Live standalone Kestrel browser shell: wgpu GPU compositor, custom HTML layout, Omnibox, and multi-tab manager running on Windows.


Architectural Pipeline

[ Raw Network Stream / File Input ]
                 |
                 v
   +-----------------------------+         +-----------------------------+
   |  HTML5 Tokenizer & Builder  |         |   CSS Tokenizer & Parser    |
   +--------------+--------------+         +--------------+--------------+
                  |                                       |
                  v                                       v
         [ Arena DOM Tree ]                      [ CSSOM Stylesheet ]
                  \                                       /
                   \                                     /
                    v                                   v
          +-------------------------------------------------------+
          |      Style Resolution & Specificity Matching          |
          |       - Element Selector Matching (ID/Class/Type)     |
          |       - Cascade Resolution & Computed Property Map    |
          +---------------------------+---------------------------+
                                      |
                                      v
          +-------------------------------------------------------+
          |            Box Model Layout Calculation               |
          |       - Content, Padding, Border, Margin Rects        |
          |       - Block Formatting Context & Inline Runs        |
          +---------------------------+---------------------------+
                                      |
                                      v
          +-------------------------------------------------------+
          |            Display List Paint Engine                  |
          |       - Draw Rectangles, Border Lines, Text Glyphs    |
          |       - Decoded Texture Images (PNG / JPEG)           |
          +---------------------------+---------------------------+
                                      |
                                      v
          +-------------------------------------------------------+
          |          GPU Hardware Compositor (wgpu)               |
          |       - Low-level Vulkan / Metal / DirectX 12         |
          |       - Vertex Buffers, Layer Blending & Viewport     |
          +---------------------------+---------------------------+
                                      |
                                      v
                           [ Native Window Frame ]

Engine Subsystems

1. HTML Tokenizer & Arena-Based DOM

  • Resilient Parsing: Resilient tokenizer handling malformed HTML tags, unclosed attributes, comments, and doctypes without panicking.
  • Arena Tree Structure: The DOM is represented as an index-linked memory arena (Vec<DomNode>), eliminating raw cyclic reference-counting overhead and guaranteeing cache-locality.

2. CSSOM, Specificity Cascade & Variables

  • Selector Matching: Right-to-left evaluation supporting type, class, ID selectors, attribute selectors ([attr], [attr="value"], [attr*="value"], [attr^="value"], [attr$="value"], [attr~="value"], [attr|="value"]), and combinators (>, +, ~, descendant).
  • Cascade Specificity: Strict specificity tuple tracking (id_count, class_count, type_count) honoring !important declarations, stylesheet origin, and source order.
  • CSS Custom Properties & Variables: Full support for --* custom properties with DOM tree inheritance and recursive var(--name, fallback) resolution.
  • HTML5 User-Agent Default Stylesheet: Built-in standard styling for semantic elements, tables, lists, buttons, headings, and modern form controls.

3. Box Model Layout Engine

  • CSS Box Model: Computes exact coordinates for content, padding, border, and margin geometry.
  • Formatting Contexts: Supports vertical block stacking, explicit and auto dimensions, overflow wrapping, and display: none pruning.

4. GPU-Accelerated Hardware Compositor

  • Direct GPU Rendering: Powered by wgpu targeting cross-platform native graphics APIs (DirectX 12, Vulkan, Metal).
  • Text & Texture Pipeline: Hardware-accelerated glyph caching via wgpu_glyph and native image texture decoders (PNG and JPEG).

5. Custom JavaScript Bytecode VM

  • Compiler & Bytecode: Custom lexer, Pratt parser, and compiler translating ECMAScript subsets into compact bytecode instructions.
  • Stack-Based Execution: Fast evaluation loop with local variables, arithmetic, closures, and branching.
  • Mark-Sweep Garbage Collection: Fully functional cycle-detecting mark-sweep GC managing object allocations.
  • DOM Bindings: Direct bidirectional bindings allowing JavaScript to manipulate the DOM tree dynamically.

6. Native Networking & TLS 1.3

  • Pure Rust Cryptography: HTTP/1.1 client with modern TLS 1.3 encryption using rustls and webpki-roots.
  • Resource Discovery: Discovers and fetches external stylesheets (<link rel="stylesheet">) and remote assets automatically.

7. Security Architecture & Sandboxing

  • Multi-Process Model: Clean separation between the privileged UI browser process and sandboxed renderer instances communicating over IPC channels.
  • Policy Enforcement: Strict Same-Origin Policy (SOP) and Content-Security-Policy (CSP) headers verification.
  • Transactional Storage: Origin-isolated IndexedDB transaction manager and session cookie jar.

8. Native Browser Shell UI

  • Multi-Tab Architecture: Dynamic tab creation, switching, and closing.
  • Omnibox Navigation: URL normalization and search engine routing with interactive suggestion dropdowns.
  • Right-Click Context Menu: Native contextual operations: Back, Forward, Reload, Copy Page URL, and Inspect Element.

9. Built-in DevTools & DOM Inspector

  • Dock Panel [F12]: Hardware-rendered diagnostic overlay supporting live tabbed panels: Elements, Console, Network, and Performance.
  • Live DOM Inspector: Recursive tree inspection with tag/attribute syntax highlighting, node IDs, and computed CSS box model dimensions.
  • Diagnostic Logging: Direct integration with JavaScript runtime execution logs and network waterfall requests.

Keyboard Shortcuts & Controls

Shortcut / Action Description
F12 Toggle built-in DevTools Dock Panel (DOM Inspector, Console, Network)
Ctrl + T Open a new browser tab
Ctrl + W Close the active browser tab
Ctrl + R / F5 Reload the current page
Ctrl + L Focus the Omnibox address bar
Ctrl + + Zoom in page content
Ctrl + - Zoom out page content
Right-Click Open Context Menu (Back, Forward, Reload, Copy URL, Inspect Element)
Scroll Wheel Smooth vertical page scrolling

Getting Started

Prerequisites

Install the standard Rust toolchain:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

On Linux systems, install graphics and windowing libraries:

# Ubuntu / Debian
sudo apt-get install -y libx11-dev libxi-dev libxrandr-dev libxcursor-dev libxkbcommon-dev libwayland-dev

Build & Run

# Clone the repository
git clone https://github.com/rahadbhuiya/browser_engine.git
cd browser_engine

# Run the test suite (124 unit tests covering DOM, CSSOM, Layout, JS VM, and Security)
cargo test

# Build and run the browser in release mode
cargo run --release

Authors & Acknowledgments

  • Rahad Bhuiya (@rahadbhuiya)
    • Core Systems & Linux Kernel Engineer
    • Author of xdp-guard and Exploidus OS

License & Commercial Inquiries

browser_engine is dual-licensed under open-source and commercial terms:

1. Open Source (GNU AGPLv3)

For open-source projects, academic research, and non-commercial exploration, this project is licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later). Under this license, any web browser, embedded WebKit/Blink alternative, kiosk runtime, or server-side headless renderer incorporating, modifying, or linking browser_engine must make its complete source code available under compatible copyleft terms when distributed or deployed over a network. See LICENSE for the full text.

2. Proprietary Commercial License

For enterprises, embedded device OEMs, financial/defense organizations, and proprietary software vendors who wish to embed browser_engine into closed-source commercial applications, security-isolated web views, or proprietary hardware without AGPLv3 copyleft obligations:

  • Commercial licenses are available without copyleft requirements.
  • Includes custom rendering pipeline integration, GPU backend porting, and dedicated support.
  • For commercial licensing terms, proprietary SLA, and custom integration inquiries, contact: [email protected].

About

Modular, security-first web browser engine built from scratch in Rust featuring custom DOM, CSSOM, JS VM, and wgpu compositor.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages