使用Greasemonkey调试,获取实际行号 [英] Greasemonkey debugging, get real line numbers

查看:85
本文介绍了使用Greasemonkey调试,获取实际行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使Greasemonkey Userscript正常工作,但它不断抛出 遗失;陈述前" 在JavaScript错误控制台中.

I'm trying to get a Greasemonkey Userscript to work but it keeps throwing "missing ; before statement" in the Javascript error console.

Greasemonkey文档说应该忽略行号,但是由于脚本很长,所以知道错误发生在哪里将非常有帮助.我怎么知道?

The Greasemonkey docs say the line number should be ignored but since the script is quite lengthy it would be very helpful to know where the error occurred. How can I find out?

长话短说.行号在最新的Greasemonkey版本中是正确的.

So, long story short. Line numbers are correct in recent Greasemonkey versions.

推荐答案

最新版本的Greasemonkey似乎可以充分报告行号,但最好还是在Firebug控制台中调试并测试尽可能多的脚本.在Greasemonkey脚本中使用它.
而且,正如missingno所说, jsHint 可以很好地解决这类问题.

The latest editions of Greasemonkey seem to report line numbers adequately, but it is still best to debug and test as much of your script as possible in the Firebug console before using it in the Greasemonkey script.
And, as missingno said, jsHint can be good for catching these kinds of problems.

无论如何,假设我有一个像这样的脚本:

Anyway, suppose I have a script like this:

// ==UserScript==
// @name        _Debugging test
// @include     http://YOUR_SERVER/YOUR_PATH/*
// ==/UserScript==

unsafeWindow.console.log ('Line 1', 1 + 0);

unsafeWindow.console.log ('Line 2', 1 + 1);

unsafeWindow.console.log ('Line 3', 1 + 2);

unsafeWindow.console.log ('Line 4 **Throw error here**', 1 + 3 + nonExistantVariable);

unsafeWindow.console.log ('Line 5', 1 + 4);


当我在自己的两个系统(WinXP,FF:10.0.2,GM:0.9.18,Firebug:1.9.1,以及除GM:0.9.17以外的其他系统)上运行它时,我在Firebug的控制台上得到了它:


When I run it on 2 of my systems (WinXP, FF: 10.0.2, GM: 0.9.18, Firebug: 1.9.1, and the same except GM: 0.9.17), I get this on Firebug's console:


Line 1 1
Line 2 2
Line 3 3

以及在Firefox的错误控制台( Ctrl Shift J )上的

and this on Firefox's Error console (CtrlShiftJ):


单击链接将产生:


Clicking on the link yields:

缺少真正的调试功能,没有比这更好的了.

Absent true debugging capability, it doesn't get much better than that.

这篇关于使用Greasemonkey调试,获取实际行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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