Skip to content
  1. LuzineDebug
  2. Guides
  3. Debug JavaScript with Chrome DevTools
Guide Beginner ≈ 15 min

Debug JavaScript with Chrome DevTools

In short

Open DevTools with F12, read the error in the Console, then set a breakpoint in the Sources panel to inspect variables line by line. The Network panel shows the status and response of every request, and the Application panel shows local storage and the service worker.

Be the first to approve this guide

Why this method

Chrome DevTools (identical in Edge, Brave and other Chromium browsers) are a full debugger, not just a console. Instead of scattering console.log calls everywhere, you can freeze execution at the right moment, read every variable, follow a network request end to end or clear a stubborn cache. This guide walks through the features that solve most front-end bugs: console, the different breakpoint types, the Network panel and the Application panel.

What you need

  • Chrome, Edge or another recent Chromium browser
  • The page to debug, ideally served locally (http://localhost)
  • Source maps if the code goes through a bundler (Vite, webpack)

Step by step

  1. Open DevTools on the right panel

    Press F12, or Ctrl+Shift+I on Windows and Linux, Cmd+Option+I on macOS. To land straight in the Console: Ctrl+Shift+J or Cmd+Option+J. Right-clicking an element and choosing "Inspect" opens the Elements panel on that node.

    Look at the red counter in the top right first: it shows how many errors have already been thrown since the page loaded.

  2. Make the most of the Console

    Each error shows a clickable file:line link and an arrow that expands the call stack. Filter by level (Errors, Warnings) and tick Preserve log to keep messages across a redirect.

    The Console also runs JavaScript inside the page: $0 is the element selected in Elements, copy() copies a value to the clipboard, console.table() prints an array of objects as a readable table and console.trace() prints the current stack.

    javascript
    console.table(users);
    copy(JSON.stringify($0.dataset));
    console.trace('qui appelle cette fonction ?');
  3. Set a breakpoint and step through

    In the Sources panel, open a file with Ctrl+P (Cmd+P on macOS) and click a line number: a blue marker appears. Reload or repeat the action, and execution freezes on that line.

    The right pane shows Scope (local variables), Watch (watched expressions) and Call Stack. Step with F10 (next line), F11 (step into), Shift+F11 (step out) and F8 (resume). Hover a variable in the code to see its value.

  4. Use conditional breakpoints and logpoints

    Right-click a line number: Add conditional breakpoint only pauses when the expression is true, for example inside a 10,000-iteration loop. Add logpoint prints a message to the Console without pausing and without touching the source code: it is a temporary console.log you will never forget to remove before a commit.

    javascript
    // Condition du point d'arrêt
    item.id === 42 && item.price < 0
    
    // Message du logpoint
    'panier', cart.items.length, cart.total
  5. Pause on exceptions, DOM changes and requests

    In the Breakpoints pane of Sources, tick Pause on uncaught exceptions to freeze the code at the exact moment an unhandled error is thrown, and Pause on caught exceptions for those caught by a try/catch.

    To find which script changes an element, right-click it in Elements, then Break on and choose subtree modifications, attribute modifications or node removal. The XHR/fetch Breakpoints pane pauses on any request whose URL contains a given text, and Event Listener Breakpoints on an event type (click, submit).

  6. Inspect requests in the Network panel

    Open the Network panel before reproducing the bug, filter on Fetch/XHR and tick Disable cache. A red row means a 4xx or 5xx status or a blocked request (CORS). Click it: Headers gives the URL, method and headers, Payload the body you sent, Preview and Response the raw response.

    Right-click the request, then Copy and Copy as cURL: you can replay it in a terminal or convert it to code. On Windows, pick the bash, cmd or PowerShell variant to match your shell.

    A copied cURL contains your cookies and tokens: never paste it as is into a public ticket.

  7. Inspect storage and the service worker

    The Application panel shows Local storage, Session storage, IndexedDB and Cookies: you can read, edit or delete each entry to test a specific state. Under Service workers, tick Update on reload during development, or Bypass for network to skip the offline cache. If an old version of the app keeps showing up, open Storage and click Clear site data.

Mistakes to avoid

  1. Trusting a logged object: console.log(obj) shows a live reference, and the expanded object shows its current value, not its value at log time. Log structuredClone(obj) or use a breakpoint.
  2. Forgetting that Disable cache only works while DevTools are open: close them and the cache is back.
  3. Debugging the minified bundle: without source maps, breakpoints land on unreadable code. Enable them in the bundler configuration in development.
  4. Leaving a debugger; statement in committed code: it freezes the page for every teammate who has DevTools open.

Checklist

Did this guide help you?

Approve it in one click: it will be highlighted for other developers.

Frequently asked questions

How do I set a conditional breakpoint in Chrome?

In the Sources panel, right-click the line number, choose "Add conditional breakpoint" and type a JavaScript expression. The code only pauses when it is true.

How do I copy a request as cURL from Chrome?

In the Network panel, right-click the request, then Copy and Copy as cURL. On Windows, pick the variant that matches your terminal.

Why does my breakpoint never pause?

The code is not executed, or it is a different file from the one loaded (cache, service worker, wrong bundle). Disable the cache, check the source maps and confirm the line is reached with a logpoint.

Tools to apply this guide

More guides