Welcome Guest Search | Active Topics | Sign In | Register

EvalScript / GetDOMWindow fail - lock up app Options
Mike King
Posted: Tuesday, July 2, 2019 2:54:02 AM
Rank: Newbie
Groups: Member

Joined: 6/14/2019
Posts: 5
I have a user control that contains your webcontrol and a webview. I load html into the webview using a public method:

ControlWebBrowser.WebView.LoadHtml(psHTML)

I respond to the MouseClick event to interact with the document. On MouseClick, these all lock up the app, as if the webview is no longer responding:

webView.EvalScript('document.getElementById.....

and

webView.GetDOMWindow.document

The form responds to the event but always locks up on interacting with the webview.

The webcontrol is replacing the .Net web browser control that was used extensively in the app. Using the web browser, we would capture the element at the mouse click position. All of this code can be moved to javascript with registered/external events, and I've done that for smaller forms, but it's a large undertaking for the bulk of the app.

Thanks.
Mike King
Posted: Tuesday, July 2, 2019 4:52:11 AM
Rank: Newbie
Groups: Member

Joined: 6/14/2019
Posts: 5
I'm all but certain the problem is with the events.

If I try to access the web view - evalscript, anything - it appears to lock up. If I raise a custom event on a new thread and capture the event on my form, I get a little closer, when I execute scripts that modify input element values, a System.Drawing.dll argumentException is raised (this happens when I Invoke and do not Invoke on the UI thread). That seems to introduce some major time delays as well.

Is it not recommended to use the events? If I create a new view using a thread runner on user control create, no events fire. I can't seem to successfully add a handler after .createwebview.

Is there a successful model to use the web browser on a user control and consume the events in a form?

Thanks.

eo_support
Posted: Tuesday, July 2, 2019 4:40:32 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

You will need to use QueueScriptCall instead. EvalScript relies on Windows message pumps and unless you return from your event handler, the message needed to unblock EvalScript will never arrive. So it's a sure deadlock. You can not use another thread either since WebView is associated to the UI thread.

The recommended code would be something like this:

Code: C#
//Get the WebView from the event sender
EO.WebBrowser.WebView webView = (EO.WebBrowser.WebView)sender;

//Unlike EvalScript, QueueScriptCall is nonblocking
EO.WebBrowser.ScriptCall call = webView.QueueScriptCall("document");

//Attach an OnDone handler
call.OnDone(() =>
{
    //Get the call result
    object document = call.Result;
});


Please let us know if this works for you.

Thanks!
Mike King
Posted: Tuesday, July 2, 2019 7:57:34 PM
Rank: Newbie
Groups: Member

Joined: 6/14/2019
Posts: 5
Thanks - I was having some issues with QueueScriptCall as well, but BeginInvoke on FindForm of the user control solved my issues.

Thanks again.
eo_support
Posted: Wednesday, July 3, 2019 8:01:23 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Yes. BeginInvoke will work. Please feel free to let us know if there is anything else.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.