Aran Mulholland
Aran Mulholland

Reputation: 23945

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.

Upvotes: 0

Views: 638

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 371193

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

Upvotes: 3

Related Questions