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

发布于 2024-11-13 06:53:27 字数 325 浏览 1 评论 0 原文

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

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

我想做的是告诉调试器忽略某些 JavaScript 文件或单独的行,这样它就不会在我不感兴趣或已排除的代码上停止。有什么方法可以在 IE 中实现这一点(吐,吐!) - 或者你能建议更好的方法吗?

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?).

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

零崎曲识 2024-11-20 06:53:27

在 FireFox 中,此功能称为 “黑匣子” 将在 FireFox 25 中提供。它可以让我们完全满足您的需求。

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

通常我会在这里放置答案和操作方法而不是链接,但最终我会复制科林的帖子。

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.

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.

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

沉溺在你眼里的海 2024-11-20 06:53:27

您似乎正在寻找视觉事件

Looks like you're looking for Visual Event.

说不完的你爱 2024-11-20 06:53:27

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

您可以开始记录所有 JavaScript 事件 - 函数执行(使用源代码行等)并根据事件进行调试被解雇了。 google IO 演讲中还隐藏了其他非常方便的调试工具,也可以帮助您解决这个问题。

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.)

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.

久隐师 2024-11-20 06:53:27

如果您非常确定它是一个 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); 
    };
})

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

$('#your_div').click()

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:

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:

$('#your_div').click()
街道布景 2024-11-20 06:53:27

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

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

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.

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.

白首有我共你 2024-11-20 06:53:27

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文