DEV Community

Cover image for How Chrome DevTools Works Under the Hood
Henry Lim
Henry Lim

Posted on Originally published at limhenry.substack.com

How Chrome DevTools Works Under the Hood

This article is based on my talk "Chrome DevTools LIVE LIVE LIVE", presented at DevFest events in Modena, Málaga, Venezia, Vicenza, Birmingham, Dublin, and more.


As web developers, we spend hours debugging web applications using Chrome DevTools every week. But we rarely think about what's under the hood of Chrome DevTools. Unlike the rest of the browser, which is built using C++, Chrome DevTools is actually built using the technologies that we are very familiar with: HTML, CSS, and TypeScript.

In this article, we will look at how Chrome DevTools is built, how it evolved from a simple debugging tool 18 years ago to today's full debugging suite, as well as the protocol that powers Chrome DevTools itself.

Chrome DevTools Frontend

The Chrome DevTools UI (devtools-frontend) is an open-source web application built with TypeScript, HTML, CSS, Lit, and Web Components.

Back in 2013, the DevTools team was using Google's Closure Compiler and JSDoc annotations for type checking. However, as TypeScript got more popular over time, they decided to migrate the entire DevTools codebase to TypeScript. This took them over 13 months, but the result is that the codebase of DevTools looks very familiar to any frontend developer.

To run DevTools locally, you can follow the Chrome DevTools contribution guide. Fortunately, back in 2019, they detached DevTools itself from the massive Chromium monorepo. This means building and running DevTools locally doesn't require a powerful machine to build the entire Chromium C++ codebase.

Inspecting DevTools with DevTools

We use Chrome DevTools to debug the web applications we build. But since Chrome DevTools is also another web application, how do Googlers or DevTools contributors debug Chrome DevTools? The answer is that they use DevTools to debug DevTools!

Here's how to do it:

  1. Open Chrome DevTools by pressing F12, Cmd + Option + I on Mac, or Ctrl + Shift + I on Windows and Linux.
  2. Click the "Customize and control DevTools" (⋮) menu in the top-right corner and select the "Undock into separate window" icon next to Dock side.
  3. Click inside the undocked DevTools window to focus it, then press Cmd + Option + I (Mac) or Ctrl + Shift + I (Windows and Linux) a second time.

With this, you can now debug DevTools using another DevTools window. You can use the Elements panel to look at how the complex UI panels in DevTools are structured, or maybe run a performance audit on DevTools to see how well-optimized it is.

Or just for fun, you can repeat the process infinitely. You can use DevTools to debug another DevTools window, and then open a third DevTools window to debug the DevTools that is debugging the first DevTools, just like the movie Inception.

Inspecting Chrome DevTools using a second Chrome DevTools window

18 Years of DevTools Layout

Before 2006, developers often needed to use some weird, hacky workarounds to debug their websites. Then in 2006, Firebug was launched for Firefox as the first-of-its-kind devtools.

In 2008, Google launched the first version of Google Chrome. It bundled WebKit's Web Inspector directly into the browser itself.

Screenshot of the original Chrome 1.0 Web Inspector at chrome-resource://inspector/inspector.html running on Windows XP in 2008

Take note of the URL bar at the top of the window: chrome-resource://inspector/inspector.html. Even in Chrome 1.0, DevTools was already an HTML page running inside the browser.

Since the launch of the first version of DevTools 18 years ago, Chrome has added many new features and panels to it. However, if you compare Chrome 1.0 from 2008 with Chrome today, the core layout is still very similar:

  • Top Tabs (Elements and Resources): Elements is still the first tab today, while Resources later evolved into the Network, Application, and Sources panels.
  • DOM Tree and Breadcrumbs: The left pane shows the HTML tree, with the html > body > div breadcrumb bar at the bottom.
  • Styles Sidebar: The right pane already had Styles, Computed Style, Metrics, and Properties.
  • Console Drawer Toggle: The bottom-left corner has the same toggle buttons for docking and opening the Console drawer (>_).

The Chrome team got the core layout right from the beginning. Since 2008, most updates have expanded on this original layout instead of replacing it.

Chrome DevTools Protocol (CDP)

The Chrome DevTools Protocol (CDP) is a JSON-based protocol that connects debug and automation targets (such as browsing contexts and workers) with trusted debug and automation clients. It allows tools to instrument, inspect, debug, and profile Chromium, Chrome, and other Blink-based browsers.

CDP is used by Chrome, Chrome DevTools (including Chrome DevTools for Agents and Chrome DevTools MCP), Lighthouse, Puppeteer, and ChromeDriver.

Protocol Monitor

You can view the CDP messages sent between the Chrome browser and DevTools with the Protocol Monitor panel. It is an experimental panel that lets you view every CDP request and response sent between DevTools and the browser, and even send raw CDP commands yourself.

To enable the Protocol Monitor, you need to turn it on in DevTools Settings:

  1. Open Chrome DevTools and click the Settings gear icon in the top-right corner.
  2. In the Experiments tab, check "Protocol Monitor" and reload DevTools.
  3. Click the "Customize and control DevTools" (⋮) menu and select "More tools" > "Protocol Monitor".

Screenshot of the Protocol Monitor panel in Chrome DevTools displaying a live table of CDP methods, requests, and JSON responses

Console Utilities API

When you evaluate expressions in the Console panel, DevTools uses CDP's Runtime.evaluate method with includeCommandLineAPI: true to inject the Console Utilities API, a collection of helper functions and shortcuts that dates all the way back to Firebug. Because CDP only injects these utilities when evaluating expressions from the Console, they are only available inside the Console panel and won't work inside your application's own JavaScript code.

For example, instead of typing document.querySelector() or document.querySelectorAll() in the Console panel, you can use $() or $$(). While these look just like jQuery, they actually originated in Firebug (inspired by Prototype.js) and were later adopted by WebKit's Web Inspector and Chrome DevTools.

Besides that, the Console Utilities API also provides shortcuts like $0 to $4. They return the last 5 DOM elements you selected in the Elements panel (or the last 5 heap objects selected in the Memory panel), where $0 is the currently selected element, $1 is the previous one, and so on.

Using $('img'), $$('img'), and $0 through $3 in the Chrome DevTools Console

Chrome DevTools Extensions

Chrome DevTools has over 30 panels, but it still can't cover every use case, especially when debugging web frameworks like React or Angular. With the chrome.devtools.* extension APIs, developers can create their own custom panels and sidebar panes in DevTools.

For example, React Developer Tools uses chrome.devtools.panels.create() to add the Components and Profiler tabs directly into DevTools. You can also build your own DevTools extension for your team to debug internal tools, feature flags, or state management.

Screenshot of Chrome DevTools showing the custom Components and Profiler tabs added by the React Developer Tools extension

However, DevTools is also making it easier for framework authors to visualize performance data without building a dedicated DevTools extension. In the past, to show a custom performance track, framework developers needed to use a DevTools extension to create a separate panel just to display their custom waterfall chart.

With the Performance extensibility API (built on console.timeStamp() and the User Timing API), they can now add custom tracks directly into the Performance panel without an extension API at all.

Screenshot of Chrome DevTools showing showing the custom performance tracks

Conclusion

It is always fun to understand what's under the hood of the tool we use every day. Since Chrome DevTools is built with the same HTML, CSS, and TypeScript we already know, the next time you find a bug in DevTools, you know you actually have the superpower to fix it and benefit millions of web developers around the world.

Top comments (0)