Language version and runtime environment
You can write scripts and EJS templates to implement Solve for All plugins, using either ECMAScript 6 or ECMAScript 5 syntax. In particular,
- Scripts should be written in ES6 strict mode. Scripts may also optionally be written in TypeScript (not extensively tested yet), which is always strict.
- EJS templates should be written in ES6 non-strict mode
In particular, the
XML class of
(but not XML literals) are available in the environment.
In your uploaded scripts and templates, you can use almost all
ES6 features without worrying about language support in Rhino, since
uploaded scripts and templates are always converted to plain ES5 first.
The following ES6 features are partially supported, or unsupported:
- In ES6, many methods and properties were added to built-in classes and additional built-ins were added, but these aren't all available in Rhino. For now, it's best to use Underscore to get most of this functionality.
- Unicode-aware regexes are not supported
Also, code that you
eval() needs to
conform to Rhino's natively supported syntax, which is
You can use some, but not all, ES6 features like
let declarations and some destructuring operations.
All scripts have access to the following libraries:
|Underscore.js||1.8.3||Available as the
|Underscore Inflection||1.4.0||Pre-mixed into the
|Underscore String||2.3.3||Pre-mixed into the
Less commonly used libraries can be imported via
require() calls, like this:
const moment = require('moment');
just like in Node.js.
Currently the available libraries are:
|Module Name||Project Name||Version|
||URI.js (includes Second Level Domain support)||1.14.1|
To request a library be added to either the built-ins or the
importable libraries, fork the
example plugins project,
and add your library to
test_harness/modules (for importable libraries).
Note that we prefer that libraries be importable to reduce the startup
with an explanation of why you need the library, and we will add it
as long as it makes sense.
For convenience, all of the functions and constants in the
Math object are
defined in the global namespace. For example,
max is an alias for
So you can write
max(x, y) instead of
These special aliases are also defined:
pi: Alias for
e: Alias for
ln: Alias for
- Access to Java classes (normally present in a Rhino environment) is disabled.
- Scripts are given a finite amount of memory and a limited time to run before they are killed.
Don't use your script to perform non-answer engine related functionality, like attacking the system, stealing user data, or mining Bitcoin. If we detect abuse, we may disable your account or take other preventative measures. For more details, see the Terms of Service.
If a script does not execute properly or is killed before it can finish, the behavior will be as follows:
|Plugin Type||Behavior if Script Fails|
|Content Recognizer||Nothing is recognized by the failed Content Recognizer; no recognition keys are added to the answer results.|
|Trigger||The failed Trigger does not activate.|
|Answer Generator||No answer results are produced.|
If you're writing an Answer Generator, take advantage of the Console API to see log messages.
For development or debugging of your scripts, you can enter an answer query
For example, the query
uses Underscore String to convert a string into camel case
(try it). Note that this code is passed to
eval() so the syntax must be directly understood by