在Javascript中在运行时动态设置断点 [英] Setting breakpoints dynamically at runtime in Javascript

查看:272
本文介绍了在Javascript中在运行时动态设置断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

webb浏览器中的firebug和内置控制台都可以在运行Javascript代码时设置断点,因此您可以像使用任何其他语言一样调试它。

Both firebug and the built in console in webkit browsers make it possible to set breakpoints in running Javascript code, so you can debug it as you would with any other language.

我想知道的是,如果有任何方法可以指示firebug或webkit我想在运行时在文件Y中的第X行设置断点,并且能够检查特定范围内的变量我暂停了。

What I'm wondering is if there is any way that I can instruct firebug or webkit that I'd like to set a breakpoint on line X in file Y at runtime, and to be able to examine variables in the specific scope that I have paused in.

我需要能够在Chrome(或任何其他webkit浏览器)和Firefox中使用的东西。对于后者,Firebug是可接受的依赖。支持IE不是必需的。

I need something that can work in both Chrome (or any other webkit browser) and Firefox. For the latter Firebug is an acceptable dependency. Supporting IE is not a requirement.

我一直在构建一个浏览器内的IDE(感兴趣的快速视频: http://www.youtube.com/watch?v=c5lGwqi8L_g )并希望给它一点肉。

I've been building an in-browser IDE ( quick video for the interested: http://www.youtube.com/watch?v=c5lGwqi8L_g ) and want to give it a bit more meat.

我尝试过的一件事就是添加调试器; 作为用户设置它们的额外行,但这不是真正的理想的解决方案。

One thing I did try was just adding debugger; as an extra line where users set them, but this isn't really an ideal solution.

推荐答案

我想你肯定可以使用远程调试协议为webkit浏览器做到这一点。这是基于websocket连接和来回的json消息协议。

I'd say you can definitely do this for webkit browsers using the remote debugging protocol. This is based on a websocket connection and a json message protocol that goes back and forth.

您可以阅读公告和整个协议架构

Chrome还在其内部提供了有关此内容的更多信息a href =https://developer.chrome.com/devtools/docs/remote-debugging =nofollow>远程开发者工具文档。

Chrome also offers more information about this inside its remote developer-tools docs.

例如,对于调试器域,您可以看到你可以使用 Debugger.setBreakpoint Debugger.setBreakpointByUrl 调试器.setBreakpointsActive 使用断点。

For the debugger domain, for instance, you can see how you can use Debugger.setBreakpoint, Debugger.setBreakpointByUrl and Debugger.setBreakpointsActive to work with breakpoints.

另一方面,Mozilla似乎正在研究这个问题,你可以在 https://developer.mozilla.org/en-US/docs/Tools/Debugger-API https://wiki.mozilla.org/Remote_Debugging_Protocol 虽然我不知道完成状态它是

On the other hand, Mozilla also seems to be working on this as you can see in https://developer.mozilla.org/en-US/docs/Tools/Debugger-API and https://wiki.mozilla.org/Remote_Debugging_Protocol though I don't know the completion status of it.

在这种情况下,您可以使用 Debugger.Script API setBreakPoint,getBreakPoint,getBreakpoints,clearBreakpoints和clearAllBreakpoints

In this case, you can work with breakpoints using the Debugger.Script APIs setBreakPoint, getBreakPoint, getBreakpoints, clearBreakpoints and clearAllBreakpoints

我希望这有助于你你继续前进。

I hope this helps you move forward.

这篇关于在Javascript中在运行时动态设置断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆