I use cefsharp to execute some JavaScript commands in browser environment (console) inside a loop.
For example, When I want to run a command like Goog_AdSense_
(related to the "Google AdSense" app), cefsharp crashes and the rest of the loop will not be executed.
I know cefsharp uses IRequestHandler
interface to call OnRenderProcessTerminated
method to display an error, but wondering how to proceed from here!
How to perform and run the rest of the loop?
class InternalBrowser
{
void CheckJS(AppSignature app, InternalBrowser browser, Scripts scripts)
{
foreach (var script in scripts)
browser.RunScript(script);
}
public bool RunScript(string script, InternalBrowser browser)
{
Task<JavascriptResponse> task = browser.EvaluateScriptAsync(script);
task.Wait();
bool result = task.Result.Success && (task.Result.Result != null);
return result;
}
}
class RequestHandler : IRequestHandler
{
public void OnRenderViewReady(IWebBrowser browserControl, IBrowser browser)
{
}
public bool OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url)
{
return false;
}
public void OnPluginCrashed(IWebBrowser browserControl, IBrowser browser, string pluginPath)
{
}
public void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status)
{
//Here is the error display
}
public bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool isRedirect)
{
return false;
}
public void OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, ref string newUrl)
{
}
public bool OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
{
var t = response.ResponseHeaders;
return false;
}
public bool OnQuotaRequest(IWebBrowser browserControl, IBrowser browser, string originUrl, long newSize, IRequestCallback callback)
{
return false;
}
public CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
return CefReturnValue.Continue;
}
public bool OnCertificateError(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback)
{
return false;
}
public bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
{
return false;
}
public bool GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
{
return false;
}
}
An example in the google chrome console: