Enable WKWebView Web Inspector Under Mac Catalyst?

I'm trying to enable the web inspector on WKWebView in a Mac Catalyst app. I'm only doing this for debugging purposes. In the released the web inspector will not be enabled.

Doing this under Mac Catalyst does not work:

 WKPreferences *prefs = [[WKPreferences alloc]init];
  [prefs _setDeveloperExtrasEnabled:YES];

//Assign the WKPreferences to a WKWebViewConfiguration and create the web view..

Is there any way to do this?

Thanks in advance.

Accepted Reply

You can now open the web inspector from Safari's "Develop" menu in the menu bar for a WKWebView in a Mac Catalyst app if you set the isInspectable property to YES. They added this in iOS 16.4.

Replies

Searched developer.apple.com trying to find info about this. I cannot find anything. If there is a way to do this it doesn't appear to be documented. I filed FB12004725

Ended up making a AppKit project that uses WKWebView, and duplicated the code I need to test in the AppKit project. Using the -_setDeveloperExtrasEnabled: method works when building under AppKit.

You can now open the web inspector from Safari's "Develop" menu in the menu bar for a WKWebView in a Mac Catalyst app if you set the isInspectable property to YES. They added this in iOS 16.4.

It's better than nothing but still not as good as being able to open the web inspector from the WKWebView itself because:

  1. We have to switch to Safari to get the Web Inspector.

and 2) You don't get an "Inspect Element..." menu item when you right click to launch the web inspector in the WKWebView itself.