Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the inspector within your WKWebView based desktop app?

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

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.

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.

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.

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.

like image 259
Koen Bok Avatar asked Aug 08 '14 09:08

Koen Bok


People also ask

How do I use WKWebView?

Here's how: Open the XIB or Storyboard you want to add the web view to in Interface Builder. Find the web view or WKWebView in the Object Library at the bottom-left of Interface Builder. Drag-and-drop a WKWebView object from the Object Library to your view controller's canvas, and adjust its size and position.

What is Uiwebview WKWebView?

Overview. A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.

How do I create a WKWebView app for Macos?

Step 1 - Install XCode 11 and open it. Step 2 - Select "File" and "New" and "Project" from the main menu. Step 3 - Select "App" (top left) and Select "Next" (bottom right). Step 4 - Give your app a name, for User Interface select "Storyboard" and then select "Next".


1 Answers

For Swift, instead of building a bridging header you can set it directly

self.webView.configuration.preferences.setValue(true, forKey: "developerExtrasEnabled") 
like image 76
Drazen Avatar answered Sep 24 '22 08:09

Drazen