C# CefSharp RenderProcessMessageHandler 示例
C# CefSharp RenderProcessMessageHandler example
我是 C# 的新手,正在学习 Cefsharp + javascript。我试图等到页面完成加载 Cefsharp 以执行我的代码。我在下面找到了代码片段,并将其添加到一个新的class中,在class中出现了关于创建接口的错误,请帮助这些接口里面需要写什么?
public class RenderProcessMessageHandler : IRenderProcessMessageHandler
{
// 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.
void IRenderProcessMessageHandler.OnContextCreated(IWebBrowser browserControl, IBrowser browser, IFrame frame)
{
const string script = "document.addEventListener('DOMContentLoaded', function(){ alert('DomLoaded'); });";
frame.ExecuteJavaScriptAsync(script);
}
}
this is photo of error
您需要实现接口中的所有方法IRenderProcessMessageHandler
public class RenderProcessMessageHandler : IRenderProcessMessageHandler
{
// 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.
void IRenderProcessMessageHandler.OnContextCreated(IWebBrowser browserControl, IBrowser browser, IFrame frame)
{
const string script = "document.addEventListener('DOMContentLoaded', function(){ alert('DomLoaded'); });";
frame.ExecuteJavaScriptAsync(script);
}
void IRenderProcessMessageHandler.OnFocusedNodeChanged(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IDomNode node)
{
var message = node == null ? "lost focus" : node.ToString();
Console.WriteLine("OnFocusedNodeChanged() - " + message);
}
void IRenderProcessMessageHandler.OnContextReleased(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
{
//The V8Context is about to be released, use this notification to cancel any long running tasks your might have
}
void IRenderProcessMessageHandler.OnUncaughtException(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
{
Console.WriteLine("OnUncaughtException() - " + exception.Message);
}
}
您可以查看this以供参考
我是 C# 的新手,正在学习 Cefsharp + javascript。我试图等到页面完成加载 Cefsharp 以执行我的代码。我在下面找到了代码片段,并将其添加到一个新的class中,在class中出现了关于创建接口的错误,请帮助这些接口里面需要写什么?
public class RenderProcessMessageHandler : IRenderProcessMessageHandler
{
// 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.
void IRenderProcessMessageHandler.OnContextCreated(IWebBrowser browserControl, IBrowser browser, IFrame frame)
{
const string script = "document.addEventListener('DOMContentLoaded', function(){ alert('DomLoaded'); });";
frame.ExecuteJavaScriptAsync(script);
}
}
this is photo of error
您需要实现接口中的所有方法IRenderProcessMessageHandler
public class RenderProcessMessageHandler : IRenderProcessMessageHandler
{
// 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.
void IRenderProcessMessageHandler.OnContextCreated(IWebBrowser browserControl, IBrowser browser, IFrame frame)
{
const string script = "document.addEventListener('DOMContentLoaded', function(){ alert('DomLoaded'); });";
frame.ExecuteJavaScriptAsync(script);
}
void IRenderProcessMessageHandler.OnFocusedNodeChanged(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IDomNode node)
{
var message = node == null ? "lost focus" : node.ToString();
Console.WriteLine("OnFocusedNodeChanged() - " + message);
}
void IRenderProcessMessageHandler.OnContextReleased(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
{
//The V8Context is about to be released, use this notification to cancel any long running tasks your might have
}
void IRenderProcessMessageHandler.OnUncaughtException(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
{
Console.WriteLine("OnUncaughtException() - " + exception.Message);
}
}
您可以查看this以供参考