Chrome Debugging Protocol

Under the hood, Chrome Developer Tools is a web application written in HTML, JavaScript and CSS. It has a special binding available at JavaScript runtime that allows interacting with chrome pages and instrumenting them. The interaction protocol consists of commands that are sent to the page, and events that the page is generating. Although Chrome Developer Tools is the primary client of this protocol, including for remote debugging, there are ways for third parties to use it and start instrumenting browser pages explicitly.

Interaction protocol consists of JSON commands that are sent to the page and events that the page is generating. We define this protocol in Blink so that any Blink-based browser can support it.

Latest Protocol

The tip-of-tree protocol captures the full capabilities of the Protocol, whereas the stable release is a subset. There is no backwards compatibility support guaranteed for the capabilities it introduces. You can use it with Chrome Canary builds or tip of tree Chromium. See the Sniffing the protocol section below to identify the protocol commands used by Chrome.

The tip-of-tree protocol changes frequently. If you need the protocol version for a specific Chrome client, this snippet will provide the protocol JSON based on the client's /json/version.

Debugging Protocol Viewer

The Chrome debugger protocol viewer offers a more readable view of the tip-of-tree protocol.

Frozen 1.1 Protocol

Debugger protocol version 1.1 is the latest stable release of the protocol, tagged at Chrome 31.

Debugging over the wire

The Developer Tools front-end can attach to a remotely running Chrome instance for debugging. For this scenario to work, you should start your host Chrome instance with the remote-debugging-port command line switch:

    chrome.exe --remote-debugging-port=9222

Then you can start a separate client Chrome instance, using a distinct user profile:

    chrome.exe --user-data-dir=<some directory>

Now you can navigate to the given port from your client and attach to any of the discovered tabs for debugging: http://localhost:9222

You will find the Developer Tools interface identical to the embedded one and here is why:

  • When you navigate your client browser to the remote's Chrome port, Developer Tools front-end is being served from the host Chrome as a Web Application from the Web Server.
  • It fetches HTML, JavaScript and CSS files over HTTP
  • Once loaded, Developer Tools establishes a Web Socket connection to its host and starts exchanging JSON messages with it.

In this scenario, you can substitute Developer Tools front-end with your own implementation. Instead of navigating to the HTML page at http://localhost:9222, your application can discover available pages by requesting: http://localhost:9222/json and getting a JSON object with information about inspectable pages along with the WebSocket addresses that you could use in order to start instrumenting them.

Remote debugging is especially useful when debugging remote instances of the browser or attaching to the embedded devices. Blink port owners are responsible for exposing debugging connections to the external users.

Sniffing the protocol

You can inspect how the Chrome DevTools uses the protocol. This is especially handy when looking up newer features. First, run Chrome with the debugging port open:

/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --remote-debugging-port=9222 http://localhost:9222 http://chromium.org
Then, select the Chromium Projects item in the Inspectable Pages list. Now that DevTools is up and fullscreen, open DevTools to inspect it. Cmd-R in the new inspector to make the first restart. Now head to Network Panel, filter by Websocket, select the connection and click the Frames tab. Now you can easily see the frames of WebSocket activity as you use the first instance of the DevTools.

Sniffing the debugger protocol
Screenshot of sniffing the DevTools protocol with DevTools

Debugging Protocol Clients

Many applications and libraries already use the protocol. Some to collect performance data, others to breakpoint debug from another editor. There are libraries to access the raw protocol from Node.js and Python.

Many of these clients are showcased here: Showcased Debugging Protocol Clients.

Using debugger extension API

To allow third parties to interact with the protocol, we introduced chrome.debugger extension API that exposes this JSON message transport interface. As a result, you can not only attach to the remotely running Chrome instance, but also instrument it from its own extension.

Chrome Debugger Extension API provides a higher level API where command domain, name and body are provided explicitly in the sendCommand call. This API hides request ids and handles binding of the request with its response, hence allowing sendCommand to report result in the callback function call. One can also use this API in combination with the other Extension APIs.

If you are developing a Web-based IDE, you should implement an extension that exposes debugging capabilities to your page and your IDE will be able to open pages with the target application, set breakpoints there, evaluate expressions in console, live edit JavaScript and CSS, display live DOM, network interaction and any other aspect that Developer Tools is instrumenting today.

Opening embedded Developer Tools will terminate the remote connection and thus detach the extension.

Simultaneous protocol clients

We currently do not support multiple clients connected to the protocol simultaneously. This includes opening DevTools while another client is connected. On the bug tracker, crbug.com/129539 follows the issue; you can star it for email updates.

Upon disconnnection, the outgoing client will receive a detached event. For example: {"method":"Inspector.detached","params":{"reason":"replaced_with_devtools"}}. View the enum of possible reasons. (For reference: the original patch). After disconnection, some apps have chosen to pause their state and offer a reconnect button.