From GreaseSpot Wiki
Jump to: navigation, search


What does Greasemonkey do?

Greasemonkey lets you add JavaScript code (called "user scripts") to any web page, which will run when its HTML code has loaded. Compared to writing extensions, user scripts often offer a light-weight alternative, requiring no browser restart on user script installation nor removal, and work with the common DOM API familiar to any web developer (with somewhat elevated privileges for doing cross domain XMLHttpRequest requests and storing small portions of private data). User scripts work more or less like bookmarklets automatically invoked for any URLs matching one or more glob patterns.

Where is Greasemonkey installed?

In the Greasemonkey directory of your profile directory.

Where is my profile directory?

See: profile directory.

Where is the Greasemonkey directory?

See: Greasemonkey directory.

Where are installed Greasemonkey user scripts stored?

See: scripts directory.

Why should I care about these directories?

Answers to other FAQs reference them.

Where is the link to report Greasemonkey bugs?

You'd be best served by starting with troubleshooting the problem yourself, then getting help from the community if that doesn't help.

If all else fails: https://github.com/greasemonkey/greasemonkey/issues

Using Greasemonkey

I installed a script that crashes Firefox. How can I get rid of it?

Edit scripts directory/config.xml and remove the <script>...</script> element for the offending script.

You may also want to delete the offending script itself from scripts directory.

How can I backup or share a copy of my installed scripts?

Just copy the contents of greasemonkey directory/gm_scripts/.

Authoring & Debugging

How do I get the browser to report script errors?

Navigate to about:config, and change the values of javascript.options.showInConsole and javascript.options.strict to true.

How can I log information (without using alert)?

  • You can use GM_log, which logs messages to the Error Console.
  • With the Firebug extension, you can do e.g. console.log("Link: %o", document.links[0]) to log messages and inspect elements. Don't forget to remove the Firebug code before distributing the script.
  • You can use dump() statements to print debugging info to the Firefox console.
  • You can set window.status = message_string, understanding that the status bar text is transient: many other processes within Firefox set it. (You may need to enable writing to status bar by setting dom.disable_window_status_change=false in about:config .)

How do I edit a script I'm working on?

  1. Open the the "Manage User Scripts..." dialog, from the "Tools" menu, the "Tools, Greasemonkey" menu, or the Monkey Menu, depending on the Greasemonkey version you use.
  2. Select the script you want to modify from the management dialog.
  3. Right click that script and select Edit.
  4. Edit the file and reload the target page to have it take effect.

You can also edit a script from Monkey Menu by right clicking on a script you want to edit.

How do I change the script editor?

See next question.

Why doesn't the Edit button open anything?

See next question.

Why doesn't the New Userscript command open anything?

The first time you click the Edit button or select the "New User Script" menu item, you will open a file-browse dialog box. This dialog box is asking you to select the program that is your text editor, used to edit the script. It is not asking you to select a script.

If you do select a script, Greasemonkey will attempt to execute it. Since it is not a text editor, it will not work. To fix this, you must reset what Greasemonkey thinks is your editor. You can do this from the options dialog (Tools -> Greasemonkey -> Greasemonkey Options -> Browse For Editor Program).

For Greasemonkey prior to version 0.9.0, use these steps:

  1. Open about:config
  2. Find the entry named "greasemonkey.editor". (It helps to start typing "greasemonkey" into the filter box.)
  3. Right click on that entry and choose "Reset" to empty it out.
  4. Try "Edit" or "New User Script" again. When the file-browse dialog appears, find the executable for your editor. For example:
    • On Windows, you may wish to browse to C:\Windows\system32\notepad.exe .
    • On Linux, you may wish to browse to /usr/bin/gedit , /usr/bin/kwrite , or /usr/bin/kate .
    • On Mac OS X, you may wish to browse to /Applications/TextEdit.app .

Yes, but how can I edit a script without going through Greasemonkey?

If you're the do-it-yourself type:

  1. Open the .user.js file in the scripts directory, where Greasemonkey stored the script when you installed it.
  2. Edit the file and reload the target page to have it take effect.

How do I determine the file my script is installed under?

  1. As per the earlier FAQ, use Greasemonkey to edit the script.
  2. Use whatever method is appropriate in your favorite text editor to determine where the file came from.

Or (if you're the do-it-yourself type):

  1. Open scripts directory/config.xml.
  2. Find the <Script> tag for the script you're interested in and note the value of its filename="..." attribute.used to
  3. Open the file at scripts directory/filename.

Can Greasemonkey be used to open local files?

No. Opening local files requires chrome-level privileges, which Greasemonkey scripts lack (aside from a small subset of functionality exposed through GM_* functions—see next question). A commonly-suggested workaround is to install a local web server and communicate with that.

Do Greasemonkey scripts have chrome privileges?

No. Scripts are considered to exist in a space between untrusted content like web pages and fully trusted content such as extensions. Thus, their special permissions are limited to the chrome-level privileges exposed by the GM_* API, like cross-domain XMLHttpRequest and persistence via GM_setValue(). You’ll have to write a full extension to make use of chrome-only features.