Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Expose .NET class to JavaScript

softoille@gmail.com edited this page Nov 29, 2019 · 1 revision

Applies Only to CefSharp apps

.NET object bounded to JavaScript details can be found on CefSharp site at section [How do you expose a .NET class to JavaScript?].

Chromely allows .NET objects exposed to JavaScript to be registered in ChromelyConfiguration. Registration is done by adding instance of ChromelyJsHandler to the IoC container. The ChromelyJsHandler:

public class ChromelyJsHandler
{
      ......

       public string Key { get; private set; }
       public string JsMethod { get; set; }
       public object BoundObject { get; set; }
       public object BindingOptions { get; set; }
       public bool RegisterAsAsync { get; set; }
   }

where RegisterAsAsync determines whether CefSharp RegisterAsyncJsObject or RegisterJsObject method is used for registration.

Following is an example of how registration is done:

ChromelyConfiguration config = ChromelyConfiguration()
                             .Create()
                             ....
                             .RegisterJsHandler("boundControllerAsync", new CefSharpBoundObject(), null, true);
                             .RegisterJsHandler("boundControllerAsync2", new NewCefSharpBoundObject(), null, false);
                             .....
Clone this wiki locally