I Built a Web Browser from Scratch in 42 Days
42 days ago I made a decision.
I wanted to understand how the internet actually works. Not just use it. Not just build on top of it. Actually understand it — at the wire level.
So I started building a web browser from scratch. In Node.js. No external libraries. Every line written by hand.
I called it Courage.
What Courage can do today
...
- Parse URLs into protocol, host, port, path
- Open raw TCP and TLS connections
- Build and send HTTP GET requests
- Parse HTTP responses including chunked encoding
- Tokenize raw HTML character by character
- Build a DOM tree using a stack
- Match CSS rules to DOM nodes
- Calculate layout (x, y, width, height) for every element
- Paint rectangles and text on a Canvas using Electron
- Execute JavaScript via eval()
- Navigate with back, forward, reload
- Multiple tabs with independent history
- Render real websites — today it rendered Wikipedia
What I learned
Before this project I knew how to use the web. Now I understand it.
TCP handshakes aren't magic. HTTP is just text. HTML is just tokens. CSS is just rules. A browser is just a pipeline.
Every abstraction that used to feel like magic now makes complete sense.
The most surprising thing — a layout engine is just two passes over a tree. Width flows down from parent to child. Height bubbles up from child to parent. That's it. That's what every browser does.
The hard days
Day 9 — built a DOM tree using a stack. Failed 6 times before it clicked.
Day 21 — layout engine born. Took 3 days to get width and height right.
Day 42 — fixed a bug where CSS inside style tags was breaking the entire DOM tree because my tokenizer treated > in CSS selectors as HTML tag endings.
Every bug taught me something real.
The code
github.com/Nitin-kumar-yadav1307/Courage
42 days. No libraries. Every line by hand.
This is just the beginning.


Top comments (0)