Skip to content

lukehoban/browser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Browser - A Simple Web Browser in Go

CI Go Report Card

A simple web browser implementation in Go, focusing on static HTML and CSS 2.1 compliance. This project aims to stay close to W3C specifications and provide a clean, well-organized codebase for educational purposes.

Features

  • HTML parsing with DOM tree construction
  • CSS 2.1 parsing and style computation
  • Visual formatting model (box model, block layout)
  • High-quality text rendering with Go fonts (proportional sans-serif)
  • Font styling support (bold, italic, underline, size)
  • Image rendering (PNG, JPEG, GIF, SVG support)
  • Data URLs: Support for RFC 2397 data URLs (base64 and URL-encoded)
  • Background and border rendering
  • PNG image output
  • Network support: Load pages via HTTP/HTTPS
  • External CSS: Fetch and apply stylesheets from <link> tags
  • Network images: Load images from remote URLs
  • WebAssembly: Run the browser entirely in a web client

Project Structure

browser/
├── cmd/
│   ├── browser/      # Main CLI browser application
│   └── browser-wasm/ # WebAssembly entry point
├── html/            # HTML tokenization and parsing
├── css/             # CSS parsing
├── dom/             # DOM tree structure
├── style/           # Style computation and cascade
├── layout/          # Layout engine (visual formatting model)
├── render/          # Rendering engine
├── wasm/            # WebAssembly demo page
└── test/            # Test files and fixtures

Specifications

This browser implementation follows these W3C specifications:

Quick Start

Building

go build ./cmd/browser

Running

# Render local HTML file to PNG
./browser -output output.png test/styled.html

# Load and render a web page from URL
./browser -output hn.png https://news.ycombinator.com/

# View layout tree without rendering (text output)
./browser test/styled.html

# Custom viewport size
./browser -output output.png -width 1024 -height 768 test/hackernews.html

Screenshots

Font Rendering

The browser uses the Go fonts - high-quality, proportional, sans-serif fonts designed for the Go project. These fonts are embedded in the binary and provide excellent readability with support for bold, italic, and various sizes.

Font Comparison

Test Case Rendering

Example of styled HTML with borders, colors, and text formatting:

Test Case Rendering

Hacker News

Latest Hacker News render (1024x768):

Hacker News Rendering

Testing

go test ./...

WebAssembly

The browser can be compiled to WebAssembly and run entirely in a web browser. A live demo is available at https://lukehoban.github.io/browser/ and is automatically deployed via GitHub Actions.

To build locally:

GOOS=js GOARCH=wasm go build -o wasm/browser.wasm ./cmd/browser-wasm
cd wasm && python3 -m http.server 8080

See wasm/README.md for more details.

Documentation

Current Status

✅ Milestones 1-7 Complete: Foundation, HTML Parsing, CSS Parsing, Style Computation, Layout Engine, Rendering, Image Rendering
✅ Milestone 9 Complete: Network Support (HTTP/HTTPS, external CSS, remote images)
✅ Milestone 9.5 Complete: Data URL Support (RFC 2397, base64 & URL-encoded inline resources)
🔄 Milestone 8 In Progress: Testing & Validation (81.8% WPT pass rate)

See MILESTONES.md for detailed progress and known limitations.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •