Last active
September 8, 2023 08:35
-
-
Save telefonosuci/76ad7fdda2b2c294cc31cf84ae524ea5 to your computer and use it in GitHub Desktop.
Print trace when a node of a specific type is appended to the dom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
const checkNodeType = Node.COMMENT_NODE; | |
const observer = new MutationObserver((mutationsList, observer) => { | |
for (const mutation of mutationsList) { | |
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { | |
for (const addedNode of mutation.addedNodes) { | |
if (addedNode.nodeType === checkNodeType) { | |
console.log('Comment added to DOM:', addedNode.textContent); | |
console.trace(); | |
} | |
} | |
} | |
} | |
}); | |
// Here we are watching the head of the dom... We can specific any other node to watch... | |
observer.observe(document.head, { childList: true, subtree: true }); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment