Chrome DevTools: Network — Debugging

The Network panel in DevTools records every request a page makes while DevTools is open. So open it first, then repeat the action you want to check, or press…

The user list on your page takes more than a second to appear. Is the server slow, or your internet? Or did the request fail without any message? The Network panel in DevTools answers questions like these.

Network records every request a page makes: its HTML file, CSS, JavaScript, images, and even API calls through fetch. Each request is one row, with its status, type, size and duration. You can click a row to see what's inside. Network is like the order history in a food delivery app. One order is one request. Tap one order and you see three things: what you ordered (what the browser sent), what came (the server's answer), and where the time went. The time can go in the restaurant's kitchen (the server working) or on the road (the network).

Recording requests

Network only records while DevTools is open. So open the Network panel first, then do the action you want to check. To see everything the page loads from the start, press Ctrl+R (Mac: Cmd+R) while Network is open. The page reloads, and all its requests are recorded. The Network toolbar has two checkboxes you'll use a lot:

Reading the request table

The user list page at http://localhost:3000 makes five requests:

Name Status Type Size Time
index.html 200 document 5.2 kB 98 ms
logo.png 200 png 15.3 kB 40 ms
missing.png 404 png 300 B 22 ms
users 200 fetch 620 B 125 ms
auth 401 fetch 310 B 43 ms

Status codes: the server's answer in three digits

In code, a fetch that fails because the server is down and a fetch that fails because of CORS both throw the same TypeError: Failed to fetch. So the Network panel is what tells you the cause.

The details of one request

Click a row and its detail pane opens with several tabs:

Why is auth 401? Open its Headers tab: there's no Authorization: Bearer ... in the Request Headers. This means the code forgot to send the token. The Response tab shows the server's answer: {"message":"Unauthenticated."}. Once the header is added, the status becomes 200.

Timing: where the time goes

The Timing tab splits one request's time into several phases:

Phase What it is If it's long, suspect
Queueing, Stalled waiting for a turn in the browser too many requests at once
DNS Lookup finding the IP for the domain name slow DNS
Initial connection opening the connection (SSL included for https) a far-away server
Request sent sending the request a big upload
Waiting for server response waiting for the first byte of the answer (TTFB) the server: a slow database query, a cold start (a server that has just started), heavy processing
Content Download downloading the answer a big answer or a slow connection

A normal users request: Waiting is 120 ms out of 125 ms in total. If Waiting becomes 1,200 ms while the other phases stay fast, the server needs a long time to think. The problem is the server, not your connection. Faster internet won't help. What has to be fixed is the backend code (the code that runs on the server) or its query. In the opposite case, if Content Download is the long one, make the answer smaller, for example with compression or pagination (splitting the data into pages).

Other tools in the toolbar

⚠️ Misreading the Network panel

TL;DR: The Network panel in DevTools records every request a page makes while DevTools is open. So open it first, then repeat the action you want to check, or press Ctrl+R to reload the page. Each row has a Name, Status, Type, Size and Time. Failed requests are red, and the Fetch/XHR filter leaves only the API calls. Status codes (the server's number for its answer): 2xx success, 3xx a redirect or the cache (304 Not Modified: use the cached copy, the answer has no body), 4xx something wrong with the request (401: no login token), 5xx something wrong on the server. Click a request to see the Headers tab (the extra information sent and received), Payload (the data sent), Preview and Response (the answer's body), and Timing (the time per phase). If the Waiting for server response phase (TTFB: the time until the first byte of the answer arrives) is long while the other phases are fast, the server is slow.

⚡ Open Network first, then act

Meaning: The Network panel in DevTools records every request a page makes, but only while DevTools is open. Open the panel first, then repeat the action you want to check, or press Ctrl+R to reload the page. For API calls, pick the Fetch/XHR filter.

⚡ The server's answer in three digits

Guess first: each request has a status code, a three-digit number from the server. Is 304 Not Modified an error?

No. It means the file hasn't changed, so the browser uses the copy in its cache (the copies it keeps). Failure starts at 400.

Meaning: 2xx success, 3xx a redirect or the cache, 4xx something wrong with the request (401: no login token), 5xx something wrong on the server.

⚡ Click the request

Meaning: In the Network panel, click a request's row to see its details. The Headers tab holds the extra information the browser sent and the server sent back. Preview and Response hold the answer's body. For example, a request to auth got a 401 (not logged in). Its Request Headers have no Authorization: Bearer ...: the code forgot to send the login token.

⚡ A long Waiting means the server

Guess first: the Timing tab splits one request's time into phases. The Waiting for server response phase (waiting for the server's answer) is 1,200 ms, the other phases are fast. Is your internet slow?

No. The server needs a long time to think, a slow database query for example. Faster internet won't help.

Meaning: Look at which phase is long in the Timing tab, and you know what to fix.

What you will learn