Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 36 Β· Console and Sources

The Sources Panel and Breakpoints

Navigate the Sources panel, set line, conditional, logpoint, DOM, XHR and event breakpoints, and pause on exceptions, with a runnable conditional-breakpoint stand-in.

console.log tells you what happened. A breakpoint lets you stop the program at a chosen moment and examine everything: the values of variables, the chain of function calls that led there, and what the next line will do. This is the core of real debugging, and the Sources panel is where it happens.

The layout of Sources

The panel has three areas:

  • Left sidebar: tabs for Page (files grouped by origin, as loaded), Workspace (local folders you connect), Overrides, Snippets, and Content scripts. Press Ctrl+P to open a file by name.
  • Center: the editor, showing the selected file. Minified files can be shown pretty-printed with the { } button at the bottom-left.
  • Right (debugger) sidebar: controls and panes: Watch, Breakpoints, Scope, Call Stack, XHR/fetch Breakpoints, DOM Breakpoints, Global Listeners, Event Listener Breakpoints, and CSP Violation Breakpoints.

You can reach the same file in other ways: click a file link from the Console, a stack frame, or a CSS rule in Styles. Source maps (a later lesson) let you open your original TypeScript or unminified code instead of the bundle.

Line breakpoints

Open a file and click the line number in the gutter: a blue marker appears. When that line is about to run, the page pauses, the line is highlighted, and the debugger sidebar fills with information. Click the marker again to remove it. Right-click it to edit it, disable it or delete it. Use the Breakpoints pane to see all of them, toggle with checkboxes and jump to each.

If the line never runs, the page never pauses. That is itself useful information: it means your assumption about the code path was wrong.

You can also write debugger; in your source code. When DevTools is open, execution pauses at that statement. Remember to remove it, as it will pause for any visitor who has DevTools open.

Conditional breakpoints and logpoints

Right-click the gutter and choose Add conditional breakpoint… or Add logpoint….

  • A conditional breakpoint pauses only when a JavaScript expression you type is true: user.id === 7 or items.length > 100. It is how you stop in the 500th iteration of a loop, not the first.
  • A logpoint prints a message to the Console and does not pause. The message is an expression list: "total", total, "items", items.length. It acts like adding a console.log, without editing the file or reloading.

Both turn orange or pink in the gutter. Prefer them to editing code when you need quick evidence from deep inside a loop.

JS Stand-in: conditional breakpoints and logpoints

Press Run (or Ctrl + Enter) to see the console output here.

No output.

In real DevTools the pause freezes the page and shows the Scope pane with order and i. The stand-in records the same decision points so you can see how many pauses the condition would trigger.

Other breakpoint types

The debugger sidebar offers breakpoints that are not tied to a line:

  • DOM breakpoints (set from the Elements panel): pause on subtree modifications, attribute modifications or node removal.
  • XHR/fetch breakpoints: pause when a request URL contains a string you provide. Leave the string empty to pause on every request. Execution stops at the line that called fetch or XMLHttpRequest.send, with the full call stack.
  • Event listener breakpoints: tick an event type (for example Mouse, click, Keyboard, keydown, Timer, setTimeout, Animation, requestAnimationFrame) and the page pauses where a handler for it is about to run. Handy for "which code runs when I click this?".
  • Pause on exceptions (the octagon icon at the top of the right sidebar): pause when an exception is thrown. Choose Pause on uncaught exceptions and optionally tick Pause on caught exceptions. Pausing on caught exceptions finds errors that your code swallows with an empty catch.
  • CSP violation breakpoints pause when content security policy blocks something.

When a bug has no clear location, use an Event listener breakpoint or an XHR breakpoint to find where to start, then add a regular line breakpoint inside the code you land in.

Choosing a breakpoint type

flowchart TD
  A["What do you know?"] --> B{"The exact line"}
  A --> C{"A condition inside a loop"}
  A --> D{"Only a symptom"}
  B --> B1["Line breakpoint"]
  C --> C1["Conditional breakpoint or logpoint"]
  D --> D1{"What changes?"}
  D1 --> D2["A DOM node: DOM breakpoint"]
  D1 --> D3["A request: XHR/fetch breakpoint"]
  D1 --> D4["After a click: Event breakpoint"]
  D1 --> D5["An error: Pause on exceptions"]

Match the breakpoint to what you already know about the bug.

When the page is paused

Everything is frozen. In the right sidebar:

  • Scope lists local, closure and global variables with their values. Hover a variable in the editor to see a tooltip, or edit a value (double-click it) to test a fix.
  • Watch lets you add expressions that are re-evaluated at each step, such as cart.items.length.
  • Call Stack shows how execution got here, the topmost frame first.
  • The Console still works and runs in the paused frame's scope: type a variable name to read it.

Controls at the top: Resume (F8), Step over (F10), Step into (F11), Step out (Shift+F11), Step (F9), and Deactivate breakpoints (Ctrl+F8). The next lesson explains stepping in detail.

Stand-in: a breakpoint list with conditions

This second stand-in keeps a list of breakpoints with line numbers, enabled flags and optional conditions, and reports which would pause for a given execution trace.

JS Stand-in: which breakpoints would pause?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check Β· 4 questions

of 4 answered You scored / 4 Β· perfect!

  1. 1. What does a logpoint do?

    A logpoint is a breakpoint that logs an expression and continues running.
  2. 2. How do you pause only on the 500th loop iteration?

    A conditional breakpoint pauses only when its expression is true.
  3. 3. You do not know which code runs when a button is clicked. Which breakpoint helps?

    The Mouse > click event listener breakpoint pauses where a click handler is about to run.
  4. 4. Which statement in source code pauses execution when DevTools is open?

    The debugger statement acts as a breakpoint when a debugger is attached.

Summary

  • Sources has a file navigator, an editor and a debugger sidebar with Watch, Scope and Call Stack.
  • Use line, conditional and logpoint breakpoints; debugger; also pauses.
  • DOM, XHR/fetch, event listener and exception breakpoints find code when you only know a symptom.
  • While paused, inspect Scope, evaluate in the Console and edit values to test fixes.

Next: Stepping Through Code and Reading the Call Stack