skip to content

In Chrome DevTools, paused in a promise callback holding a wrong total, how do you find what scheduled it and step across that async hop?

level: seniorimportance: nice to knowfreq 33%

answer

  1. the stack looks too short
  2. extra sections in the Call Stack pane
  3. recorded frames, not live frames
  4. F11 follows a scheduled callback
  5. custom schedulers can break the chain

basics

~20 s

The Call Stack pane adds async sections below the running frames, showing the code that scheduled this callback; those frames give locations, not live variables. Step into (F11) follows a callback the current line schedules, while Step (F9) stays with synchronous code.

solid answer

~50 s

The **Call Stack** pane shows more than the frames running now. Below them it adds a section for each async hop, headed by the operation, with the frames that scheduled this callback, so I can read back through the `.then` or timer to the code that started it. Those frames are a recording, not live ones: clicking one opens its source location, but their variables are gone, so to see values there I set a breakpoint on that line and reproduce. To move across a hop, **Step into** (`F11`) follows a callback the current line schedules, and **Step** (`F9`) stays with the synchronous code. The chain has limits. **Disable async stack traces** turns it off, it is recorded only while the debugger is attached, and a hand-written task queue can break it unless the framework links its tasks with `console.createTask`.

go deeper

for a junior

Recall that the Call Stack pane can show what scheduled a callback, in extra sections below the running frames. Knowing that those entries are there, and that you can click them, is enough at this stage.

for a middle

Explain that running frames and async entries differ: one has live variables, the other only a location. Be able to say which step key follows a scheduled callback, and that recording happens only while the debugger is attached.

for a senior

Diagnose a chain that stops short: late DevTools, the setting, a framework queue draining from one timer. Then say what you do about each one, including pairing enqueue and run with logpoints when the framework offers no link.

for a principal

The relevant decision is whether in-house schedulers and queues support async stack tagging. A small instrumentation cost in shared code can save every engineer time, so weigh it when a team builds its own task layer.

## The problem: the stack looks too short Paused inside a promise callback, the running part of the call stack is very short, often just the callback itself. The function that created the promise returned long ago, so it is no longer running. Why that happens is a matter of how tasks and microtasks are scheduled, which belongs with the event loop. The practical trouble is that the question you most want answered, "who asked for this?", has no answer among the frames that are currently running. ## What the Call Stack pane adds Chrome DevTools records where async work was scheduled and stitches that into the **Call Stack** pane. Below the running frames you get a series of sections, each with a header naming the operation, such as `setTimeout`, followed by the frames that were on the stack when that work was scheduled. ```js function onCheckout() { loadPrices().then(applyTotal); // shown in the async section } function applyTotal(prices) { const total = sum(prices); // paused here: the only running frame render(total); } ``` Paused in `applyTotal`, you see `applyTotal` as the running frame, then an async section containing `onCheckout` and whatever called it. The pane shows up to 32 hops at first, with a **Show more** link when the chain goes further. To use it on a wrong value: 1. Read the running frame, which tells you what is executing now. 2. Read the first async header, which names the hop you came across. 3. Click the frames beneath it to open the code that scheduled this work. 4. Set a breakpoint there and reproduce, if you need the values it held. ## Recorded frames and running frames are different things This distinction is what the question is really testing. | | Running frame | Frame in an async section | |---|---|---| | Is its function still on the stack? | Yes | No, it has already returned | | Clicking it | Selects it: Scope, Watch and Console follow | Opens its source location only | | Its local variables | Available | Gone | | **Restart frame** | Offered, where the frame allows it | Not offered | So an async section tells you **where** to look, not **what the values were**. To get values at `onCheckout`, set a breakpoint on that line and reproduce the bug. If the callback runs many times, use a conditional breakpoint, or a logpoint that prints an identifier at both ends so you can pair a schedule with its run. ## Stepping across a hop - **Step into** (`F11`, labelled **Step into next function call**) enters synchronous calls and also follows a callback the current line schedules. On a line calling `setTimeout(applyTotal, 0)`, it pauses at the start of `applyTotal` when the timer fires. - **Step** (`F9`) enters synchronous calls too, but does not make that jump. It moves to the next statement in synchronous order. - **Step over** (`F10`) on an `await` line normally lands on the next statement of that `async` function once the promise settles. Other tasks may run in between, and a breakpoint in one of them stops you first. - **The dependable fallback** for a long chain is a breakpoint in the next callback, followed by `F8`. Stepping hop by hop through library code is rarely worth it. ## When the chain stops short An incomplete async section is a clue, not a bug in your code: - **The debugger was not attached yet.** Recording runs only while it is enabled, so work scheduled before you opened DevTools has no parent to show. Open DevTools first, then reproduce. - **The setting is off.** **Disable async stack traces**, under the debugger settings, sets the recording depth to zero. - **A hand-written scheduler sits in between.** The engine links real scheduling operations. If a framework pushes callbacks into an array and one timer drains them, the recorded parent is whatever scheduled the flush, not the code that enqueued your callback. - **Ignore-listed frames are hidden.** Framework frames on the ignore list are left out of the pane unless you tick **Show ignore-listed frames**. For that scheduler case, the fix belongs to the framework: `console.createTask()` lets it link work to where it was enqueued, which DevTools calls async stack tagging. Without it, set a breakpoint or logpoint at the enqueue site. ## What this view is not The async section is data the debugger keeps while attached. It does not lengthen the `stack` string that an `Error` carries at runtime, so it will not appear in what your error tracker receives. How that string behaves across async hops is covered with error stacks. The practical consequence is that a chain you can read in DevTools may not exist in a production report, so do not plan a diagnosis around seeing it there.

  • Why can't you read variables in a frame from an async section?
    That function already returned, so its frame no longer exists. The debugger kept only the record of where it was, meaning function name and location. Clicking the entry opens the source line and nothing more. To get values there, set a breakpoint on that line and reproduce, using a condition if the line runs many times.
  • The async section stops at a framework's scheduler. What do you do?
    Recognise that the engine links only real scheduling operations, so a queue drained by one timer shows the flush as the parent. If the framework uses `console.createTask`, the link is restored for you. Otherwise, set a breakpoint or logpoint where work is enqueued, printing an identifier, and print the same identifier in the callback to pair the two.
  • What happens when you step over an await line in Chrome DevTools?
    It normally lands on the next statement of that `async` function after the promise settles, so you stay with the logical flow rather than falling out into the caller. Other tasks can run during the wait, so a breakpoint in one of them may stop you first. The running frames at that next pause come from the resumed function.

  • Frames in an async section are live, so clicking one shows its variables in Scope.
  • An async section means the scheduling function is still running on the call stack.
  • Step over jumps straight into a callback that the current line schedules.
  • Async sections appear even for work scheduled before DevTools was opened.
  • The async section shows the true origin no matter how a framework schedules its work.