sodcalculator

10 Tech How-To

Chrome DevTools Debugger: Step-by-Step Guide

Guide 10-44650 · Updated · Step by step

This guide shows you how to use the Chrome DevTools debugger to pause, inspect, and step through your JavaScript code. You’ll learn to set breakpoints, watch variables, and trace the exact flow of your program, making it far easier to find and fix bugs. All you need is a web page with JavaScript and Chrome.

What You’ll Need

  • Google Chrome (current version)
  • A web page or local HTML file with JavaScript you want to debug
  • Chrome DevTools opened (right-click > Inspect, or press F12 / Ctrl+Shift+I on Windows/Linux, Cmd+Option+I on Mac)

Step-by-Step

  1. Open the Sources panel. In DevTools, click the Sources tab in the top navigation bar. If you don’t see it, click the » (more tabs) icon to reveal it.
  2. Navigate to your script. In the left sidebar of the Sources panel, you’ll see a file tree. Click on the HTML file that contains your script, or expand the js folder and click on your JavaScript file. The file’s code appears in the central pane.
  3. Set a breakpoint. Click on the line number where you want the code to pause. A blue arrow or dot appears, indicating a breakpoint. You can set multiple breakpoints. To remove one, click the line number again.
  4. Trigger the code. Interact with your page to execute the code that contains the breakpoint. For example, click a button, submit a form, or reload the page if the code runs on load. When the execution reaches the breakpoint, the debugger pauses, and the line is highlighted.
  5. Use the action buttons. At the top right of the Sources panel, you’ll see a toolbar with these buttons (hover to see tooltips):
    • Resume (F8 / ▶): Continue execution until the next breakpoint or until the script finishes.
    • Step over (F10 / ↷): Execute the current line and move to the next line. If the current line calls a function, it runs that function without stepping into it.
    • Step into (F11 / ↷↷): If the current line calls a function, this jumps into that function’s first line. If not, it behaves like Step over.
    • Step out (Shift+F11 / ↶): Run the rest of the current function and pause at the line after the function call.
  6. Inspect variables. While paused, hover over any variable in the code to see its current value. In the right sidebar, the Scope section shows all local, closure, and global variables. The Watch section (click the + to add) lets you type an expression (e.g., user.name) and see its value update as you step.
  7. Check the call stack. In the right sidebar, the Call Stack section shows the chain of function calls that led to the current line. Click any entry to jump to that call site.
  8. Use conditional breakpoints. Right-click a line number and select Add conditional breakpoint. Type an expression (e.g., count === 5). The debugger only pauses when that expression is true.
  9. Log points. Right-click a line number and choose Add logpoint. Type an expression in curly braces, like {count}. Instead of pausing, the debugger logs the value to the Console. This is handy when you don’t want to stop execution.
  10. Edit code live. While paused, you can click directly on a value in the Scope and type a new one. You can also edit the code in the central pane; press Ctrl+S (Cmd+S on Mac) to save, then reload the page to apply changes.

Common Mistakes

  • Setting a breakpoint in the wrong file – Make sure you’re editing the file that actually runs. If you’re using a build tool, you might be looking at the source map, not the compiled file.
  • Forgetting to trigger the code – Many breakpoints never fire because the user hasn’t interacted with the page. Double-check that the event (like a click) actually runs the function.
  • Clicking the line number vs. the code – Clicking the gutter (the line number column) sets a breakpoint; clicking the code itself just places the cursor.
  • Using Step Over when you need Step Into – If you want to see inside a function, use Step Into. Step Over will skip it.
  • Not using conditional breakpoints in loops – If you set a breakpoint inside a loop that runs 1000 times, you’ll be pressing Resume 1000 times. Use a conditional breakpoint like i === 999.

Tips

  • Use the Console while paused. You can type any JavaScript expression in the Console and it will evaluate in the current paused context. This is great for testing changes without editing the code.
  • Press Ctrl+Shift+F (Cmd+Option+F on Mac) in the Sources panel to search across all files for a function or variable name.
  • Use the Event Listener Breakpoints in the right sidebar to automatically pause when a specific event (like a click or keypress) occurs, without setting a manual breakpoint.
  • Save a snippet for frequently used debug code. In the Sources panel, click the Snippets tab, create a new snippet, and run it anytime.
  • Disable all breakpoints temporarily by clicking the icon that looks like a stop sign with a slash (or pressing Ctrl+F8) when you want to run freely.

Troubleshooting

  • Breakpoint not hit – Check that the file you’re viewing is the one being executed. If you’re using a bundler, you may need to enable source maps (in DevTools Settings > Sources > Enable JavaScript source maps). Also, ensure the code isn’t minified; if it is, use the Pretty-print button ({} icon) to format it.
  • Variables show as undefined – This usually means the variable is out of scope at the current line. Step back to a line where the variable is defined, or check the Scope panel for the correct context.
  • Debugger pauses on a line that isn’t mine – This can happen if you have a breakpoint in a library or framework file. Use the Call Stack to navigate back to your own code, or remove breakpoints from third-party scripts.
  • Changes to code don’t take effect – After editing in the Sources panel, you must save (Ctrl+S) and then reload the page. If you’re using a server, make sure the file is saved on disk as well.
  • Performance is slow while debugging – Disable any breakpoints you don’t need, and avoid logging large objects to the console. Use conditional breakpoints to reduce pauses.

Frequently Asked Questions

How do I start the debugger?

Open DevTools, go to the Sources panel, set a breakpoint in your JavaScript file, and then trigger the code that contains that line. The debugger will pause automatically.

What’s the difference between Step Over and Step Into?

Step Over runs the current line and moves to the next, executing any function calls as a single step. Step Into jumps into the function being called, allowing you to inspect its internals.

Can I debug code that runs on page load?

Yes. Set a breakpoint in the script that runs on load, then reload the page. The debugger will pause at that breakpoint.

How do I watch a variable’s value change?

Add the variable to the Watch panel by clicking the + icon and typing its name. As you step through the code, the value updates in real time.

What is a logpoint and how is it different from a breakpoint?

A logpoint logs a message to the Console without pausing. It’s useful for quickly checking values without interrupting the flow of your program.

Can I debug code in a framework like React or Vue?

Yes, as long as source maps are enabled. You’ll see the original component code, and you can set breakpoints just like in plain JavaScript.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →