Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CefSharp in WinForms - ExecuteScriptAsync or EvaluateScriptAsync doesnt work

I am using CefSharp WinForms in my project and i cannot get it to execute a JS script from the CefSharp Browser Control (I was to navigate to URLs though - so most of the CEF functionality works) I tried following the tutorial at: https://github.com/cefsharp/CefSharp/search?utf8=%E2%9C%93&q=BoundObject

I am using the following namespaces:

using CefSharp.WinForms;
using CefSharp.Internals;

and added references to the following assemblies (x64):

CefSharp.WinForms.dll
CefSharp.dll
CefSharp.Core.dll

but still I get the following error when I try to use one of the functions: ExecuteScriptAsync or EvaluateScriptAsync

I get the following error:

'CefSharp.WinForms.ChromiumWebBrowser' does not contain a definition for 'EvaluateScriptAsync' and no extension method 'EvaluateScriptAsync' accepting a first argument of type 'CefSharp.WinForms.ChromiumWebBrowser' could be found (are you missing a using directive or an assembly reference?)

'CefSharp.WinForms.ChromiumWebBrowser' does not contain a definition for 'ExecuteScriptAsync' and no extension method 'ExecuteScriptAsync' accepting a first argument of type 'CefSharp.WinForms.ChromiumWebBrowser' could be found (are you missing a using directive or an assembly reference?)

can anyone direct me to the point i am missing? is there another API? maybe some reference dll that I am missing? thanks

like image 899
user1322801 Avatar asked Nov 25 '15 14:11

user1322801


People also ask

How does evaluatescriptasync work in Windows Forms?

If you use EvaluateScriptAsync, the script will be executed asynchronously and the method returns a Task encapsulating the response from the script. Create a Windows Forms Application.

How to receive data from a web application in cefsharp?

Add below the method for receiving data from a web application and bind it to the CefSharp eventhandler called "JavascriptMessageReceived". Whenever the data has been sent from a web application, then this method will be triggered.

How to execute JavaScript code using postMessage in cefsharp?

The method is used to execute the simple javascript code. In the javascript code, attach the "CefSharp.PostMessage" handler with "messageSentEvent " type. Whenever the event is dispatched with the type "messageSentEvent " in the web application then "CefSharp.PostMessage" will be executed.

How to integrate WinForms with ReactJS in cefsharp?

The same URL has been given in the CefSharp browser control (See the code part in point #5 of the WinForm application). Run the Winform application. In the WinForm application, type a message in the text box and click send button. The ReactJS application (inside the browser control) will receive the message.


2 Answers

You may be missing one other namespace. I would suggest you add:

 using CefSharp;

We were having the same trouble and found that we were simply missing this one. We now have:

using System.Text;
using CefSharp;
using CefSharp.WinForms;
using CefSharp.Internals;
like image 185
CaptainBli Avatar answered Oct 04 '22 21:10

CaptainBli


CaptainBli is correct: you have to use "using CefSharp"

Probably you didn't expect it there, since it seems to be in another namespace: "CefSharp.WinForms.ChromiumWebBrowser".

This is because EvaluateScriptAsync and ExecuteScriptAsync are extension methods

like image 25
Sam Avatar answered Oct 04 '22 19:10

Sam