Enable a domain, watch its events stream in — the request lifecycle and a console call, from a live trace.
In Lesson 1 you learned the three message
shapes and sent your first command. Every command's name had two parts —
Browser.getVersion, Page.navigate. That first part is a
Domain, and organizing the whole protocol. This lesson makes domains
concrete: you'll turn two of them on and watch real events pour out.
A Domain is a namespace of related commands and events — and each
domain's events are silent until you send its Domain.enable command.
Commands are pull; events are push you opt into.docs
CDP has dozens of domains, but a handful cover almost everything:docs
Page | Navigation, lifecycle events, screenshots, frames |
Runtime | Evaluate JS in the page; console API calls |
DOM | Read / query / modify the DOM tree by nodeId |
Network | Watch requests & responses; read response bodies |
Input | Synthesize keyboard / mouse / touch |
Target | Discover & attach to targets; sessions (Lesson 3) |
You met Runtime.evaluate in Lesson 1's exercise. But Runtime also
emits events — once enabled. Enable it, then run a console.log, and the
page's console call comes back to you as an event. This is the real exchange:
This is how a tool captures a page's console output: not by scraping a screen,
but by subscribing to Runtime.consoleAPICalled. Each argument arrives as a typed
RemoteObject — here a string and a number.
Now the domain that makes CDP a debugging superpower. Send Network.enable, then
navigate, and every request narrates itself through a fixed lifecycle. This is the real stream
for loading example.com, filtered to the main document:
requestId that ties them
Every request walks the same path: requestWillBeSent → responseReceived
→ dataReceived (0+ times) → loadingFinished.docs
All four carry the same requestId — that's how you correlate them across the many
requests interleaving on one page load.
Once you have a request's requestId, you can ask for its body — a command whose
result (not an event) carries the bytes. Real capture, main document:
Just like /json/list in Lesson 1, the event stream is cluttered: a real
capture also shows chrome-extension://… requests from bundled extensions, and
…ExtraInfo variants of the events. Filter by the url (and often by
type: Document, Script, XHR…) to find the
request you care about.
The driver script grew two verbs for this lesson. From the cdp/ directory:
In the net output, pick one request and trace it from >>
to <<. What was its status and MIME type? Bring me anything odd.
Network.* events at all. What was missing?getResponseBody need?The official Network domain reference and Runtime domain reference. Skim the event lists — you've now watched the core ones fire live, so the docs read as a map of a place you've already been, not a wall of names.