x
Main Site login Signup

Awesomium WebControl : C# delegate is not invoked when JavaScript method is invoked

Problem : The C# method is not invoked when JavaScript method is invoked. I have a WPF application in which I am using Awesomium web control

Details:

The javascript method is as follows:

 function onPaymentMethod(nonce, type, details) {
     //console.log(nonce);
     app.onNonceReceived(nonce);
 }


In C# I have following code:

 public Window3()
 {
     InitializeComponent();

     WebControl.DocumentReady += WebControl_DocumentReady;
 }

 private void WebControl_DocumentReady(object sender, DocumentReadyEventArgs e)
 {
     BindMethods(WebControl);
 }

 private void BindMethods(IWebView _webView)
 {
     // This is where we create the object.
     JSValue result = WebControl.CreateGlobalJavascriptObject("app");

     if (result.IsObject)
     {
         JSObject appObject = result;
         using(appObject)
         {
             appObject.Bind("onNonceReceived", onNonceReceived);
         }
     }
 }

 private JSValue onNonceReceived(object obj, JavascriptMethodEventArgs jsMethodArgs)
 {
     // ********** this is never invoked!!!!!!!!***************
     string nonce = jsMethodArgs.Arguments[0].ToString();
     return null;
 }

Not sure why but the "onNonceReceived" method is never invoked. I have verified that the javascript function "onPaymentMethod(nonce, type, details)" is invoked which means a call must have been done to app.onNonceReceived(nonce).

Can someone help?

asked Apr 27, 2016 at 06:04 AM avatar image skonduru26 0
more ▼
(comments are locked)
10|1100 characters needed characters left

1 answer: sort voted first

You can also add a handler for the ConsoleMessage event and see if you're getting an error when app.onNonceReceived is called in JavaScript.

Note that starting with v1.7.6, it will be very easy to create local Inspector Views (dedicated Developer Tools views) to inspect the content, code and behavior of a page.

Suggestion:

If you're using v1.7.5+, we would suggest switching to the Javascript Interoperation Framework (JIF) available to every page loaded in Awesomium.NET web-view components. In particular, OSMJIF.sendMessage and OSMJIF.sendMessageAsync can be used instead of creating global objects and binding to custom methods.

answered Jun 15, 2016 at 01:06 AM avatar image Perikles C. Stephanidis ♦♦ 10.7k
more ▼
(comments are locked)
10|1100 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.