Skip to content

Instantly share code, notes, and snippets.

@omrilotan
Last active July 16, 2020 14:47
Show Gist options
  • Save omrilotan/0592a361788041e69b0b168e0af4e071 to your computer and use it in GitHub Desktop.
Save omrilotan/0592a361788041e69b0b168e0af4e071 to your computer and use it in GitHub Desktop.
Get DOM tree modification Changelog
/**
* @example
* getDOMChangelog()
*
* at https://github.githubassets.com/assets/vendor-cd663c13.js:120:53592
* at https://github.githubassets.com/assets/vendor-cd663c13.js:120:53557
* at cn (https://github.githubassets.com/assets/frameworks-728fb339.js:1:78638)
* at on (https://github.githubassets.com/assets/frameworks-728fb339.js:1:77982)
* at https://github.githubassets.com/assets/github-bootstrap-59211cb2.js:16:285146
* at https://github.githubassets.com/assets/github-bootstrap-59211cb2.js:1:15524
* at add (https://github.githubassets.com/assets/github-bootstrap-59211cb2.js:16:264107)
* at add (https://github.githubassets.com/assets/github-bootstrap-59211cb2.js:16:65125)
* at add (https://github.githubassets.com/assets/github-bootstrap-59211cb2.js:16:65043)
* at add (https://github.githubassets.com/assets/github-bootstrap-59211cb2.js:16:65043)
*
*/
const getDOMChangelog = (function(maxSize = 10) {
const DOMChangeLog = [];
document.addEventListener('DOMSubtreeModified', function () {
const line = new Error().stack.split('\n').find(
line => line.includes('.js')
);
if (line) {
DOMChangeLog.unshift(line);
if (maxSize) {
DOMChangeLog.length = maxSize;
}
}
});
return () => DOMChangeLog.filter(Boolean).join('\n');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment