V8 is a JavaScript engine from Google which is used in the Chrome Browser, Node.js and other applications. It implements ECMAScript (the JavaScript standard) and WebAssembly.
ClearScript from Microsoft is a dotNET assembly that makes it easy to add this kind of scripting to your UiPath workflow, because it contains the V8 engine in its native assembly packages. Compared to the approach of using Node.js, described in my tutorial, here the V8 engine is used via ClearScript and the integration can be done via the Invoke Code activity.
Preparation
First of all it is necessary to add the ClearScript packages via Manage Packages.
All packages and its dependencies are available at the nuget repository.
Now it is necessary to copy the native V8 engine into a path, where the V8 assembly of ClearScript expects it. In my case I use the win-x64 assembly.
All preparations are done now and we can use the V8 JavaScript in our UiPath workflow.
Using
In the next step we import the necessary namespaces Microsoft.ClearScript, Microsoft.ClearScript.JavaScript and Microsoft.ClearScript.V8.
Now we can use the example code from the ClearScript project, or in this case only a part of it.
// Begin----------------------------------------------------------------
using (var engine = new Microsoft.ClearScript.V8.V8ScriptEngine()) {
// expose a host type
engine.AddHostType("Console", typeof(Console));
engine.Execute("Console.WriteLine('{0} is an interesting number.', Math.PI)");
}
// End------------------------------------------------------------------
And it delivers exact the expected result.