diff --git a/.changes/inspector-ios-16.4-macos-13.3.md b/.changes/inspector-ios-16.4-macos-13.3.md new file mode 100644 index 000000000..165aaa879 --- /dev/null +++ b/.changes/inspector-ios-16.4-macos-13.3.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +Use the new WKWebView `inspectable` property if available (iOS 16.4, macOS 13.3). diff --git a/src/webview/wkwebview/mod.rs b/src/webview/wkwebview/mod.rs index 56ccb4fb5..4bebab431 100644 --- a/src/webview/wkwebview/mod.rs +++ b/src/webview/wkwebview/mod.rs @@ -308,14 +308,6 @@ impl InnerWebView { #[cfg(target_os = "macos")] (*webview).set_ivar(ACCEPT_FIRST_MOUSE, attributes.accept_first_mouse); - #[cfg(any(debug_assertions, feature = "devtools"))] - if attributes.devtools { - // Equivalent Obj-C: - // [[config preferences] setValue:@YES forKey:@"developerExtrasEnabled"]; - let dev = NSString::new("developerExtrasEnabled"); - let _: id = msg_send![_preference, setValue:_yes forKey:dev]; - } - let _: id = msg_send![_preference, setValue:_yes forKey:NSString::new("allowsPictureInPictureMediaPlayback")]; if attributes.autoplay { @@ -360,6 +352,18 @@ impl InnerWebView { let _: () = msg_send![scroll, setBounces: NO]; } + #[cfg(any(debug_assertions, feature = "devtools"))] + if attributes.devtools { + let has_inspectable_property: BOOL = + msg_send![webview, respondsToSelector: sel!(setInspectable:)]; + if has_inspectable_property == YES { + let _: () = msg_send![webview, setInspectable: YES]; + } + // this cannot be on an `else` statement, it does not work on macOS :( + let dev = NSString::new("developerExtrasEnabled"); + let _: id = msg_send![_preference, setValue:_yes forKey:dev]; + } + // allowsBackForwardNavigation #[cfg(target_os = "macos")] {