Skip to content

Instantly share code, notes, and snippets.

@schnogz
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save schnogz/ae3e145f379e45817702 to your computer and use it in GitHub Desktop.

Select an option

Save schnogz/ae3e145f379e45817702 to your computer and use it in GitHub Desktop.
Count All Watchers Currently Running on an AngularJS Page
(function () {
// Change root to point at your ng-app in HTML
var root = $(document.getElementsByTagName('body'));
var watchers = [];
var f = function (element) {
if (element.data().hasOwnProperty('$scope')) {
angular.forEach(element.data().$scope.$$watchers,
function (watcher) {
watchers.push(watcher);
}
);
}
angular.forEach(element.children(),
function (childElement) {
f($(childElement));
}
);
};
f(root);
console.log("Watchers Count: " + watchers.length);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment