Skip to content

Commit b25faa3

Browse files
authored
Merge pull request #349 from StijnDRZP/fix/set-inspectable-crash
Fix: Conditionally set inspectable property on iOS
2 parents 730403f + ccd65ad commit b25faa3

File tree

1 file changed

+19
-1
lines changed
  • webview/src/iosMain/kotlin/com/multiplatform/webview/web

1 file changed

+19
-1
lines changed

webview/src/iosMain/kotlin/com/multiplatform/webview/web/WebView.ios.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import androidx.compose.ui.viewinterop.UIKitView
1111
import com.multiplatform.webview.jsbridge.WebViewJsBridge
1212
import com.multiplatform.webview.util.toUIColor
1313
import kotlinx.cinterop.ExperimentalForeignApi
14+
import kotlinx.cinterop.cValue
1415
import kotlinx.cinterop.readValue
1516
import platform.CoreGraphics.CGRectZero
17+
import platform.Foundation.NSOperatingSystemVersion
18+
import platform.Foundation.NSProcessInfo
1619
import platform.Foundation.setValue
1720
import platform.WebKit.WKAudiovisualMediaTypeAll
1821
import platform.WebKit.WKAudiovisualMediaTypeNone
@@ -149,7 +152,22 @@ fun IOSWebView(
149152
}
150153
}
151154

152-
this.setInspectable(state.webSettings.iOSWebSettings.isInspectable)
155+
/**
156+
* Sets the inspectable property of the WKWebView.
157+
* This is only done if the operating system version is iOS 16.4 or later
158+
* to prevent crashes on lower versions where the `setInspectable` method is not available.
159+
* Enabling this allows Safari Web Inspector to debug the content of the WebView.
160+
* The value is determined by `state.webSettings.iOSWebSettings.isInspectable`.
161+
*/
162+
val minSetInspectableVersion =
163+
cValue<NSOperatingSystemVersion> {
164+
majorVersion = 16
165+
minorVersion = 4
166+
patchVersion = 0
167+
}
168+
if (NSProcessInfo.processInfo.isOperatingSystemAtLeastVersion(minSetInspectableVersion)) {
169+
this.setInspectable(state.webSettings.iOSWebSettings.isInspectable)
170+
}
153171
}.also {
154172
val iosWebView = IOSWebView(it, scope, webViewJsBridge)
155173
state.webView = iosWebView

0 commit comments

Comments
 (0)