Dev Tools: Debugging DOM Tree modifications

“Break on Subtree Modification” allows you to debug dynamically added and removed DOM nodes.
The other day I was debugging a Drag’n’Drop component, and I noticed that it added a DOM node every time I dragged an element. I wanted to inspect th…

“Break on Subtree Modification” allows you to debug dynamically added and removed DOM nodes.

The other day I was debugging a Drag’n’Drop component, and I noticed that it added a DOM node every time I dragged an element. I wanted to inspect the node and see what’s going on in the CSS panel, but as soon as I dropped the element I was dragging, the new node was removed from the DOM (Document Object Model). I tried to catch it quickly, but I didn’t have a chance.

Break Stuff

A quick search pointed me to an option I’ve noticed several times in the context menu of nodes in the elements panel, but I never cared to see what it was doing: “Break on…”.


Context menu in Firefox Dev Tools: the option “Break on…” selected and three child menu items showing: Subtree Modification, Attribute Modification, and Node Removal

Selecting “Break on Subtree Modification” pauses any script that modifies the DOM of the selected element and jumps to the line in the script that modified it.


The line that caused the DOM modification is highlighted in the sources panel.

Now that the script is paused, you can unhurriedly inspect the DOM.


Dev tools shows a message “Paused on DOM mutation” and allows me to select the new node in the elements panel.

This option helped me not only to debug the component, but I also felt less stupid because I didn’t have to desperately try to move the mouse as quickly as possible.

The other options are useful, too. I can imagine that “Break on attribute modification” can come in handy when we’re debugging complex animations or user interactions.

You can use this CodePen, if you want to try it yourself.


Print Share Comment Cite Upload Translate
APA
Manuel Matuzović | Sciencx (2024-03-29T15:13:40+00:00) » Dev Tools: Debugging DOM Tree modifications. Retrieved from https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications/.
MLA
" » Dev Tools: Debugging DOM Tree modifications." Manuel Matuzović | Sciencx - Friday January 29, 2021, https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications/
HARVARD
Manuel Matuzović | Sciencx Friday January 29, 2021 » Dev Tools: Debugging DOM Tree modifications., viewed 2024-03-29T15:13:40+00:00,<https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications/>
VANCOUVER
Manuel Matuzović | Sciencx - » Dev Tools: Debugging DOM Tree modifications. [Internet]. [Accessed 2024-03-29T15:13:40+00:00]. Available from: https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications/
CHICAGO
" » Dev Tools: Debugging DOM Tree modifications." Manuel Matuzović | Sciencx - Accessed 2024-03-29T15:13:40+00:00. https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications/
IEEE
" » Dev Tools: Debugging DOM Tree modifications." Manuel Matuzović | Sciencx [Online]. Available: https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications/. [Accessed: 2024-03-29T15:13:40+00:00]
rf:citation
» Dev Tools: Debugging DOM Tree modifications | Manuel Matuzović | Sciencx | https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications/ | 2024-03-29T15:13:40+00:00
https://github.com/addpipe/simple-recorderjs-demo