如何使用Firebug扩展debuggingGreasemonkey脚本?

我没有find用Firebug扩展debuggingGreasemonkey脚本的方法。

有谁知道如何做到这一点 ?

谢谢。

更新: Mene + Shuman修复程序现在已经被Firefox 30和Firebug 2破坏.Firefox 31 可能会提供解决方法(将进行调查)。 同时,使用下面列出的“常规解决方法策略”。


更新:这个答案现在已经过时了。

如果你打开about:config
extensions.firebug.filterSystemURLs设置为false
那么你可以像使用Firebug一样debuggingGreasemonkey脚本。

这个工作@grant模式。

看到梅恩的回答 – 在舒曼的协助下 。



老答案:

由于Greasemonkey在沙箱中运行,Firebug无法看到它。 有没有简单的方法来解决这个问题。

一般的解决方法策略:

  1. 首先在Firebug的JavaScript控制台中testing不使用GM_函数的GM脚本的所有部分。 最大限度地减lessGM_函数的使用,而不要使用GM_log()

  2. 所有Firebug的consolefunction都可以在GM脚本中使用。

目前的Firefox和Firebug现在可以debugging当前的Greasemonkey脚本,就像其他的JavaScript一样。 只需在下拉菜单中find*.user.js脚本。 控制台也可以工作。

至less在Firefox 28.0和Firebug 1.12.7上可用; 我还没有尝试过早期版本。

有限情况调试的屏幕截图

注意:为了使其工作,您可能必须将extensions.firebug.filterSystemURLs设置为false。 请参阅Firebug错误跟踪器中的“分析Greasemonkey脚本”。 (感谢舒曼 )

 var e = document.createElement("script"); e.src = 'http://www.xxxxxxxx.com/yyyyyyyy.js'; e.type="text/javascript"; document.getElementsByTagName("head")[0].appendChild(e); 

你可以把它添加到你的xxx.user.js中,并将其安装在greasemonkey中。

然后,你可以debugging你的js,如你所愿。

这里没有其他解决scheme为我工作,但Jan Odvarko关于如何debuggingFirefox扩展的答案对于GreaseMonkey脚本来说也是完美的:

在Firefox 19或更高版本中,可以在浏览器本身上使用内置的JSdebugging器。 转到about:config并设置以下两个首选项:

 devtools.chrome.enabled: true devtools.debugger.remote-enabled: true 

重新启动浏览器后,可以通过工具> Web开发人员>浏览器debugging器访问浏览器debugging器。

(请注意,您必须接受传入的连接)

更多信息,请访问: https : //developer.mozilla.org/en/docs/Debugging_JavaScript

然后,只需search您的脚本的名称,并开始debugging。

Chromebug可以看到沙盒脚本, http: //getfirebug.com/wiki/index.php/Chromebug_User_Guide,但是我没有在Greasemonkey上试过。

它可以使用本地的Firefoxdebugging器,就像之前提到的那样。 以下是Firefox的现代版本的说明。

about:config设置以下首选项:

  devtools.chrome.enabled: true devtools.debugger.remote-enabled: true devtools.debugger.prompt-connection: false 

打开全局脚本debugging器窗口: Open Menu – > Developer – > Browser Toolbox – > Debugger (或Ctrl + Shift + Alt + I )。

search您的脚本的名称,并开始debugging 。

– 这个答案已经过时了,请使用@Brock Adams解决scheme –

从外部加载主脚本,而不是通过GM运行。 所以你只是用GM来注入脚本。

这是@bigml和@ Yuval的解决scheme之间的混合,它使用jQuery。 它也适用于框架。

 // ==UserScript== // @name My GM script // @include The website I want this to run on // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // ==/UserScript== $(document).ready(function() { // fetch jquery dependent scripts using $.getScript() }); 

我试过ChromeBug,它似乎没有工作。

在FireBug中,通过在我的GM代码中添加“debugging器”,我获得了成功的起点。 这会导致一个断点,我可以检查堆栈上的variables,但正确的文件不显示,所以我不能步骤或任何东西。

我已经用FirebugMonkey(https:// addons.mozilla.org/en-US/firefox/addon/13623/)获得了最好的成功,我刚刚开始对GreaseMonkey脚本进行基本的debugging,这要归功于最近的一些解释由f0rsvinn评论扩展页面。 以下是我刚刚在http://groups.google.com/group/greasemonkey-users/browse_thread/thread/994cfa58c79d222上发布的说明:;

我从来没有想到,它的工作方式是通过在脚本周围创build自己的沙盒而不是使用Greasemonkey,你实际上必须关掉GM。 有一些通用汽车方面的东西,但不会工作,因为脚本真的不在GreaseMonkey。 作为一个例子,GM_getValue返回undefined。

尽pipe如此,它仍然适用于基本的debugging – 而且总比没有好。

使用步骤如下:

  1. 安装FireBug 1.5.4(以后的版本似乎不工作)
  2. 安装FireBugMonkey
  3. 使用FireBugMonkey中的脚本pipe理器来select要debugging的文件
  4. 禁用GreaseMonkey(脚本将在FireBugMonkey中运行,而不是
  5. 的GreaseMonkey)
  6. 启用FireBugMonkey
  7. 在FireBug中启用脚本

您在ScriptManager中添加的脚本应该在FireBug脚本列表中可见。

类似于@ bigml的build议,如果你设置了一个本地web服务器(apache)来为userscript文件提供服务,那么你可以运行它unrivileged,然后在你的脚本中添加一些内容:

 if (typeof GM_addStyle == "undefined") { loadScript("http://localhost/path/to/script.user.js"); } else { runScript(); } function loadScript(url) { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; document.getElementsByTagName('head')[0].appendChild(res); } function runScript() { // ... whatever your userscript does ... } 

当然,你不会在特权的情况下运行。 但是这样你可以像任何其他脚本一样轻松地连续debugging脚本。

正如其他人所说,你可以设置一个简单的HTTP服务器,并使用Greasemonkey将其提供给你的页面,如下所示:

 function loadScript(url) { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; document.getElementsByTagName('head')[0].appendChild(script); } 

WEBrick和Python -m SimpleHTTPServer对此很有帮助。 我们还可以通过在GreaseMonkey中的文档中添加一个自定义事件处理程序来将GM _…函数公开给脚本:

 function gMHandler(e){ GM_log(e.detail.message); e.detail.response = "Hi!" } document.addEventListener("gM", gMHandler, false); 

然后在服务脚本中,在任意DOM元素上引发此事件将运行处理程序并修改元素的响应参数:

 $(document).ready(function() { var event = new CustomEvent( "gM", { detail: { message: "Hello World!" } bubbles: true, cancelable: true, } ); document.getElementById("AnyElement").dispatchEvent(event); alert("Response was: " + event.detail.response); });