CefSharp in WinForms - ExecuteScriptAsync or EvaluateScriptAsync doesnt work
Asked Answered
S

2

6

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

Sandstorm answered 25/11, 2015 at 14:7 Comment(1)
Did you install the Nuget package? Which Version specifically are you using? In newer versions those methods were made into Extension Methods as they can be executed on a specific frame. In a couple of cases I've seen people have trouble. Try getting the main frame first. See github.com/cefsharp/CefSharp/blob/cefsharp/45/CefSharp/… for an exampleRancid
S
3

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;
Shopkeeper answered 24/3, 2016 at 19:41 Comment(0)
F
1

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

Freddiefreddy answered 6/5, 2019 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.