wpf 在 Chromium 嵌入式框架中调试 JavaScript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29117882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debugging JavaScript in Chromium Embedded Framework
提问by stefan
I have a WPF application which uses CEF to display web content. My question is, is there a way to debug the Javascript/Web parts inside a WPF application?
我有一个 WPF 应用程序,它使用 CEF 来显示 Web 内容。我的问题是,有没有办法调试 WPF 应用程序中的 Javascript/Web 部件?
回答by Eido95
回答by Sga
Enable remote debugging in your application:
在您的应用程序中启用远程调试:
C#(CefSharp)
C#(CefSharp)
CefSettings.RemoteDebuggingPort = 8088;
C++
C++
CefSettings settings;
settings.remote_debugging_port = 8088;
then run your app and point your browser to http://localhost:8088/
to access the Chromium developer console (the same you have in Chrome with Ctrl+Shift+j)
然后运行您的应用程序并指向您的浏览器以http://localhost:8088/
访问 Chromium 开发人员控制台(与您在 Chrome 中使用Ctrl+Shift+j 相同)
回答by craftworkgames
While the accepted answer is correct, it doesn't really have enough detail.
虽然接受的答案是正确的,但它并没有足够的细节。
I got this working in CefSharp using the WinForms control in a WPF application. (the WinForms control seems to have better performance). The code for remote debugging will probably be very similar for the WPF control though.
我在 WPF 应用程序中使用 WinForms 控件在 CefSharp 中完成了这项工作。(WinForms 控件似乎具有更好的性能)。不过,WPF 控件的远程调试代码可能非常相似。
var settings = new CefSettings { RemoteDebuggingPort = 8088 };
Cef.Initialize(settings);
WindowsFormsHost.Child = new ChromiumWebBrowser(url);
Then go to http://localhost:8088/
in your browser.
然后http://localhost:8088/
在浏览器中访问。
回答by Eduardo Gadotti
To use 'ShowDevTools()' you will need first verify if the browser is initialized. An example solution:
要使用“ShowDevTools()”,您首先需要验证浏览器是否已初始化。一个示例解决方案:
//Add an event to check
ChromeBrowser.IsBrowserInitializedChanged += ChromeBrowser_IsBrowserInitializedChanged;
//Declare the event method to be called
private void ChromeBrowser_IsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e)
{
if (e.IsBrowserInitialized)
{
ChromeBrowser.ShowDevTools();
}
}
回答by Caleb Seadon
To open the Chromium Dev-Tools window you can do the following:
要打开 Chromium Dev-Tools 窗口,您可以执行以下操作:
CefBrowser.GetBrowser().GetHost().ShowDevTools();
This is similar to Eido95's answer, but it doesn't require the extension methods, which essentially just wrap these method calls.
这类似于 Eido95 的答案,但它不需要扩展方法,它本质上只是包装了这些方法调用。
NOTE: The control needs to be initialized before calling this method can be called. If you're wiring-up and F12-like functionality this shouldn't be a problem. If you're trying to do this when the app is starting you will need to listen for the ChromiumWebBrowser.IsBrowserInitializedChangedevent
注意:控件需要在调用此方法之前进行初始化才能调用。如果您正在接线和类似 F12 的功能,这应该不是问题。如果您在应用程序启动时尝试执行此操作,则需要侦听ChromiumWebBrowser.IsBrowserInitializedChanged事件