Which JavaScript back end to use. Currently, the only two back ends available are JE, a pure-Perl JavaScript interpreter, and WWW::Scripter::Plugin::SpiderMonkey (that back end is bundled separately). The SpiderMonkey back end is just a proof-of-concept as of July, 2010, but may become the default in a future version. JE is now the default.

If this option is not specified, either JE or SpiderMonkey will be used, whichever is available. It is possible to write one's own bindings for a particular JavaScript engine. See below, under "BACK ENDS".

Pass to this option a reference to a subroutine and it will be run every time a new JavaScript environment is initialised. This happens after the functions above have been created. The first argument will be the WWW::Scripter object. You can use this, for instance, to make your own functions available to JavaScript.

WWW::Scripter's use_plugin method will return a plugin object. The same object can be retrieved via $w->plugin('JavaScript') after the plugin is loaded. The same plugin object is used for every page and frame, and for every new window derived from the WWW::Scripter object. The following methods can be called on that object:

This evaluates the JavaScript code passed to it. The WWW::Scripter object is the first argument; the string of code the second. You can optionally pass two more arguments: the file name or URL, and the first line number.

Sets the named variable to the value given. The first argument is the WWW::Scripter object. The last argument is the value. The intervening arguments are the names of properties, so if you want to assign to a property of a property ... of a global property, you can pass each property name separately like this:

This creates a new global JavaScript function out of a coderef. This function is added to every JavaScript environment the plugin has access to. Pass the WWW::Scripter object as the first argument, the name as the second and the code ref as the third.

Instead of using this method, you might consider WWW::Scripter's class_info method, which is more general-purpose (it applies also to whatever other scripting languages might be available).

With this you can bind Perl classes to JavaScript, so that JavaScript can handle objects of those classes. These class bindings will persist from one page to the next.

You should pass a hash ref that has the structure described in HTML::DOM::Interface, except that this method also accepts a _constructor hash element, which should be set to the name of the method to be called when the constructor function is called within JavaScript; e.g., _constructor => 'new'.

It has to create a JavaScript environment, in which the global object delegates to the window object for the members listed in %WWW::Scripter::WindowInterface.

When the window object or its frames collection (WWW::Scripter::Frames object) is passed to the JavaScript environment, the global object must be returned instead.

This method can optionally create window, self and frames properties that refer to the global object, but this is not necessary. It might make things a little more efficient.

Finally, it has to return an object that implements the interface below.

The back end has to do some magic to make sure that, when the global object is passed to another JS environment, references to it automatically point to a new global object when the user (or calling code) browses to another page.

For instance, it could wrap up the global object in a proxy object that delegates to whichever global object corresponds to the document.

These correspond to those listed above for the plugin object. Unlike the above, though, this set is not passed a window as its first argument. Also, bind_classes and new_function are only expected to act on a single JavaScript environment. The plugin's own methods of the same names make sure every JavaScript environment's methods are called.

new_function must also accept a third argument, indicating the return type. This (when specified) will be the name of a JavaScript function that does the type conversion. Only 'Number' is used right now. This requirement may be removed before version 1.

This method needs to turn the event handler code in $code into an object with a call_with method and then return it. That object's call_with method will be called with the event target and the event object as its two arguments. Its return value, if defined, will be used to determine whether the event's preventDefault method is called.

The function's scope must contain the following objects: the global object, the document, the element's form (if there is one) and the element itself.

If the $code could not be compiled, this method must set $@ and return undef, just like eval.