简体   繁体   English

Javascript console.log 在调试器中无法在 function 内部工作

[英]Javascript console.log not working inside function in debugger

To debug some concepts I run this in Chrome Console:为了调试一些概念,我在 Chrome 控制台中运行了这个:

what = function(){ 
    let value = 5
    try { 
        wrong(); 
    } catch(e) { 
        console.log('bad'); 
        value += 1
    }
    return value
}
what()
# returns 6

Works as expected, except console.log('bad') never happens.按预期工作,除了console.log('bad')永远不会发生。

obviously the fact that value = 6 and not 5 is proof that block is called.显然,值 = 6 而不是 5 的事实证明块被调用了。

Why does console.log just get skipped in the console?为什么 console.log 只是在控制台中被跳过? I'm pretty sure I've injected JS into apps where the console.log works so this is probably a setting in the console window itself.我很确定我已经将 JS 注入到 console.log 工作的应用程序中,所以这可能是控制台 window 本身的一个设置。 Firefox's behavior is the same. Firefox 的行为是相同的。

My best guess, since it isn't working on either platform, is that it is an extension that is blocking it -- from another stackoverflow post , it may be firebug lite or you accidentally disabled it through your filters.我最好的猜测是,因为它不能在任何一个平台上工作,所以它是一个阻止它的扩展——来自另一个 stackoverflow 帖子,它可能是 firebug lite 或者你不小心通过你的过滤器禁用了它。

If none of this works, I suggest trying out a guest window and seeing if it works there.如果这些都不起作用,我建议尝试使用访客 window,看看它在那里是否有效。

I can not reproduce this on my own machine as well as others: Chrome 102.0.5005.61 (Official Build) (64-bit) (cohort: 102_win_control)我无法在自己的机器和其他机器上重现此内容:Chrome 102.0.5005.61(官方构建)(64 位)(群组:102_win_control)

It is working!这是工作! Remove the last line and it will work!删除最后一行,它将起作用! If it again did not worked then it is might blocking by an extension如果它再次不起作用,那么它可能会被扩展阻止

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

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