Embedding JavaScript Engine into .Net

Sandbox JavaScript in C# Code and execute it

From my own experience, for simple things Jurassic works like a charm and it's a JavaScript that can be used to run-time compile JavaScript and call functions, variables or whatever.

For example, taken from their own doc pages:

var engine = new Jurassic.ScriptEngine();
Console.WriteLine(engine.Evaluate("5 * 10 + 2"));

There're other options which involves embedding a full JavaScript engine, but AFAIK and reading your question's requirement, it seems like Jurassic should work in your scenario and you get the advantage of using a managed JavaScript compiler written in C# so there's no other dependency than the BCL from .NET and Jurassic itself.

Embedding Chakra Javascript Engine in Windows 8 / .Net 4.5

There is no mechanism to do this that has been released or talked about. For now, it is available only in IE and to Metro style apps. There isn't even a Windows Scripting Host style exposure of it.

What is it about Chakra that you want in your scripting?

How can I execute Javascript code in C# (.NET)

The Chromium Embedded Framework has C# bindings: CefSharp

It will run your JavaScript and it can work without UI or rendering the result if you need:

https://cefsharp.github.io/

The FAQ contains a specific answer to your question, too:

https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#CallJS

Is there a port of the Rhino JavaScript engine for .NET

You should probably use JScript - Microsoft's implementation of JavaScript, which is a full .NET language.

EDIT: it turns out the question is a duplicate. Some specific suggestions: use Managed JScript, or use MSScriptControl.ScriptControlClass in JScript mode.

How to embed javascript chat client into C#

You can open a window with the WebBrowser Control

and navigate to the a local html file with the javascript chat code in it. Or you could navigate to a remote url with the code in it.

On windows the web browser control uses IE under the hood. I do not know how this would work on other systems.

If you need other types of browser support there is also Awesomium which is more like Chrome's rendering engine, and GeckoFx which is more Firefox's engine.

JavaScript interoperability with Managed/Native code

There are a number of ways to go about this. Chakra is a 'active script engine' in windows, and implements a number of COM interfaces to enable it to tell the OS that it is capable of running script files in an interactive environment.

One of things this enables, is to use COM (interop if you're pure managed) in your application and offer native objects to the scripting environment. This is how windows script host runs, and enables the WSH class to all script engines that it hosts when you use it to run a script.
The COM interface references are on MSDN. You can use IActiveScript::AddNamedItem to expose objects at runtime to the executing script.

I have done this to enable a hosted IE web browser control to call native code via javascript, but you have to be pretty comfortable in COM's workings and your COM/interop skills have to be pretty keen. In hindsight it was not worth the difficulty of the undertaking, as one of my coworkers found an easier way to accomplish script/host RPC (by watching the navigate event of the browser ccontrol, he was able to craft custom links and then click them programmically and then used the URL from the link to determine which action to undertake, quite a hack but he got it up and running in like 5 minutes and i had spent hours exposing classes to the script runtime...)



Related Topics



Leave a reply



Submit