How to debug Greasemonkey script with Firebug extension?

I have not found a way to debug Greasemonkey scripts with the Firebug extension.

Does anyone know how to do this?

Thank.

+43
debugging greasemonkey firebug
Aug 16 '10 at 1:32
source share
10 answers

Update: The Mene + Shuman fix is ​​now corrupted by Firefox 30 and Firebug 2. Firefox 31 may provide workarounds (will investigate). In the meantime, use the "General workarounds" listed below.




Update: This answer has been deprecated.

If you open about:config and
set extensions.firebug.filterSystemURLs to false
then you can use Firebug to debug a Greasemonkey script like any other.

This works regardless of @grant mode.

See Answer to Mene - with Schumann .







Old answer:

Since Greasemonkey runs in the sandbox, Firebug cannot see it. It is not easy.

General workaround strategies:

  • Check out all parts of the GM script that don't use the GM_ functions, first in the Firebug JavaScript console. Minimize the use of GM_ functions and do not use GM_log() at all.

  • All Firebug console functions work fine from a GM script.

+24
Aug 16 '10 at 2:45
source share

Now Firefox and Firebug can now debug current Greasemonkey scripts, like any other javascript. Just find the *.user.js script in the dropdown menu. The console also works.

This works at least on Firefox 28.0 and Firebug 1.12.7; I have not tried earlier versions.

Screenshot of limited-case debugging


Note. To make it work, you probably need to set extensions.firebug.filterSystemURLs to false. See "Profiling Greasemonkey Scripts" in Firebug, an error tracker. (Thanks to Shuman )

+8
Feb 27 '14 at 13:19
source share
 var e = document.createElement("script"); e.src = 'http://www.xxxxxxxx.com/yyyyyyyy.js'; e.type="text/javascript"; document.getElementsByTagName("head")[0].appendChild(e); 

you can add this to your xxx.user.js and set it to greasemonkey.

Then you can debug your js as you wish.

+7
Oct 31 '11 at 9:23
source share

No other solutions here worked for me, but Jan Odvarko's answer on how to debug Firefox extensions worked great for GreaseMonkey scripts:

In Firefox 19 or later, you can use the built-in JS debugger in the browser itself. Go to: config and set the following two prefs:

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

After restarting the browser, you can access the browser debugger through Tools> Web Developer> Browser Debugger.

(note that you must accept the incoming connection)

See also: https://developer.mozilla.org/en/docs/Debugging_JavaScript

Then just find the name of your login name and start debugging.

+4
Aug 29 '16 at 20:42 on
source share

Chromebug can see sandboxed scripts, http://getfirebug.com/wiki/index.php/Chromebug_User_Guide , but I have not tried it on Greasemonkey.

+3
Aug 16 '10 at 3:24
source share

This can be done using the Firefox native debugger, as mentioned earlier. The instructions below are for modern versions of Firefox.

Set the following settings in about:config :

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

Open the global debug window script: Open MenuDeveloperBrowser ToolboxDebugger (or Ctrl + Shift + Alt + I ).

Find the name of your login name and run debugging .

+3
Nov 23 '16 at 12:24
source share

- this answer is deprecated, use @Brock Adams solution above -

Download your main script from the outside, and don't run it through GM. That way you are just using GM to enter the script.

This is a bit of a hybrid between @bigml and @Yuval's solution, and it uses jquery. He also works in frames.

 // ==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() }); 
+2
Jul 29 '12 at 23:52
source share

I tried ChromeBug, it doesn't seem to work.

With FireBug, I had a starting point for success by adding a "debugger" to my GM code. This causes a breakpoint, and I can check the variables on the stack, but the right file is not displayed, so I can neither step, nor anything.

I had the best success with FirebugMonkey (https: // addons.mozilla.org/en-US/firefox/addon/13623/) that I just got to do the main debugging of GreaseMonkey scripts thanks to some explanation in a recent comment on the page extensions f0rsvinn. Here are the instructions I just posted at http://groups.google.com/group/greasemonkey-users/browse_thread/thread/994cfa58c79d222 :

It never occurred to me that the way it works is to create your own sandbox around the script instead of using Greasemonkey's, you really need to disable GM. There are some aspects of GM that won't work because the script is really not in GreaseMonkey. For example, GM_getValue returns undefined.

However, it works for basic debugging - and better than nothing.

Use steps are as follows:

  • Install FireBug 1.5.4 (later versions do not seem to work)
  • Install FireBugMonkey
  • Use the script manager in FireBugMonkey to select the files you want to debug
  • Disable GreaseMonkey (scripts will run inside FireBugMonkey, not
  • GreaseMonkey)
  • Enable FireBugMonkey
  • Enable Scripts in FireBug

Scripts added to ScriptManager should be visible in the FireBug Script List.

+1
Nov 10 2018-10-10T00:
source share

Like the @bigml clause, you can run it unprivileged if you set up a local web server (apache) to work with the usercript file, and then add something along the lines in your user script:

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

Of course, you will not work in a privileged context. But this way you can easily continuously debug a script like any other script.

+1
Mar 09 '12 at 12:56
source share

As others have said, you can set up a simple HTTP server and serve it on your page using Greasemonkey:

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

WEBrick and Python -m SimpleHTTPServer are good for this. We can also provide GM _... functions for the script by adding a special event handler to the GreaseMonkey document:

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

and then in the served script, raising this event on an arbitrary DOM element will trigger the handler and change the element's response parameter:

 $(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); }); 
0
Aug 17 '16 at 15:26
source share



All Articles