简体   繁体   English

是否可以在 JavaScript 代码执行的每个 console.log 语句上暂停 chrome 调试器?

[英]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.每当出现 console.log 语句时,我想暂停 Chrome 调试器。 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.我知道我可以中断子树修改等。类似于我暂停的事件是发送到控制台的事件。

One option is to overwrite console.log with your own function that uses debugger :一种选择是使用您自己的使用debugger的函数覆盖console.log

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM