Break on DOM changes in DevTools
Find the code that changes an element with a DOM breakpoint in Chrome DevTools for subtree, attribute or removal changes, or log changes with MutationObserver.
Something keeps changing a button's text or removing a node, and you do not know which script does it. A DOM breakpoint pauses at the exact line that makes the change.
In the Elements panel, right-click the element, then choose Break on and pick one of three:
Subtree modifications, when a child is added, removed or moved.
Attribute modifications, when an attribute or class changes.
Node removal, when the element is removed from the page.
When it triggers, the Sources panel pauses on the script line and the call stack shows who made the change. See the DevTools DOM breakpoints guide.
To record changes without stopping, use a MutationObserver from the console:
const target = document.querySelector("#cart");
new MutationObserver((records) => {
for (const r of records) console.log(r.type, r.target.id);
}).observe(target, { childList: true, attributes: true });childList cart
attributes cartThe observer tells you what changed, but not who changed it. Use the breakpoint for the caller, and the observer for a log of the whole session.