Greasemonkey Manual:Other Useful Tools
|User Script Authoring|
|Other Useful Tools|
This page briefly describes tools that can help in writing user scripts. The descriptions link to more thorough explanations of the tools.
So far, tools are all targeted to help write scripts included in just a content page, and don't explicitly support the fact that Greasemonkey scripts run in a sandbox distinct from the base page. So, noting caveats of how these tools behave or misbehave with the Greasemonkey sandbox model is the major independent content of this page. (other than saying that the tool can work in the Greasemonkey world, that is.)
Note in particular that Greasemonkey does not expose a user script's global object which means no tool can see it and directly help in debugging, but it is possible to pass things to unsafeWindow for temporary help.
The DOM Inspector extension is a very powerful tool, that lets you fully explore the DOM (Document Object Model) tree of a page, and even gives to limited ability to edit and delete nodes and attributes. it can even inspect the XML tree for browser windows/sub windows, making it equally powerful for extension developers. It is an optional component in the Firefox installer, to get it you must use the Custom Installation option while installing Firefox. Access it via clicking "Tools>DOM Inspector".
It is good for examining where in a document's DOM changes need to be made and for looking at the changes after a script has run.
Note: If you click the "Inspect" button in the inspector, it will reload the URL next to it and no scripts will run. This can either be confusing or helpful.
Extensions that enhance the DOM Inspector are:
Note:: The XMLHttpRequest spy (logger) built into Firebug works for content pages only, and will not catch GM_xmlhttpRequest calls. To watch those you should run an extension like Tamper Data that shows all Firefox requests.
Strongly Note: On the GM lists there have been several reports that running Firebug may cause strange or random errors in GM scripts. If you run Firebug and experience something inexplicable one first step is to right click on the Firebug icon in the status bar, disable it, and then retry. For the reported cases this is fix enough. Anyway, if this fix works for you then please report it because nobody understands the root cause of the conflict.
- Firebug screws GM & frames/iframes?
- GM executes randomly, or doesn't execute at all
- script does not work until clicking a link
- Greasemonkey conflicting with Firebug?
- Is there a bug in GM_registerMenuCommand?
If you have problems installing or using Greasemonkey, installing or running a script, your first step is to turn on the Console and see if errors are reported there. When you activate the Console you may often find a long listing of lots of errors in pages that you have visited. Just click the "clear" button and reload the problem page to see what errors it alone causes.
The Greasemonkey API provides the function GM_log which lets scripts write messages that can be seen on the Console.
However if you understand sandboxing and the GM API, and don't feed to the Shell anything that involves such unclean complications it works fine. I.e. any clean part of a userscript that works will work in the Shell. The converse is not true - something working in the shell does not mean it will work in a userscript because it might not follow the implicit rules of cleanliness.
The Tamper Data extension lets one see the details of the get and put traffic caused by a page.
The XPather extension helps a script writer find and test out XPath expressions for use in scripts. It is not accessed through the Tool menu, instead it is integrated into the DOM Inspector and also can be found in the right-click menu.