热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用Chromejavascript调试程序跟踪事件-TrackeventsusingChromejavascriptdebugger

Idonthaveaspecificusecasehere,butoccasionallyIhavebeeneitherhelpingoutsomeoneonSO

I don't have a specific use case here, but occasionally I have been either helping out someone on SO or seen a cool Javascript effect on a website and been curious about the code that drives it. However, the event that drives the code may not be immediately obvious. If I can't find the event handler then it can be really hard to find the js responsible for the effects I am interested in. Is there a quick way in the debugger to identify the events attached to an element and to drop a break point in when it fires?

我这里没有特定的用例,但偶尔我会帮助某人或者在网站上看到一个很酷的Javascript效果,并对驱动它的代码感到好奇。但是,驱动代码的事件可能不会立即显而易见。如果我找不到事件处理程序那么很难找到负责我感兴趣的效果的js。在调试器中是否有一种快速方法来识别附加到元素的事件并删除断点在什么时候开火?

So for example an event may exist on a structure something like so

因此,例如,事件可能存在于类似的结构上

Now I don't know if the event is bound to the img, span, li, ul or div itself. Chrome has the Event Listeners area, but I feel like it doesn't always contain events. Anything you guys do that allows you to quickly find the event and drop a break point into it?

现在我不知道事件是否绑定到img,span,li,ul或div本身。 Chrome有“事件监听器”区域,但我觉得它并不总是包含事件。你们做的任何事情都可以让你快速找到事件并给它留下一个断点?

3 个解决方案

#1


39  

yes there is!

就在这里!

find the element that is being reloaded and right click, choose inspect from context menu, then right click the html of the element (in the bottom firebugish pane), in the context menu there are options to:

找到正在重新加载的元素并右键单击,从上下文菜单中选择inspect,然后右键单击元素的html(在底部firebugish窗格中),在上下文菜单中有以下选项:

  • break on subtree modifications
  • 打破子树修改

  • break on attributes modifications
  • 打破属性修改

  • break on node removal
  • 打破节点删除

Article on awesome new dev features in chrome: http://elijahmanor.com/7-chrome-tips-developers-designers-may-not-know/

有关chrome中令人敬畏的新开发功能的文章:http://elijahmanor.com/7-chrome-tips-developers-designers-may-not-know/

#2


7  

If you have access to the .js, just add "debugger;" on its own line. Whenever Chrome (or FF) hits that, it'll trigger the debugger and let you walk through. Esp useful if you have some general idea which code will trigger the event. See http://beerpla.net/2009/12/17/how-to-make-firebugs-Javascript-debugger-break-inside-dynamic-Javascript-using-the-debugger-keyword-ie-chrome-too/ for more.

如果您有权访问.js,只需添加“调试器”;在自己的路线上。每当Chrome(或FF)点击它时,它都会触发调试器并让你走过。如果你有一些一般的想法,哪些代码将触发事件,Esp很有用。请参阅http://beerpla.net/2009/12/17/how-to-make-firebugs-Javascript-debugger-break-inside-dynamic-Javascript-using-the-debugger-keyword-ie-chrome-too/更多。

#3


0  

Right click on the element in chrome dev tools, and click on 'break on' , then you would see multiple selections such as sub tree modifications. Or you could also go to chrome//:tracing

右键单击chrome dev工具中的元素,然后单击“break on”,然后您将看到多个选项,例如子树修改。或者你也可以去chrome //:tracing


推荐阅读
author-avatar
阿什顿安抚_343
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有