using CefSharp; namespace TradeIdeas.TIProGUI.Charting.JavaScriptBridge { public class ChartJSBridgeRenderProcessMessageHandler : IRenderProcessMessageHandler { public string ScriptToExecuteAfterContentLoaded = string.Empty; public bool ContextCreated = false; public void OnContextReleased(IWebBrowser browserControl, IBrowser browser, IFrame frame) { } public void OnFocusedNodeChanged(IWebBrowser browserControl, IBrowser browser, IFrame frame, IDomNode node) { } public void OnUncaughtException(IWebBrowser browserControl, IBrowser browser, IFrame frame, JavascriptException exception) { } // Wait for the underlying JavaScript Context to be created. This is only called for the main frame. // If the page has no JavaScript, no context will be created. public void OnContextCreated(IWebBrowser browserControl, IBrowser browser, IFrame frame) { ContextCreated = true; var script = "document.addEventListener('DOMContentLoaded', function(){ console.log('chart ready, script wait for execute : " + !string.IsNullOrEmpty(ScriptToExecuteAfterContentLoaded) + "'); " + ScriptToExecuteAfterContentLoaded +" });"; frame.ExecuteJavaScriptAsync(script); this.ScriptToExecuteAfterContentLoaded = string.Empty; } } }