Skip to content

andre-eriksson/browser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

233 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Browser

A web browser built in Rust! It currently supports a subset of HTML and CSS when rendering, as well as UI elements like tabs. The goal of this project is to learn more about how browsers work under the hood and to improve my Rust skills, as such it contains a few dependencies but is otherwise built from scratch.

Warning

This is a work in progress and is not intended for production use. It is missing many features and is not optimized for performance or security.

Features

  • Headless mode
  • Navigating to URLs
  • Cookies
  • UI theming with user configurable TOML file
  • Tabbed browsing

Extra

Supported CSS properties can be found: ./docs/CSS.md.

Screenshots

https://github.com/andre-eriksson

A screenshot of the app rendering my own GitHub page

https://flask.palletsprojects.com/en/stable/quickstart

A screenshot of the app rendering the Flask quickstart page

https://en.wikipedia.org/wiki/Web_browser

A screenshot of the app rendering the Wikipedia page for web browsers

Architecture

The browser is composed of 7 subsystems, each responsible for a specific aspect of the browser's functionality.

Subsystems

  • IO Subsystem: Responsible for handling all input/output operations, including file system access and network communication.
    • HTTP Client: Responsible for making HTTP requests and handling responses.
  • HTML Parser: Parses HTML documents and builds the DOM tree.
  • CSS Parser: Parses CSS stylesheets and builds the CSSOM.
  • Layout Engine: Generates the layout tree based on the DOM and style tree.
  • Rendering Engine: Renders the layout tree to the screen using GPU acceleration.
  • Kernel (Browser Core): Manages the overall browser state, including tabs, navigation, and communication between subsystems.
  • UI Layer: Manages the user interface elements like tabs, address bar, etc.

Planned Features

  • History management
  • Bookmarks
  • Download manager
  • Form handling

Non-Goals (for now)

  • JavaScript support
  • Advanced CSS features (animations, flexbox, grid, etc.)
  • Advanced security features (sandboxing, etc.)
  • Extensions or plugins
  • Spec compliance with all web standards

How to Run

  1. Install Rust (https://www.rust-lang.org/tools/install)
  2. Run
# Standard mode
$ cargo run

# Help for command line options
$ cargo run -- --help

# Headless mode
$ cargo run -- --headless

# Start with a specific URL
$ cargo run -- --url http://localhost:5000/preview.html

Testing

The project includes unit tests for many subsystems. To run the tests, use the following command:

$ cargo test

# Specific crate tests
$ cargo test -p <crate-name>

Dependencies

This project intentionally uses a limited set of dependencies, the goal for this project is to minimize relying on external libraries for core functionality, but I am also realistic about what can be achieved in a reasonable timeframe.

Rust Crate Dependencies

Rust crates dependencies are chosen based on the following criteria:

  • Essential functionality that would be impractical to implement from scratch and is out of scope for this project (e.g., wgpu for GPU rendering).
  • Development and testing tools that do not impact the core functionality of the browser (e.g., tracing for logging).
  • Libraries that would force me to work extensively on other aspects that isn't browser related (e.g., serde for serialization/deserialization).
  • Temporary dependencies that facilitate developer velocity, these fall into two sub-categories:
    • Dependencies that will be replaced by a lower-level dependency eventually (e.g., reqwest for HTTP requests, which could eventually be replaced by curl/libcurl).
    • Dependencies that come from another dependency but are used for convenience and will be removed when that dependency is removed (e.g., cosmic-text for text shaping, which is a dependency of iced).

To generate the most up-to-date list, run the gen_third_party.py script and/or refer to the Cargo.toml file and each individual subsystem crate's Cargo.toml, e.g., crates/errors/Cargo.toml.

External

This project relies on some external tools and libraries, these are not dependencies of the browser itself but are used to facilitate development and testing.

  • Python 3 - Required to run the Flask server and other scripts.
  • Flask - Used for serving test HTML files, allows us to test internal functionality outside of rendering such as cookies, headers, etc.

Fonts

We have fallback fonts to ensure that the browser can always render text properly, these can be found in: ./assets/font, licenses for these fonts can be found in FONTS.md.

Currently included fonts:

  • OpenSans (SIL Open Font License)
  • Roboto Mono (SIL Open Font License)

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A simple web browser made in Rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages