Search code examples
javascriptgoogle-chromedebugginggoogle-chrome-devtoolsbreakpoints

Setting breakpoints on function calls in Chrome Dev. Mode


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.


Solution

  • 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) ;
    }
    

    Edit:

    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.