Reputation: 6481
I am debugging a complex webpage which is throwing an alert box on clicking a particular element. I want to locate the code which is causing this. It is difficult to search my codebase by looking for message shown in alert box as it is very vague and dynamic. Is it possible to pause JS execution on alert in debugger from the Chrome dev tools or any other debugger? (In a similar way like Chrome allows to pause JS execution on events like click, etc).
I already tried reaching the code by pausing on click event, but there are too many JS files to step through and the code is minified and complex.
Thanks.
Upvotes: 2
Views: 2207
Reputation: 4600
You can override alert function, put a breakpoint and take a look at Call Stack to figure out where it comes from.
You will need to have browser's DevTools to be opened for debugger;
to trigger. And ensure that this code is executed BEFORE actual alert that you are looking for is called, so put it at the top of everything else.
(function() {
var _old_alert = window.alert;
window.alert = function() {
// breakpoint
debugger;
_old_alert.apply(window, arguments);
};
})();
alert('hey');
Upvotes: 2