Troubleshooting (Script Authors): Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
Aavindraa (talk | contribs)
ouch, lots of "documents" and not "document"'s
Aavindraa (talk | contribs)
adding the character set issue, workarounds, use wikipedia format for links, removing broken / irrelevant links. remove last link as well?
Line 110: Line 110:
</pre>}}
</pre>}}


== Links ==
== Character set ==
Various issues can arise when working in the wrong character set. In general, writers are advised to use the standard utf-8 format, which isn't supported in the latest version of Windows Notepad. Other workarounds include using JavaScript to parse characters which would otherwise be invalid in other formats, from integer values.


* http://greaseblog.blogspot.com/2005/12/troubleshooting-064.html
{{Good samp |1=<pre style="border: none; margin: inherit;">
* http://dunck.us/collab/GreaseMonkeyUserScripts#head-010b85ad56b34c34c7c2a3b2436c740e30428ed5
var values = [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33];
* http://dunck.us/collab/GreaseMonkeyUserScripts#head-4ac4d1e80f8bbd66bf4f1fbea77ea2390b6a2870
for(var i = 0; i < values.length; i++) {
* http://www.brockman.se/writing/method-references.html.utf8
values[i] = String.fromCharCode(values[i]);
}
alert(values.join(""));
</pre>}}
 
== External links ==
 
* [http://greaseblog.blogspot.com/2005/12/troubleshooting-064.html Troubleshooting Greasemonkey 0.6.4]

Revision as of 08:48, 3 October 2009

The article Avoid Common Pitfalls in Greasemonkey covers some of the most common problems people come across when writing user scripts.

If your problem is not listed, please ask on the mailing list.

Changes don't take effect when editing a script

You may be editing your original copy of the script, not the installed copy. Once you create and install a script, you need to follow these steps to make sure you're editing the installed, active copy.

Also, changing the include and exclude rules in the metadata block of the installed script does not do anything, as the script metadata is only accessed during installation. The script must be re-installed (or config.xml edited manually) for these changes to take.

Note: You can change the include and exclude rules in the Manage User Scripts window and those changes will take effect.

Variables change before a GM_xmlhttpRequest or setTimeout callback runs

Problem example:

Template:Bad samp

The request is asynchronous, meaning the rest of the code doesn't wait for it to complete. The for keeps running as the request loads. When the request for the first link on the page completes and the onload callback function runs, the link variable might point to a different link altogether, typically the last one (since the for loop completes much quicker than the HTTP requests).

One solution is to pass those values that you want unchanged into a function surrounding the request, as arguments. Then they will be in a different scope, and will no longer be changed from the outside.

Solution example with named function: Template:Good samp Solution example with anonymous function:

Template:Good samp

Solution example with iteration in the "onload" function. Note that this processes each element one by one.

Template:Good samp

Component not Available errors

These are usually caused by attempting to access an element's event handlers (onclick, onkeydown, etc.) directly, rather than through addEventListener. GreaseMonkey 0.5 and above require the use of addEventListener. For details, see XPCNativeWrapper.

Form POST data

When using GM_xmlhttpRequest to POST form data, remember to add the Content-Type parameter:

Template:Good samp

Character set

Various issues can arise when working in the wrong character set. In general, writers are advised to use the standard utf-8 format, which isn't supported in the latest version of Windows Notepad. Other workarounds include using JavaScript to parse characters which would otherwise be invalid in other formats, from integer values.

Template:Good samp

External links