Here is a good article to avoid common mistakes due to the differences between "normal" JS and Greasemonkey.
The most important things in the beginning:
- Do not use functions as strings, for example:
window.setTimeout("my_func()", 1000); , but rather window.setTimeout(my_func, 1000); or window.setTimeout(function(){doSomething(); doSomethingOther();}, 1000); - Do not set
element.onclick , but rather element.addEventListener("click", my_func, true); Some code that usually returns various DOM objects in the Greasemonkey environment returns those objects that are wrapped in an XPCNativeWrapper. This is for security reasons.
Some methods and properties are transparent, and you can call them on a wrapped object, but some do not. Read the article on how to get around this; you can also use (this is not recommended at all, but for testing, etc.) wrappedJSObject. When obj.something / obj.something() does not work in Greasemonkey, try obj.wrappedJSObject.something / obj.wrappedJSObject.something() .
source share