[Greasemonkey] Access netscape.xxx objects?

esquifit esquifit at googlemail.com
Wed May 3 20:26:03 EDT 2006


I think the problem here is that, in a normal js script, netscape is a
global object of the window object, whereas in the context of GM, "window"
is a XPCNativeWrapper around the actual window object, and as such it lacks
some of its original properties and functions, netscape being probably one
of these.

If you just want to execute some function in the context of the "real"
window, use

unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege(...)

instead.  This approach, as it name suggests, is not secure. Alternatively
you can use GM_executeContentScript() (currently only in CVS, not part of
any official release of GM, and undocumented as well), which basically
amounts to executing a javascript function as if it had been typed in the
location bar, in other words, as a bookmarklet:

window.location.href = "javascript:
netscape.security.PrivilegeManager.enablePrivilege( 'UniversalXPConnect')";

This means that the script runs in the context of the loaded page (outside
GM), and consequently there is no possibility of getting information from
the page into GM.  In your example, you could get the content of the
clipboard and use it right there in the function you are executing, but you
would not be able to pass its content to the main GM script for further
processing.

Also remember that, irrespective of the method you use, your browser must
have  codebase principals enabled (i.e. the
signed.applets.codebase_principal_support preference set to true) for
netscape.security.PrivilegeManager.enablePrivilege to have any effect, and
this is highly insecure, it its really only intended for testing of script
that will eventually be signed in some way.

2006/5/2, Luca <lucafbb at gmail.com>:
>
> Hi all list, I'm near new in greasemonkey devel, and I found a big problem
> that I want to resolve (of course) but first of all I want to understand
> the
> meaning of this error.
> I looked google for a while, but I found nothing!
>
> I must create a script to enable the clipboard accesso from firefox. I use
> code like this:
>
>     netscape.security.PrivilegeManager.enablePrivilege(
> 'UniversalXPConnect'
> > );
> >     this.clipboardstring.data = text;
> >     var transfer = Components.classes['@
> > mozilla.org/widget/transferable;1'].createInstance(
> > Components.interfaces.nsITransferable );
> >     ...
>
>
> I get an error on the first line. In a normal js script, firefox ask me if
> I
> want to use this rescricted code and the work normally. If I use this in a
> gm script, I get an error immediatly that say me that netscape is not
> defined.
>
> 1) How to correct this?
> 2) Why I cant use those objects in a gm script?
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list