First of all, does anyone know if this is resolved in cef 3?
anthony, Jack, I don't believe that to be the problem. I am currently using cefsharp 1.x stable. In my implementation, I have done the following things:
A thread (we'll say thread 1), news up a WebView control. This thread sets various methods to the events available on WebView. It additionally sets up Js callback method. Thread 1 then occasionally calls WebView.EvaluateScript to figure out what the user is doing. Just to be extra safe, I've wrapped the webview object in a class, and used a locking object to ensure that no matter what is going on in my code, EvaluateScript is only called by one thread at a time.
When the exposed javascript method is called, it crunches some data, and pushes the results to an, as of currently, unused object elsewhere in the program. Nothing else.
Now when the page is finished loading, as triggered by WebView.LoadCompleted, I set a script on the document that is supposed to (it doesn't seem to work, but) call the exposed javascript method whenever the user scrolls. Interestingly, I've found that all of the WebView events are raised on a different thread than the thread I initiated the webview object with, so I've tested the following with both that thread, and thread 1.
In my experience, if I go to a website, and scroll, occasionally, a call to EvaluateScript by Thread1 will timeout, or lockup, depending on whether a timeout value is specified. Indeed, it seems that even if a timeout/exception isn't raised, so long as thread 1 is occasionally calling evaluate script, the registered callback method may not be called with any consistency.
After reading Jack's post, I thought that perhaps the problem is the fact that there were conflicting threads. As such, I tested calling evaluate script with both Thread1, and the thread created when WebView's events are raised, but both have the same problem.
I have no way, that I can tell, of calling evaluate script with the thread that calls the exposed javascript method. I tried such craziness as WebView.Invoke(Webview.EvaluateScript), but as expected, that was not successful.
So I think the problem must be that within cef or cefsharp, my Thread1 will call EvaluateScript while CefSharp's javascript thread attempts to call the exposed javascript method, or vice versa, and as a result, the exposed method is not called, and the evaluate script call times out or locks up.
-Rob