Inspect Web Content on iOS 16.4+


2 min read

Before iOS 16.4 developers were able to attach the Web Inspector to inspect content running in WKWebView and JSContext for a developer-provisioned app built directly from Xcode for local development.

With iOS 16.4+ this is no longer possible. In your code, you must explicitly opt-in to content being inspectable.

Example WKWebView

let webConfiguration = WKWebViewConfiguration()
let webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.isInspectable = true // <== !!!

Example JSContext

let jsContext = JSContext()
jsContext?.isInspectable = true // <== !!!

Those new properties are available in iOS 16.4+ so you must use the if #available if you support older versions.

It is a good idea to enable inspection for DEBUG builds only.

Here is a complete example for WKWebView

       if #available(iOS 16.4, *) {
          webView.isInspectable = true

If you are using WKWebView for an in-app web browser experience then you can consider always making content inspectable.

A common situation in which you may want the content of WKWebView to be inspectable is in an in-app web browser. The browser shows ordinary web content that would be inspectable when loaded in Safari. It can be beneficial both for the app developer, as well as web authors, to be able to inspect content in these views, as the size of the view may not match that of Safari’s, or the app developer may be injecting script into the view to provide integration with their app.

A considerable advantage is that you can inspect apps build for release if isInspectable is set to true. That was previously not possible.

However, released versions of apps had no way to inspect dynamic web content or scripts, leaving developers and users to have to resort to more complicated workflows to get information that would otherwise be made available by Web Inspector. Now, this same functionality is available through an API on WKWebView and JSContext.

You find further information in the very helpful article from WebKit.

Did you find this article valuable?

Support Marco Eidinger by becoming a sponsor. Any amount is appreciated!