0

I am having a problem about using EvaluateScriptAsync in Cefsharp. I want to run a javascript code with EvaluateScriptAsync and then, after this is completed I want my code continue to work, but ContinueWith isn't waiting to EvaluateScriptAsync complete. Here is my code, and don't know what's the problem:

private void WebBrowserFrameLoadEnded(object sender, FrameLoadEndEventArgs e)
{
    if (e.Frame.IsMain)
    {
        var task = browser.EvaluateScriptAsync("(function() { function xx() { $('body').animate({scrollTop: $('body').prop(\"scrollHeight\")}, 8000, function() { var win = $(window); if ($(document).height() - win.height() == win.scrollTop()) { return true; } else { xx(); } }); }; xx(); })();");

        task.ContinueWith(taskHtml =>
        {
            if (taskHtml.IsCompleted)
            {
                /* Some code working */
            }
            this.DialogResult = DialogResult.OK;
        });
    }
}
YSFKBDY
  • 735
  • 1
  • 12
  • 38

1 Answers1

-2

You Should use the ExecuteSciptAsyc() method of the Browser Tab Control.

1st you have to get the Current tab page Control and then call the ExecuteSciptAsyc() method from browser control.

var control = GetCurrentTabControl(); control.Browser.ExecuteScriptAsync("alert('It's Working')");

Deepak Gupta
  • 73
  • 1
  • 5