SEBWIN-510, #278, #417: Fixed crash when attempting to execute JavaScript.

This commit is contained in:
Damian Büchel 2022-07-25 18:37:43 +02:00
parent 82e8166fd5
commit 9d7b89d36c

View file

@ -7,6 +7,7 @@
*/
using System;
using System.Threading.Tasks;
using CefSharp;
using SafeExamBrowser.Browser.Wrapper;
using SafeExamBrowser.Browser.Wrapper.Events;
@ -63,10 +64,12 @@ namespace SafeExamBrowser.Browser
}
public void ExecuteJavascript(string javascript, Action<JavascriptResult> callback)
{
if ((control as IWebBrowser)?.CanExecuteJavascriptInMainFrame == true)
{
control.EvaluateScriptAsync(javascript).ContinueWith(t =>
{
callback(new JavascriptResult()
callback(new JavascriptResult
{
Message = t.Result.Message,
Result = t.Result.Result,
@ -74,6 +77,15 @@ namespace SafeExamBrowser.Browser
});
});
}
else
{
Task.Run(() => callback(new JavascriptResult
{
Message = "JavaScript can't be executed in the main frame!",
Success = false
}));
}
}
public void Find(string term, bool isInitial, bool caseSensitive, bool forward = true)
{