brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Break on subtree modifications finds the script that changes an element

Javascript
~/tips/tip-devtools-dom-break-subtree

Elements > right-click #results > Break on > Subtree modifications

Pauses the page in the script that adds, removes or changes an element.

Sometimes a list on a page changes and I have no idea which script touches it. Instead of searching through bundles, I let DevTools pause at the moment it happens.

In the Elements panel, right-click the element, hover over Break on and pick one of three entries: Subtree modifications, Attribute modifications or Node removal.

Subtree modifications fires when a child of the selected node is added or removed, or when a child’s contents change. Attribute modifications fires when an attribute on the selected node is added, removed or changed. Node removal fires when the selected node is removed.

When one of those happens, the debugger pauses in the code that did it, and the call stack tells you who asked for the change. For a container such as a feed or a results list, you select the parent and wait:

Elements > right-click #results > Break on > Subtree modifications

Every breakpoint you set this way is listed in the DOM Breakpoints pane, in Elements or in Sources, where you can switch it off again.

The caveat sits in the definition. Subtree modifications ignores attribute changes on the children and changes to the selected node itself. If a class changes on a list item and not on the list, put an Attribute modifications breakpoint on that item instead.

Further reading: Chrome DevTools: breakpoints

More Javascript tips node --inspect-brk app.js obj?.prop const filePath = String.raw`C:\Development\profile\about.html`; const observer = new ResizeObserver((entries) => { URL.parse("not a url"); // null All Javascript tips (40) All topics

Link