Chromium WebUI: Polymer and Lit in Browser Management
This article provides a comprehensive look into Chromium's WebUI architecture, explaining how the browser uses standard web technologies to build its internal management screens. You will learn what WebUI pages are, how they communicate with the browser's core system, and how Google's Polymer and Lit frameworks are used to construct and maintain complex interfaces like the settings, history, and downloads pages.
What are WebUI Pages?
WebUI is a term used in the Chromium project to describe parts of the browser's user interface implemented using web technologies—specifically HTML, CSS, and TypeScript/JavaScript—rather than native operating system UI toolkits.
When you navigate to URLs that begin with the chrome://
scheme (such as chrome://settings,
chrome://bookmarks, or chrome://history), you
are viewing a WebUI page.
Using web technologies for these screens offers several advantages:
- Cross-Platform Consistency: The interfaces look and behave identically across Windows, macOS, Linux, and ChromeOS without needing platform-specific code.
- Rapid Development: Developers can iterate on UI designs quickly using standard web development workflows.
- Resource Sharing: The browser already contains a powerful rendering engine (Blink), so using it to render its own UI avoids adding the bloat of an external UI library.
Unlike standard web pages, WebUI pages run with elevated privileges.
They communicate directly with the browser’s C++ backend using
Chromium's Inter-Process Communication (IPC) system, known as Mojo, or
through a legacy messaging system called chrome.send. This
allows a webpage button click to change system-level browser behaviors,
such as clearing the cache or managing passwords.
The Need for Web Frameworks in Chromium
In the early days of Chromium, WebUI pages were built using vanilla JavaScript. As the browser grew more feature-rich, pages like Settings became massive single-page applications. Managing the Document Object Model (DOM), keeping UI state synchronized with the C++ backend, and maintaining accessibility standards became difficult without a structured framework.
To solve this, the Chromium team turned to Web Components—a suite of native browser APIs that allow developers to create reusable, encapsulated custom HTML elements. To make writing Web Components easier and more efficient, Chromium adopted specific libraries built on top of these standards: first Polymer, and more recently, Lit.
Polymer's Legacy in WebUI
For many years, the Polymer library was the backbone of Chromium’s user interface. Developed by Google, Polymer allowed Chromium engineers to build complex management screens using a declarative syntax.
Polymer powered internal screens through a few core mechanisms:
- Custom Elements: Chromium created a vast library of
shared UI elements (such as
cr-button,cr-toggle, andcr-input) using Polymer. This ensured that every internal page adhered to Google's Material Design guidelines. - Shadow DOM: Polymer heavily utilized the Shadow DOM to encapsulate styles. This meant the CSS for a specific toggle switch wouldn't accidentally break the layout of the larger Settings page.
- Two-Way Data Binding: Polymer allowed automatic synchronization of data between the JavaScript state and the HTML view. If a user changed a setting in the UI, the underlying data model updated automatically, and vice versa.
While Polymer successfully modernized Chromium's UI, it eventually presented performance bottlenecks. Its two-way data binding system made it difficult to track how data flowed through complex pages, leading to unexpected bugs. Additionally, Polymer relied on non-standard conventions that required heavy build-time processing.
The Transition to Lit
As the broader web ecosystem evolved, the Google team behind Polymer deprecated the library in favor of a newer, lighter framework called Lit. Consequently, the Chromium team began a massive initiative to migrate WebUI pages from Polymer to Lit.
Lit powers modern Chromium screens by focusing on simplicity, speed, and standard JavaScript/TypeScript practices:
- Lightweight Footprint: Lit is significantly smaller than Polymer, which reduces the memory overhead and startup time of internal browser pages.
- Declarative Templates: Instead of relying on complex HTML parsing, Lit uses native JavaScript Tagged Template Literals to define how the UI should look.
- One-Way Data Flow: Lit abandons Polymer's two-way
data binding for a strict one-way data flow. Properties flow down into
components, and events flow up. This makes the state of complex screens
like
chrome://extensionsmuch easier to predict and debug. - Targeted Updates: Lit remembers where dynamic data is placed in the UI and updates only those specific DOM nodes when data changes, resulting in faster rendering.
How a WebUI Screen Operates in Practice
Whether powered by legacy Polymer code or modern Lit components, the lifecycle of an internal management screen follows a strict architectural pattern:
- Initialization: The user navigates to
chrome://downloads. The C++ backend bundles the necessary HTML, CSS, and compiled TypeScript files and serves them to the renderer process. - Component Rendering: Lit or Polymer initializes the custom elements on the page, rendering the visual layout inside encapsulated Shadow DOM trees.
- Fetching Data: A TypeScript class known as a
BrowserProxyrequests the current list of downloads from the C++ backend via Mojo IPC. - Displaying State: The C++ backend returns the data. The framework (Lit/Polymer) takes this data array and dynamically generates the visual cards for each downloaded file.
- User Interaction: The user clicks "Remove" on a
file. The UI component fires an event that the
BrowserProxycatches and forwards to the C++ backend. The backend deletes the record and tells the UI to re-render the updated list.
By pairing the native security and performance of C++ with the flexible, component-driven architecture of Polymer and Lit, Chromium successfully manages to use its own web engine to power its most critical management interfaces.