如何在基于WKWebView的桌面应用程序中显示检查器? [英] How to show the inspector within your WKWebView based desktop app?

查看:124
本文介绍了如何在基于WKWebView的桌面应用程序中显示检查器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种显示

I'm looking for a way to show the inspector for a WKWebView inside my Mac app.

使用WebKit1和WebView,只需在UserDefaults中将WebKitDeveloperExtras设置为true,即可轻松在Mac应用程序中显示检查器.这样,您就可以在每个Web视图中使用检查元素"菜单.

With WebKit1 and WebView it was easy to show the inspector inside your Mac app, by just setting WebKitDeveloperExtras to true in your UserDefaults. That would give you an "Inspect Element" menu in every web view.

但是在带有WKWebView的WebKit2中,此功能不再起作用.在WWDC14检查器会话中,他们解释说您必须添加权利,然后可以从Safari开发人员菜单中显示检查器.仅当您是开发人员时,此方法才有效.

But in WebKit2 with WKWebView this is not working anymore. In the WWDC14 inspector session they explain that you have to add an entitlement and can then show the inspector from the Safari developer menu. This only works if you are the developer.

我浏览了私有标头,发现_allowsRemoteInspection使我认为您可以以某种方式启动检查器并连接到它,但是我不确定从那里去哪里.

I looked through the private headers and found _allowsRemoteInspection which makes me think you can somehow launch an inspector and connect to it, but I'm not sure where to go from there.

尽管我希望有一种正式的方式来实现此目的,但我的应用程序不在AppStore中,因此我可以使用私有内容.

Although I'm hoping for an official way to do this, my app is not in the AppStore, so I'm ok with using private stuff.

推荐答案

已在此处进行了修补:

This was patched here: https://lists.webkit.org/pipermail/webkit-dev/2014-August/026790.html

只需公开这样的私有财产,您就可以使用它.

Just expose the private property like this and you can use it.

@interface WKPreferences (WKPrivate)
@property (nonatomic, setter=_setDeveloperExtrasEnabled:) BOOL _developerExtrasEnabled;
@end

现在,您可以右键单击检查元素"菜单.

Now you get the "Inspect Element" menu on right click.

我仍然需要找出的唯一一件事是如何直接从代码中显示检查器.

The only thing I still need to find out is how to show the inspector directly from code.

这篇关于如何在基于WKWebView的桌面应用程序中显示检查器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆