Skip to main content

Command Palette

Search for a command to run...

Inspect Web Content on iOS 16.4+

Updated
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 DEBUG
       if #available(iOS 16.4, *) {
          webView.isInspectable = true
       }
#endif

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.

A

Hi Marco, thanks for the explanation in the post, it was informative! Do you know by any chance if the un-inspectability extends to in-app-browser (Safari) content as well? We have resolved the issue of the application itself not being inspectable but got stuck on the app opening our web-based login solution which is still invisible to the web inspector.

Thanks!

M

András Viszlay are you referring to SFSafariViewController? I am not aware that the WebKit changes introduced in iOS 16.4 extend to SFSafariViewController.

More from this blog

Dev blog post potpourri by senior software engineer Marco Eidinger

149 posts

Hello 👋🏻 , I am a Software Engineer working on open source and enterprise mobile SDKs for iOS and MacOS developers written in Swift. From 🇩🇪 and happily living in 🇺🇸

Inspect Web Content on iOS 16.4+