I'm building a web browser engine from scratch.
The engine is the part of a browser that turns a web page's code into what you see on screen. Nirvana is mine, written in Rust, one piece at a time, and it already runs inside an Android browser.
- Match with Chrome
- 36.3 / 100
- Tests passing
- 404
- Lines written
- 46,531
What is a browser engine?
Every website reaches your phone as plain text: HTML says what is on the page, CSS says how it should look, and JavaScript says what it does when you tap things.
Text is not a picture. Something has to read all three, decide where every word, image and button goes, and colour in millions of pixels, many times a second. That something is the engine.
Chrome's engine is Blink. Safari's is WebKit. Firefox's is Gecko. Nearly every other browser borrows one of those. Nirvana is a new one, written from the first line.
The browser appTabs, address bar, buttons
The engineReads the page and draws it
The web pageHTML, CSS and JavaScript
How Nirvana turns a page into pixels
Six steps, in this order, every time you open a page. Most of it is code I wrote. Where the engine leans on an existing open-source library, it says so.
-
Download
Fetch the page and everything it needs: stylesheets, images, scripts, fonts. Blocked ads and trackers are never downloaded at all.
Written by me with the
ureqHTTP library underneath -
Read the HTML
Turn the text into a tree of elements. Real pages are full of mistakes, so the parser repairs them exactly the way the HTML standard describes.
Written by me and passes all 8,701 html5lib tests
-
Work out the style
Read the CSS and decide the final look of every element: colour, size, font, spacing. When rules disagree, the most specific one wins.
Written by me
-
Lay out the boxes
Every element becomes a box. Measure the text, wrap the lines, and give every box an exact position and size on the screen.
Written by me except CSS Grid, which uses
taffyfor now -
Run JavaScript
Let the page's scripts change things, with a time limit so a broken script cannot freeze the app.
Library
Boaruns the JavaScript; the bridge to the page is mine -
Paint and show
Draw the boxes in the right order: backgrounds, borders, text, images, SVG. Then hand the finished picture to the Android app.
Written by me with
tiny-skiafilling in the shapes
How close is it to Chrome?
I open the same websites in Nirvana and in Chrome, on the same phone-sized screen, and compare the two screenshots piece by piece. 100 would mean identical.
36.3/100
Average over 27 real websites. Simple, well-built pages are close; big sites like GitHub and BBC still look very different. That is the honest starting point, and every update tries to move it.
Score for each website
Average score after each round of fixes
The first two rounds compared against a desktop-width Chrome; from the third round on, against Chrome pretending to be a phone, which is fairer.
Updates
What changed, in plain words, newest first.
What's next
The long-term plan is to replace each borrowed library with my own code, one at a time, without letting the Chrome score go down.
Done
Spec-exact HTML parser, CSS cascade and
calc(), margin collapsing, SVG images, matching fonts.Working on
The worst-looking sites: GitHub, BBC and Amazon. Percentage heights.
Next
My own CSS Grid layout and image decoders.
Later
My own shape drawing, text shaping, and eventually a JavaScript engine.