我在使用Cefsharp中的 EvaluateScriptAsync 时遇到问题。我想使用 EvaluateScriptAsync 运行javascript代码,然后,在完成此操作后,我希望我的代码继续工作,但 ContinueWith 不等待EvaluateScriptAsync完成。这是我的代码,不知道是什么问题:
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;
});
}
}
答案 0 :(得分:-1)
您应该使用“浏览器选项卡控件”的ExecuteSciptAsyc()方法。
首先,您必须获取当前标签页控件,然后从浏览器控件调用ExecuteSciptAsyc()方法。
var control = GetCurrentTabControl(); control.Browser.ExecuteScriptAsync(" alert(' It' work')");