Browser DevTools and Debugging
Find and fix front-end problems quickly: the Elements, Console, Sources, Network, Application and Performance panels, inspecting and editing CSS live, breakpoints, reading errors and the network waterfall, device emulation, and a method for debugging.
1. Your best tool is already installed
Every modern browser ships with developer tools: a toolbox for inspecting the page, running JavaScript, watching the network and measuring performance. Open them with F12, Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (macOS), or right-click anything and choose Inspect. This lesson uses Chrome’s names. Firefox, Edge and Safari have close equivalents.
Professional front-end developers spend a large part of their day here. Being fast in DevTools is one of the clearest differences between beginners and experienced developers.
2. Elements: see and edit the live page
The Elements panel shows the DOM as it is right now (not your original HTML): every element your JavaScript created or changed.
- Click the select tool (arrow icon) and click anything on the page to find its element.
- The Styles pane lists every CSS rule that applies, from most to least specific, with overridden rules struck through. Toggle a declaration with its checkbox, or edit values live (arrow keys nudge numbers).
- The Computed tab shows the final value of every property, and the box model diagram shows content, padding, border and margin with real sizes. It is the fastest way to understand a spacing or overflow bug.
- Right-click an element and Force state (
:hover,:focus) to style states you cannot hold with a mouse. - The Accessibility tab shows the element’s accessible name, role and contrast.
- Edit text or attributes by double-clicking. Nothing you do here is saved to your files: copy what worked back into your code.
Common finds: a rule overridden by a more specific selector, display: none on the parent, box-sizing surprises, a wrong class name, an element that is much wider than the viewport.
3. Console: messages, errors and experiments
The Console shows errors, warnings and anything you log, and lets you run JavaScript in the page.
console.log('user', user); // print values
console.table(students); // an array of objects as a table
console.error('bad', err); // red, with a stack trace
console.group('load'); /* ... */ console.groupEnd();
console.time('render'); render(); console.timeEnd('render'); // measure
$0 // the element currently selected in Elements
$$('li').length // like querySelectorAll
Read errors properly. Uncaught TypeError: Cannot read properties of undefined (reading 'name') means you tried x.name while x was undefined. The file and line link jumps to the code, and the stack trace shows the chain of calls that led there. Start with the first error, because later ones are often consequences.
Typical messages and meanings:
| Message | Usually means |
|---|---|
x is not defined |
A typo, or the variable is out of scope or loaded later |
x is not a function |
Calling something that is not a function (wrong import, undefined method) |
Cannot read properties of null |
querySelector found nothing (wrong selector, or the script ran before the element existed) |
Unexpected token < |
A request expected JSON or JavaScript but got an HTML page (often a 404 or an error page) |
Failed to load resource: 404 |
A wrong URL |
blocked by CORS policy |
The other server did not allow your origin |
Refused to execute inline script |
A Content Security Policy blocked it |
4. Sources: breakpoints and stepping
console.log shows what you thought to print. A breakpoint pauses the program so you can see everything.
- Open Sources, find your file, and click a line number to set a breakpoint (or write
debugger;in your code). - Trigger the code. Execution stops on that line.
- Look at Scope (all variables right now), Call Stack (how you got here) and Watch (expressions you track).
- Step over (F10) runs the line, Step into (F11) enters a function call, Step out (Shift+F11) leaves it, Resume (F8) continues.
- Conditional breakpoints (right-click the line number) pause only when an expression is true, such as
user.id === 42in a loop. Event listener breakpoints pause on any click or key press. Pause on exceptions stops exactly where an error is thrown.
Use source maps so that bundled and minified production code appears as your original files.
5. Network: what really went over the wire
The Network panel lists every request the page makes. Reload with it open.
- Each row shows status, type, size and time. Click one for its Headers (request and response), Payload, Preview/Response and Timing.
- Status codes tell the story:
200fine,301/302redirect,304served from cache,401/403auth problem,404wrong URL,500server bug. A failed (red) request with no status means the network, CORS or an ad blocker stopped it. - The waterfall shows when each request started and finished. Long bars are slow; many requests queued one after another show dependencies you could parallelise.
- Filter by Fetch/XHR to see your API calls, and check the request payload and the response to separate front-end bugs (you sent the wrong thing) from back-end bugs (the server returned the wrong thing).
- Throttling (Fast 4G, Slow 4G, Offline) shows what real users on poor connections experience. Tick Disable cache while debugging caching issues.
- Right-click a request, Copy as cURL, to reproduce it in a terminal.
6. Application: storage, cookies and service workers
The Application panel shows what the browser stores for the site: cookies (and their HttpOnly, Secure and SameSite flags), localStorage and sessionStorage, IndexedDB, the cache, and service workers. Use it to check what you saved, delete stale data that causes odd bugs (“clear site data”), and verify that sensitive values are not stored where scripts can read them.
7. Performance, Lighthouse and device emulation
- Device toolbar (Ctrl+Shift+M): emulate phone and tablet sizes, pixel density, touch and network speed. Drag the width to find where a layout breaks. (A real device remains the final test.)
- Lighthouse audits a page for performance, accessibility, best practices and SEO, with a prioritised list of fixes.
- Performance records a timeline: what the main thread was doing, long tasks that block the page, layout and paint costs. Use it when something feels janky.
- Rendering options (such as paint flashing,
prefers-reduced-motionand colour-scheme emulation) help with animation and theming.
8. A debugging method
- Reproduce it. Find the smallest steps that always trigger the bug. Until you can, you cannot know you fixed it.
- Read the error in the Console, from the first one, and follow the file and line.
- Check your assumptions. Is the element present? Is the variable what you think? Is the request returning what you expect? Inspect, log or break to find out.
- Split the problem in half. Is it HTML, CSS or JavaScript? Front end or back end? Before or after this function? Comment out or bisect until the cause is isolated.
- Change one thing at a time and predict the result before you run it.
- Fix the cause, not the symptom, then recheck in the original scenario, and in other browsers if the bug might be browser-specific.
- Keep a note of the cause. If it can recur, add a test.
When you are stuck, explain the problem out loud (the “rubber duck” method), take a break, or search for the exact error text. Do not paste secrets or private code into public forums.
9. Habits that save hours
- Keep DevTools open while you build, not only when something breaks.
- Use breakpoints instead of dozens of
console.logcalls, and delete leftover logs. - Check the Network panel for every API bug before touching code.
- Test on a narrow viewport and with the keyboard as you go.
- Learn the shortcuts: Ctrl/Cmd+P (open a file), Ctrl/Cmd+Shift+P (run any command), Esc (toggle the console drawer).
10. What you learned
You can inspect and experiment with the live DOM and CSS, read console errors, pause code with breakpoints, understand requests in the Network panel, check storage, and test different devices and connections. Most important, you have a repeatable method for debugging instead of guessing. Next you will learn how to keep your pages safe from attacks that run in the browser.
🧪 Want to practise this on your own computer? See how to set up your lab →