Skip to content

Instantly share code, notes, and snippets.

@bkardell
Last active August 29, 2015 14:03
Show Gist options
  • Save bkardell/7da8ba03e690f2c24503 to your computer and use it in GitHub Desktop.
Save bkardell/7da8ba03e690f2c24503 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script>
// select the target node
var target = document;
var total = {};
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
var mutationType = mutation.type, i = 0, nodeType;
total[mutationType]= total[mutationType] || { count: 0 };
total[mutationType].count++;
for(;i < mutation.addedNodes.length; i++) {
nodeType = mutation.addedNodes[i].nodeType;
total[mutationType][nodeType] = total[mutationType][nodeType] || { count: 0 };
total[mutationType][nodeType].count++;
};
});
});
document.addEventListener("DOMContentLoaded", function () {
var out = JSON.stringify(total, null, 4);
observer.disconnect();
document.querySelector("pre").innerHTML = out;
}, false);
observer.observe(document.documentElement, {
attributes: true,
childList: true,
subtree: true,
characterData: true
});
</script>
</head>
<body>
<h1>What's all this?</h1>
<ul>
<li>
<span class="1">A test page which adds a mutation observer early,
collects results and spits them out... Shouldn't browsers all
report the same thing here?
</span>
<pre></pre>
</li>
<ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment