Search code examples
javascriptgoogle-chromedebuggingjavascript-debuggerchrome-debugging

Is it possible to pause the chrome debugger on every console.log statement executed by the JavaScript code?


I would like to pause the Chrome debugger whenever a console.log statement occurs. Is this possible and if so how would it be achieved?

I know I can break on subtree modification etc. Something like that where the event I was pausing on was one emitted to the console.


Solution

  • One option is to overwrite console.log with your own function that uses debugger:

    const origConsoleLog = console.log;
    console.log = (...args) => {
      debugger;
      origConsoleLog(...args);
    };
    
    
    (() => {
      const foo = 'foo';
      console.log('foo is', foo);
      const fn = () => {
        const someLocalVar = true;
        console.log('fn running');
      };
      fn();
    })();
    

    enter image description here