Reputation: 10199
Is there a way to set breakpoints when specific functions are about to execute?
It needn't be an explicit breakpoint - I just want execution to pause when a console.log()
is about to be called.
Or should I resort to this method.
I prefer to accomplish this without modifying my code, or manually setting breakpoints at every console.log
.
Upvotes: 0
Views: 3149
Reputation: 47968
Yes that's the trick. Create a custom logging function, put debugger
in it and call console.log
and you have what you wanted:
function log(message) {
debugger;
console.log(message) ;
}
You can also replace console.log
by a similar fonction that calls the original:
var clog = console.log;
console.log = function(message) {
if(message == '...') {
debugger;
}
clog.apply(console, arguments);
}
This code will affect all log calls within your page. The check is to catch a certain message. Remove it to stop always.
Upvotes: 2
Reputation: 9813
How about call this at the very start that add a pause break for your every console.log
?
This replace the original console.log
, pause break first, then call the orignal console.log
for you. And this will be apply on all console.log
calls.
(function () {
var oldLog = console.log;
console.log = function() {
debugger;
oldLog.apply(console, arguments);
}
})();
console.log('hello');
Upvotes: 1