A browser in 688 KB: what Win32 and WebView2 can still do

2026-11-24来源 dev.toEnglish
A browser in 688 KB: what Win32 and WebView2 can still do

The browser engine is already on your machine. That sentence is the whole project.

I wanted a window small enough to keep one page in the corner of the screen — a dashboard, an API
reference, a chat — without keeping a whole browser window there. The options I found were either a
pinned browser window or an Electron mini-browser with an 80–150 MB runtime. So I built the host
myself: tinybrowser, a 160×90 always-on-top browser for Windows in a single 688,640-byte exe.

No Electron. No installer. No VC++ redistributable. C++20, Win32 and the WebView2 runtime that ships
with Edge and Windows 11.

tinybrowser demo: the window, the colour eyedropper, a .to snapshot and duplicated windows

The 46-second demo: demo.mp4.

The engine is not inside the exe

That is the trick, and it is also the trade-off. WebView2 is a system component; the exe is only the
host. It statically links the runtime (/MT), compiles with /O2, /OPT:REF and /OPT:ICF, and
carries the window, the HTML bar, the gestures, the containers and the snapshot format. That is why
the number is 688 KB and not 80 MB.

If you want the same idea on macOS or Linux, you need a different host and a different system runtime.
tinybrowser is deliberately Windows-only.

One window, one engine, one page

Each tiny window is a real browser: address bar, navigation, zoom, cookies, sessions. It is not a
fixed-URL viewer. There are no tabs on purpose — one page per window, as many windows as you need.
Ctrl+Alt+D duplicates the current one into the next free spot; Ctrl+click opens a link in another
one.

The window has two sizes that belong to the app: a 141×77 start bar and a 160×90 page window.
Every page is scaled so its whole width fits; without that, 90 px of height would show one corner of a
desktop layout. The user can resize it by hand down to 60×60, and the app leaves that size alone.

Per-window containers, without a browser process per container

A container is a separate set of cookies, sessions, storage, cache, permissions and history for the
same window. It is a WebView2 profile inside the same data folder, not a second copy of the
engine. Two Google accounts can stay open at the same time; changing the container reloads that page
in the other profile and keeps the window, size and zoom.

The same idea makes .to snapshots possible: a window is frozen into a plain key=value text file
with its address, rectangle, zoom, container, corners and keyed colours. Double-click it in Explorer
and the window comes back exactly as it was. The file is readable in Notepad; no database, no cloud.

tinybrowser's start bar: address field, six buttons and the container name

The hard parts were all host-side

1. Windowed WebView2 cannot be translucent

The colour eyedropper makes a colour transparent to the desktop, including video and canvas. That is
not a CSS background trick: the engine is drawing per-pixel alpha. To get it, the window has to move
from windowed hosting (a child HWND) to composition hosting (a DirectComposition tree). The
host also adds WS_EX_NOREDIRECTIONBITMAP so the window has no surface of its own, and sets a
transparent default background:

controller2->put_DefaultBackgroundColor(COREWEBVIEW2_COLOR{0, 0, 0, 0}); 

The price is that pointer input has to be forwarded by hand, because there is no child HWND to receive
it. The first colour pick recreates the engine, so the page is empty for about a second. That is the
honest cost of per-pixel transparency in WebView2; I did not find a cheaper way.

2. Rounded corners are a window region, not a frame

Windows 11 has a corner preference, but it gives you a fixed radius — not a 0–100 slider where 100
means “as round as four equal corners can be”. The shape is a Win32 region:

HRGN region = CreateRoundRectRgn(0, 0, width + 1, height + 1, radius * 2, radius * 2); SetWindowRgn(window, region, TRUE); // the system owns the region 

The radius is percentage × shorterSide / 200, so at 100 a 160×90 window becomes a capsule, not
an ellipse. The part that is easy to miss is the hit test: the low-level mouse hook decides by
rectangle, so a press in the clipped corner would be swallowed and become a resize of a window nobody
can see. The hook has to use the same quarter-circle test:

bool inside = dx * dx + dy * dy <= radius * radius; 

SetWindowRgn also invalidates the whole window, so the host remembers the last radius and size and
only rebuilds the region when the answer changes. At 0 it does not call it at all.

3. The mouse hook is the window manager

The page never sees the scrollbar, and the engine consumes most mouse input. Resizing from any edge,
moving with Alt+drag and the corner gestures therefore run through a low-level mouse hook. Two
things I had to learn the hard way:

  • WindowFromPoint + GetAncestor(hit, GA_ROOT) is the z-order gate. Without it, an unpinned window that is covered by another app swallows a click meant for the app in front and resizes itself behind it. That is the “it shrinks by itself when I click outside it” bug.
  • The edge cursor cannot live in a class on <html>: every framework rewrites that attribute on each render, and the cursor disappears. It lives in a <style> element the page owns, rewritten in place.

4. Ctrl+click is a WebView2 event, with a real-gesture gate

WebView2 turns Ctrl+click into NewWindowRequested. The handler used to navigate the same window;
now it opens another tiny window at the same size, in the next free spot, with the same container and
corners, and none of the source window's keyed colours.

The gate: the low-level hook arms a one-shot flag only when the left button goes down with Ctrl
physically held. A page that calls window.open on its own finds the flag empty and keeps the old
behaviour. The page script also stops rewriting target="_blank" to _self when Ctrl is held;
otherwise the gesture becomes an ordinary navigation before the event can fire.

What did not work

Three things looked reasonable and did not survive contact with the engine:

  • Layered windows (WS_EX_LAYERED + UpdateLayeredWindow) cannot host WebView2 correctly: the window alpha does not reach the child HWND, so the page stays opaque.
  • DWM corner preference gives a pleasant fixed rounding, but no slider and no capsule. It is a Windows 11 look, not a shape control.
  • Clipping the page with CSS looks fine on a test page but is fragile with real ones: pages paint their own backgrounds, fixed elements escape the clip, and the transparent corners need composition anyway. A window region is less glamorous and more predictable.

The numbers

exe 688,640 bytes, statically linked C++20
window 160×90, minimum 60×60, 141×77 start bar
engine WebView2, already on Windows 10/11
install none; copy the exe, delete the exe
containers per window, WebView2 profiles in one data folder
snapshots .to, plain text, double-click to reopen
demo 46 s, 60 fps

What it is not

It is not a replacement for your browser. There are no tabs, it is Windows-only, and the exe is
unsigned, so SmartScreen warns on the first run. It needs the WebView2 runtime, which ships with Edge
and Windows 11; on a machine without it, the app offers to install it.

It is also not free of renderer memory: each window still has a WebView2 renderer. The win is the
host — no Electron runtime, no installer, no account, no telemetry — and the shape of the window.

Try it

If you try it, I would like to know what you keep in a 160×90 window — and what breaks on your setup.
Multi-monitor and 150% DPI are the two places I expect the most interesting bugs.

Disclosure: I used AI assistance for parts of the implementation and this write-up. The design
decisions, the testing and the app are mine.

原文:https://www.a8q9.cn/en/article/a-browser-in-688-kb-what-win32-and-webview2-can-still-do-57cebf.html

相关文章