0

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.

Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228

1 Answers1

3

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

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
  • Works like a charm, I should have thought of this, have done similiar in the past with other things, I love JavaScript, I love it's easy to bend dynamic nature when you need to do something like this. It's a lovely little language. Thank you. – Aran Mulholland Mar 28 '20 at 07:52