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…


This content originally appeared on Web development blog - Manuel Matuzović and was authored by Manuel Matuzović

“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.


This content originally appeared on Web development blog - Manuel Matuzović and was authored by Manuel Matuzović


Print Share Comment Cite Upload Translate Updates
APA

Manuel Matuzović | Sciencx (2021-01-29T06:58:54+00:00) Dev Tools: Debugging DOM Tree modifications. Retrieved from https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications-2/

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-2/
HARVARD
Manuel Matuzović | Sciencx Friday January 29, 2021 » Dev Tools: Debugging DOM Tree modifications., viewed ,<https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications-2/>
VANCOUVER
Manuel Matuzović | Sciencx - » Dev Tools: Debugging DOM Tree modifications. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications-2/
CHICAGO
" » Dev Tools: Debugging DOM Tree modifications." Manuel Matuzović | Sciencx - Accessed . https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications-2/
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-2/. [Accessed: ]
rf:citation
» Dev Tools: Debugging DOM Tree modifications | Manuel Matuzović | Sciencx | https://www.scien.cx/2021/01/29/dev-tools-debugging-dom-tree-modifications-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.