In Chrome DevTools, how do you find the code behind a checkout button that sometimes does nothing, in a large bundled application you did not write?
answer
- let the symptom pause you
- did the click reach any code?
- did a request ever leave?
- swallowed error or changed state?
- then read the Call Stack upwards
basics
~20 sDo not read the bundle: make the symptom pause you. Use an Event Listener Breakpoint on click, an XHR/fetch breakpoint on the request URL, a DOM change breakpoint on the button and Pause on caught exceptions, then read the Call Stack.
solid answer
~50 sI wouldn't read the bundle; I'd make the browser show me the code. In **Sources**, I'd tick **Mouse > click** under **Event Listener Breakpoints** and click: if it never pauses, no listener ran, so the click isn't reaching a handler. If it pauses, I step and read the **Call Stack**, knowing it may land in a framework's dispatcher first. If I know the request that should fire, an **XHR/fetch** breakpoint on part of its URL shows whether it's sent and from where. If the button changes state, **Break on > attribute modifications** in **Elements** stops on the code doing it. If it dies silently, **Pause on caught exceptions** finds the swallowed error. Because it's intermittent, I keep those armed, compare a good run with a bad one, and then narrow down with a conditional breakpoint.
code
javascript · 5 lines// Paused on an XHR/fetch breakpoint, the Call Stack shows who sent it
async function submitOrder(cart) {
const body = buildPayload(cart);
await fetch('/api/checkout', { method: 'POST', body }); // pauses here for '/checkout'
}go deeper
Recall that breakpoints exist for events, requests and DOM changes, not only for lines. Know where each one lives: the Sources panel for the first two, and a right-click in the Elements panel for the third.
Pick the right kind from what you know: an event, a URL fragment, a node that changes, or a thrown error. Explain where each one stops, and the difference between the three DOM change kinds.
Run a method from the symptom: split the failure into click, request, exception and state, treat no pause as an answer, expect framework dispatchers, and compare a good run with a bad one for an intermittent fault.
Consider what keeps this possible on production builds. The tooling needs readable stacks and ways to reproduce a user's state, so the team's choices about those decide how quickly anyone can run this ladder during an incident.
## Turn the symptom into a pause A **line-of-code breakpoint** assumes you know where to look. In a large bundle you did not write, you do not, and reading minified code in search of a handler is slow and unreliable. Chrome DevTools has breakpoints that key on **what happens** rather than where: an event fires, a request is sent, a DOM node changes, an error is thrown. Each one pauses in whichever code is responsible, and the **Call Stack** pane then tells you how execution got there. Once you are paused, you know the file and line you could never have searched for. ## A ladder of questions "Does nothing" is several different failures. Work through them in order, because each answer rules out a whole region of code: 1. **Did the click reach any code?** Under **Event Listener Breakpoints** in the **Sources** panel, expand **Mouse** and tick **click**. If you click and nothing pauses, no click listener ran, so look at what prevents one: a disabled button, or nothing listening. If it pauses, you have an entry point. 2. **Did it reach the network?** Add part of the expected URL to the **XHR/fetch Breakpoints** pane, such as `/checkout`. A pause shows the request is being sent and exactly which code sends it. No pause means the failure is between the click and the request. 3. **Did it die on an exception?** Tick **Pause on caught exceptions** in the **Breakpoints** pane. A swallowing `catch` produces exactly this symptom: nothing on screen and an empty **Console**. 4. **Did something change the button?** In the **Elements** panel, right-click the button, then use **Break on > attribute modifications**. Code that sets `disabled` or a class stops the debugger as it does so. ## Which breakpoint for which fact | What you know | Breakpoint | Where you set it | Where it pauses | |---|---|---|---| | An event happens | **Event Listener Breakpoints** | **Sources** panel | On listener code for that event, for any element | | Part of a request's URL | **XHR/fetch Breakpoints** | **Sources** panel | On the code sending a request whose URL contains that string | | A node changes | **Break on** (three kinds) | **Elements** panel, right-click | On the code making the change | | Something throws | **Pause on caught exceptions** | **Breakpoints** pane | At the throw, before the stack unwinds | The three DOM kinds differ in ways that matter: - **Subtree modifications** fires when a child is added or removed, or a child's contents change. It does not fire for a child's attributes, or for changes to the node itself. - **Attribute modifications** fires when an attribute on that node is added, removed or changed. - **Node removal** fires when that node itself is removed. If a framework replaces the button on every render, a breakpoint on the button is attached to a node that is about to disappear, so watch its parent with **Subtree modifications** instead. ## Working inside the bundle - **Read the banner first.** It states why you stopped, such as `Paused on event listener` or `Paused on XHR or fetch`, and the DOM kinds are named too. - **Expect a dispatcher.** A framework often attaches one listener near the root, so the click pause can land in its dispatch code rather than in the button's handler. **Step into** from there, or set the XHR/fetch breakpoint instead and read the stack backwards. - **Reduce the noise.** Adding a framework's scripts to the ignore list obscures them in the stack and stops stepping from entering them. How that list works is its own subject. A pause in code you do not recognise may also come from a browser extension. - **Use the formatter.** The **Sources** panel can pretty-print a minified file, and you can set breakpoints on the formatted lines. ## Dealing with "sometimes" An intermittent bug needs a comparison more than a single pause. Keep the breakpoints armed and reproduce until you have one good run and one bad run, then ask where they diverge. If the failure seems tied to one list position or item, put a conditional breakpoint on the suspect line, such as `index === 4`, so the good iterations do not stop you. If a pause seems to make the bug vanish, the timing is probably involved, so switch to logpoints on the same lines and read the order of events instead. The request's own timing and initiator detail are covered with the Network panel. ## What the interviewer is listening for - A **method**, starting from the symptom rather than the file tree. - Knowing that no pause is also an answer. - Honesty about frameworks, since the first pause may land in a dispatcher rather than the handler. - No `console.log` and no rebuild, because all of this works on the deployed code.
- The click breakpoint lands in a framework's dispatcher. How do you reach the application's code?That is common, since a framework often attaches one listener near the root. Use **Step into** from the dispatcher, or add the framework's scripts to the ignore list so stepping no longer enters them. Often it is quicker to skip the dispatcher entirely: set an XHR/fetch breakpoint on the expected URL and read the **Call Stack** backwards to the handler.
- The request fires, but with the wrong payload. How do these breakpoints help?An XHR/fetch breakpoint on part of the URL pauses at the sending code, so **Scope** usually shows the body being sent. Click running frames in the **Call Stack** pane to see what each caller passed, and read any async section to find what scheduled it. Then set a line-of-code breakpoint where the wrong value is first built and reproduce.
- Unknown code sets the button's disabled attribute. How do you find it?In the **Elements** panel, right-click the button and use **Break on > attribute modifications**. The debugger pauses on the code setting the attribute, and the banner names the reason. Read the **Call Stack** upward, past any framework frames, to the code that decided to disable it. If a re-render replaces the node, watch its parent with **Subtree modifications** instead.
It is like setting tripwires instead of searching every room of an unfamiliar building. You do not need to know who is inside or where they are; you choose what should sound the alarm, and you catch whoever trips it, mid-act. A wire that never trips tells you something too.
- Searching a minified bundle is the fastest way to find a handler in unfamiliar code.
- Event Listener Breakpoints pause only on listeners attached directly to the clicked element.
- An XHR/fetch breakpoint needs the full, exact URL of the request.
- Subtree modifications also fires when a child's attribute changes.
- A DOM change breakpoint is set from the line number gutter in the Sources panel.
- A bug in deployed bundled code cannot be debugged without a rebuild containing console.log calls.