How to debug wkwebview in iOS 16.4.1 using XCode 14.2?
Asked Answered
G

2

4
  • Environment:
  1. MacOS: Monterey 12.6.1
  2. XCode: 14.2
  3. iOS: 16.4.1
  4. Safari : 16.2 (17614.3.7.1.7, 17614)
  • Question:

I want to debug my webview, and I open safari and nothing in the my device inspector.
Than I search the information, wkwebview change the default config.
Create new setting (isInspectable) about wkwebview.
And I using the XCode 14.2 don't have this property.

if (@available(iOS 16.4, *)) {
     self.wkWebView.inspectable = YES; //Property 'inspectable' not found on object of type 'WKWebView *'
}

Have any idea to debug webview without upgrade my macOS and install XCode 14.3?

Geyserite answered 10/5, 2023 at 8:4 Comment(1)
Does this answer your question? How to show the inspector within your WKWebView based desktop app?Crimea
N
11

I also faced the same issue and this solution works for me.

if webView.responds(to: Selector(("setInspectable:"))) {
    webView.perform(Selector(("setInspectable:")), with: true)
}

After this we can debug the WKWebView in safari.

Napier answered 3/7, 2023 at 8:25 Comment(2)
Yeah, this works for me My XCode is 14.2 (14C18) and macOS is 13.4 (22F66) Thanks a lot man you saved my life :)Rockyrococo
where should I put this code?Assuntaassur
C
2

Considering the building environment before accessing the inspectable property, as below

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300 || \
    __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400 || \
    __TV_OS_VERSION_MAX_ALLOWED >= 160400
    if (@available(macOS 13.3, iOS 16.4, tvOS 16.4, *))
      self.wkWebView.inspectable = _webviewDebuggingEnabled;
#endif
Ceraceous answered 12/5, 2023 at 8:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.