javascript 调试时如何忽略某些脚本文件/行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6213401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 19:53:50  来源:igfitidea点击:

How to ignore certain script files / lines when debugging?

javascriptjqueryinternet-explorerdebuggingfirebug

提问by Michael

I'm trying to debug some JavaScript, I want to find out what code gets executed when I hover over a certain div element (I've got no idea which bit of code, because there's no direct 'onmouseover' - I think there's a jQuery selector in place somewhere?).

我正在尝试调试一些 JavaScript,我想知道当我将鼠标悬停在某个 div 元素上时会执行哪些代码(我不知道哪一段代码,因为没有直接的“onmouseover”——我认为有一个jQuery 选择器在某处?)。

Usually I'd use the "Break All" / "Break On Next" facility provided by Developer Tools / Firebug, but my problem is that other code (tickers, mouse movement listeners etc.) immediately gets caught instead.

通常我会使用 Developer Tools/Firebug 提供的“Break All”/“Break On Next”工具,但我的问题是其他代码(代码、鼠标移动侦听器等)会立即被捕获。

What I'd like to do is tell the debugger to ignore certain JavaScript files or individual lines, so that it won't stop on code I'm not interested in or have ruled out. Is there any way to achieve that in IE (spit, spit!) - or could you suggest a better approach?

我想做的是告诉调试器忽略某些 JavaScript 文件或个别行,这样它就不会停在我不感兴趣或已排除的代码上。有没有办法在 IE 中实现这一点(吐,吐!) - 或者你能提出更好的方法吗?

回答by flu

In FireFox this feature is called "Black boxing"and will be available with FireFox 25. It let's do exactly what you where looking for.

在 FireFox 中,此功能称为“黑拳”,可在 FireFox 25 中使用。它让我们完全按照您的要求进行操作。

This feature was also introduced to Chrome (v30+) although it's tougher to find/configure. It's called "skip through sources with particular names" and Collin Miller did an excellent job in describing how to configure it.

此功能也被引入 Chrome (v30+),尽管它更难找到/配置。它被称为“跳过具有特定名称的源”,Collin Miller在描述如何配置它方面做得非常出色

Normally I'm for putting answers and howtos here instead of links but it would just end in me copying Collin's post.

通常我会在这里提供答案和方法而不是链接,但最终我会复制 Collin 的帖子。

回答by pawlik

Looks like you're looking for Visual Event.

看起来您正在寻找Visual Event

回答by gnarf

You might want to take a look at Paul Irish's Re-Introduction to the Chrome Developer Tools, in particular the Timeline section (starts around 15 minutes into the video.)

您可能想看看Paul Irish 的 Chrome 开发者工具重新介绍,特别是时间轴部分(从视频开始大约 15 分钟开始。)

You can start recording all javascript events - function executions (with source lines etc) and debug based on what events fired. There are other really handy debugging tools hiding in that google IO talk that can help you solve this problem as well.

您可以开始记录所有 javascript 事件 - 函数执行(带有源代码行等)并根据触发的事件进行调试。还有其他非常方便的调试工具隐藏在 google IO talk 中,它们也可以帮助您解决这个问题。

回答by jdeseno

If you're pretty sure it's a jQuery event handler you can try to poke around with the jQuery events. This will overwrite all the click handlers (replace with the type you're interested in) and log out something before each event handler is called:

如果您非常确定它是一个 jQuery 事件处理程序,您可以尝试使用 jQuery 事件。这将覆盖所有点击处理程序(替换为您感兴趣的类型)并在调用每个事件处理程序之前注销某些内容:

var elem = document.body; // replace with your div
// wrap all click events:
$.each($._data(elem).events.click, function(i, v) { 
    var h = v.handler; 
    v.handler = function() {
      // or use 'alert' or something here if no Dev Tools
      console.log('calling event: '+ i);
      console.log('event handler src: '+ h.toString()); 
      h.apply(h, arguments); 
    };
})

Then try calling the event type directly through jQuery to rule out that type:

然后尝试直接通过 jQuery 调用事件类型以排除该类型:

$('#your_div').click()

回答by Wladimir Palant

You can use JavaScript Deobfuscator extension in Firefox: https://addons.mozilla.org/addon/javascript-deobfuscator/. It uses the same debugging API as Firebug but presents the results differently.

您可以在 Firefox 中使用 JavaScript Deobfuscator 扩展:https://addons.mozilla.org/addon/javascript-deobfuscator/ 。它使用与 Firebug 相同的调试 API,但显示的结果不同。

In the "Executed scripts" tab it will show you all code that is running. If some unrelated code is executing as well it is usually easy enough to skip. But you can also tweak the default filters to limit the amount of code being displayed.

在“已执行的脚本”选项卡中,它将显示所有正在运行的代码。如果一些不相关的代码也在执行,通常很容易跳过。但是您也可以调整默认过滤器以限制显示的代码量。

回答by AjayR

If using are using IE 7.0 onwards, you should have developer toolbar from where you can debug. Just use breakpoint where you need, rest of the code will not stop. Alternatavely you can define other applications like Interdev/ Visual Studio.net for debugging purpose too.

如果使用的是 IE 7.0 以后的版本,您应该有开发人员工具栏,您可以从中进行调试。只需在需要的地方使用断点,其余代码不会停止。或者,您也可以为调试目的定义其他应用程序,例如 Interdev/Visual Studio.net。