Sub topic 1
Opening DevTools and finding your way around
Prerequisites
This chapter assumes you know basic HTML and CSS, and basic JavaScript syntax. You should also know roughly how a browser loads a page: it requests a document over HTTP, parses it into a tree, fetches linked resources, and renders the result. Panel names follow Chromium-based browsers such as Chrome and Edge. Firefox and Safari offer equivalent tools under similar names.
What DevTools is
Browser DevTools is a set of inspection tools built into the browser. It shows what the browser actually holds in memory for the current page: the live DOM, the computed styles, the scripts it loaded, the requests it made, and the data it stored. It does not show your source files as you wrote them. This difference explains many surprises, such as a page whose DOM no longer matches the HTML you served.
Use DevTools whenever you ask "why does this page look or behave this way?" Pick the panel that matches the kind of problem.
Opening DevTools
You have several ways to open it. They all give the same result.
| Method | Windows / Linux | macOS |
|---|---|---|
| Open DevTools | F12 or Ctrl+Shift+I | Cmd+Option+I |
| Open the Console directly | Ctrl+Shift+J | Cmd+Option+J |
| Inspect an element | Right-click, then Inspect | Right-click, then Inspect |
| Command Menu | Ctrl+Shift+P | Cmd+Shift+P |
Right-clicking an element and choosing Inspect is often the fastest route. It opens the Elements panel with that element already selected.
DevTools can dock to the right, bottom, or left of the page, or open in a separate window. Use the three-dot menu in the DevTools toolbar to change this. A bottom dock suits wide layouts, and a side dock suits checking narrow viewports.
Finding your way around
The main panels sit in a tab bar along the top of DevTools. Each one answers a different question.
| Panel | What it answers |
|---|---|
| Elements | What is the DOM now, and which CSS rules apply to a node? |
| Console | What did the page log, and what does this expression evaluate to? |
| Sources | Which scripts loaded, and where can I pause execution? |
| Network | Which requests were made, how long did they take, and what came back? |
| Performance | Where does the time go while the page runs? |
| Memory | What objects are being kept in memory? |
| Application | What is stored in cookies, storage, and service workers? |
| Lighthouse | How does the page score on performance and quality checks? |
If a panel is missing from the tab bar, it may be hidden behind the >> overflow button. You can also open it from the Command Menu.
The Command Menu
Press Ctrl+Shift+P (Cmd+Shift+P on macOS) to open the Command Menu. Type part of a name to run a command or open a panel. For example, typing "screenshot" lists screenshot commands, and typing "sources" switches to that panel. When you forget where a feature lives, search here first.
The Drawer
Press Esc to show or hide the Drawer, a secondary area at the bottom of DevTools. It can hold the Console while you work in another panel. That lets you edit an element in the Elements panel and test an expression at the same time.
How the panels relate
The panels form a rough diagnostic path. You usually start by looking at the page structure or the logs. From there you move toward the panel that fits the symptom.
Treat this as a starting point. Real problems cross panels. A blank widget might be a failed request (Network), caused by a missing cookie (Application), which leads to a script exception (Console).
A first walkthrough
Try this on any page.
- Right-click a heading and choose Inspect. The Elements panel opens with that node highlighted.
- Press Esc to open the Drawer, then switch it to the Console.
- Type
$0and press Enter. This is a Console shortcut that refers to the element selected in the Elements panel. - Reload the page with the Network panel open, and watch the request list fill in.
// Run in the Console after inspecting an element.
$0.textContent; // read the selected element's text
$0.textContent = 'Hi'; // change it on the live pageThe change appears on screen, but it lives only in the browser's memory. Reloading the page discards it. DevTools edits do not touch your source files.
Common errors
- Looking for missing requests. The Network panel was closed during load. Open it and reload.
- Expecting edits to persist. Live edits vanish on reload. Copy the change into your source code.
- Trusting View Source for the current DOM. View Source shows the original HTML. The Elements panel shows the DOM after scripts have run.
- Debugging a cached page. Stale caches can hide your latest code. The Network panel has a "Disable cache" option that applies while DevTools is open.
Exercise
You open DevTools on a page that has already finished loading, then switch to the Network panel. The list is empty, although the page clearly fetched data. What do you do, and why?
Show answer
Reload the page while the Network panel is open. The panel records requests only while DevTools is open, so requests made before you opened it were not captured.
Exercise
You want to run a Console expression against an element while you keep the Elements panel in view. Which feature lets you do this, and how do you open it?
Show answer
The Drawer. Press Esc to show it, then choose the Console in it. You can then evaluate expressions such as $0 while the Elements panel stays visible.