I'm a bit new to c# and CefSharp :-) so be cool with me !
My goal is to call an url, and then explore DOM to retrieve data and then process this data for hypervision purpose. I've achieve that retrieval and my js code work well using EvaluateScriptAsync.
By now i want to track data refresh. The page is updated by a websocket communication, which then update values in the DOM object model.
i think to use RequestHandler and adapt GetResourceResponseFilter; but i can't manage to do that and seems the the methods i've implemented were never called ... i use the Minimal solution dowloaded from cefsharp project site. I just add the two lines at the end of this snippet :
public BrowserForm()
{
InitializeComponent();
Text = "CefSharp";
WindowState = FormWindowState.Maximized;
browser = new ChromiumWebBrowser("www.google.com");
toolStripContainer.ContentPanel.Controls.Add(browser);
browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
browser.LoadingStateChanged += OnLoadingStateChanged;
browser.ConsoleMessage += OnBrowserConsoleMessage;
browser.StatusMessage += OnBrowserStatusMessage;
browser.TitleChanged += OnBrowserTitleChanged;
browser.AddressChanged += OnBrowserAddressChanged;
// Add this for request handler
Handler.RequestHandler requestHandler = new MyBasicRequestHandler();
browser.RequestHandler = requestHandler;
And my test handler look like this !
public class MyBasicRequestHandler : CefSharp.Handler.RequestHandler
{
public bool OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
{
MessageBox.Show ("OnResourceResponse");
return false;
}
public bool OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url)
{
MessageBox.Show("OnProtocolExecution : "+url);
return false;
}
public IResponseFilter GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
{
MessageBox.Show("GetResourceResponseFilter : " + request.ReferrerUrl);
return null;
}
}
But nothing is fired !
Any help or advice will be appreciate.
thanks!
Thanks to amaitland kind comments this code works. I've only added few lines to CefSharp.Minimal Example.Winforms solution pulled from github to register the RequestHandler.
And then I've add code for MyBasicRequestHandler and MyCustomResourceRequestHandler Classes as follow :
Start the app and happy to see this in the VisualStudio console ouput :
So my problem is solved ! Thanks again dear amaitland ;-)