diff --git a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md index 4de08406bba1..197c5d70784f 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.9.2 + +* Fixes error caused by calling `WKWebViewConfiguration.limitsNavigationsToAppBoundDomains` on + versions below 14. + ## 3.9.1 * Fixes bug where `WebkitWebViewController.getUserAgent` was incorrectly returning an empty String. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart index a02ed61069e7..d15b28251828 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart @@ -70,8 +70,14 @@ class WebKitWebViewControllerCreationParams ); } _configuration.setAllowsInlineMediaPlayback(allowsInlineMediaPlayback); - _configuration.setLimitsNavigationsToAppBoundDomains( - limitsNavigationsToAppBoundDomains); + // `WKWebViewConfiguration.limitsNavigationsToAppBoundDomains` is only + // supported on iOS versions 14+. So this only calls it if the value is set + // to true. + if (limitsNavigationsToAppBoundDomains) { + _configuration.setLimitsNavigationsToAppBoundDomains( + limitsNavigationsToAppBoundDomains, + ); + } } /// Constructs a [WebKitWebViewControllerCreationParams] using a diff --git a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml index 63ed6e4db5f0..2d469bd83825 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_wkwebview description: A Flutter plugin that provides a WebView widget based on Apple's WKWebView control. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_wkwebview issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 3.9.1 +version: 3.9.2 environment: sdk: ">=2.19.0 <4.0.0" diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart index d1854df4bce0..46badc069058 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart @@ -160,6 +160,25 @@ void main() { ); }); + test( + 'limitsNavigationsToAppBoundDomains is not called if it uses default value (false)', + () { + final MockWKWebViewConfiguration mockConfiguration = + MockWKWebViewConfiguration(); + + WebKitWebViewControllerCreationParams( + webKitProxy: WebKitProxy( + createWebViewConfiguration: ({InstanceManager? instanceManager}) { + return mockConfiguration; + }, + ), + ); + + verifyNever( + mockConfiguration.setLimitsNavigationsToAppBoundDomains(any), + ); + }); + test('mediaTypesRequiringUserAction', () { final MockWKWebViewConfiguration mockConfiguration = MockWKWebViewConfiguration();