Look below for an updated method of using the scripting system!The following examples will demonstrate how to use the script injection feature in MozNET.
You're probably wondering about
__doMozJSPostback(...) in the examples above.
__doMozJSPostbackin your script as this is how MozNET receives the values from your injected code.The parameters passed to
__doMozJSPostback are the name of the script (_SimpleScript_ in the examples above) and the value(s) you want returned to your code. You cannot return objects such as nodes or elements. To return multiple values you can use JSON string notation or a comma separated string or whatever other method you can think up and works for you.
MozScriptEventArgs returns the
MozWindow instance in which the injected script was ran, the name of the script andthe results, if any, returned by your script. Results are returned as a string.
Although the system is far from perfect, it's 100% better than what is currently available in the GeckoFX, OGS and other such wrappers.
Also, keep in mind that InvokeScript is a blocking method so watch what you're doing in your scripts because it will 'hang' your UI while they run.
This scripting system is also readily available for use directly from your applications' location bar.
When MozNET receives a url prefixed with
MozNet gives you unrestricted access to all, previously declared interal/private, native XPCom interfaces. This gives you more flexibility than was ever possible in previous releases of MozNET and all releases of GeckoFX and other wrappers. Using this flexibility you'll be able to access your custom XPCom components from either the MozNet source code, for a cleaner approach, or directly from your application.
Starting with the latest release, R18 at the time of this writing, the scripting system has been enhanced to allow inline return values from your injected scripts!
A quick example is as follows: