global var not accessible from greasemonkey script

204 views
Skip to first unread message

Jim Auldridge

unread,
Nov 30, 2010, 9:29:29 AM11/30/10
to greasemonkey-users
Hi everyone,

I have a greasemonkey script running on a page w/ jQuery. When I run
the body of the script in my Firebug console, it works perfectly. When
in greasemonkey, it runs, but does not work. Debugging shows that
window.jQuery is undefined in the context of the script.

The actual script:
http://pastie.textmate.org/private/hxgo5d2jeppd3k2n1v9vg

Any thoughts?

Thanks,
Jim

Anthony Lieuallen

unread,
Nov 30, 2010, 9:33:56 AM11/30/10
to greasemon...@googlegroups.com
On 11/30/10 09:29, Jim Auldridge wrote:
> Any thoughts?

This is intended behavior. Read the documentation.

http://wiki.greasespot.net/

Jim Auldridge

unread,
Nov 30, 2010, 9:46:29 AM11/30/10
to greasemonkey-users
I suppose you mean this page http://wiki.greasespot.net/Security

What's very confusing is that some global variables are accessible
from within the greasemonkey script. Further, this excerpt from the
docs is also quite confusing:

>>The window object functions as the global scope in JavaScript. For user scripts, this global
>>window option is in fact a "deep wrapper" of the content window. The content window can be
>>accessed by user scripts, but only indirectly through the wrapper. The unsafeWindow property
>>is a direct line to the actual content window.

What does it mean that I can "indirectly" access the content window
through the wrapper? This would be preferred, I assume, as opposed to
using the "direct" means of unsafeWindow?

Thanks,
Jim

Anthony Lieuallen

unread,
Nov 30, 2010, 11:10:43 AM11/30/10
to greasemon...@googlegroups.com
On 11/30/10 09:46, Jim Auldridge wrote:
> I suppose you mean this page http://wiki.greasespot.net/Security
>
> What's very confusing is that some global variables are accessible
> from within the greasemonkey script. Further, this excerpt from the
> docs is also quite confusing..

That page could definitely be improved.

But most importantly: no; "global variables" are not accessible. The
normal environment that the browser provides (window, document, etc) are
available. Anything that the page adds is not: it could be adding
something evil to break the script, or worse to make the script actively
cause problems (privacy, security, or otherwise) for the user. Keep
reading, especially about XPCNativeWrappers, and learn about expando
properties (this is actually probably "global variables" as you refer to
them).

Also valuable:
http://wiki.greasespot.net/Category:Coding_Tips:Interacting_With_The_Page

Jim Auldridge

unread,
Nov 30, 2010, 11:14:17 AM11/30/10
to greasemon...@googlegroups.com
Thanks for your continued assistance.  The other thing which confused me in all this is that I have written several user scripts before, but only one or two were for Grease Monkey itself. Other places where I have worked with them, such as Fluid App, have not put such restrictions in place.  I now understand why they are there, I have just never run into them.

Thanks again,
Jim




--
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To post to this group, send email to greasemon...@googlegroups.com.
To unsubscribe from this group, send email to greasemonkey-us...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en.




--
Jim Auldridge
 11012 Lincoln Ave
 Hagerstown MD 21740
 240.520.0240 (m)
 auldr...@gmail.com
 http://jaaulde.com
Reply all
Reply to author
Forward
0 new messages