diff --git a/flutter_inappwebview/CHANGELOG.md b/flutter_inappwebview/CHANGELOG.md index f6a5a26c2..8183257bd 100755 --- a/flutter_inappwebview/CHANGELOG.md +++ b/flutter_inappwebview/CHANGELOG.md @@ -7,9 +7,11 @@ - `flutter_inappwebview_macos`: `^1.2.0-beta.2` -> `^1.2.0-beta.3` - `flutter_inappwebview_web`: `^1.2.0-beta.2` -> `^1.2.0-beta.3` - `flutter_inappwebview_windows`: `^0.7.0-beta.2` -> `^0.7.0-beta.3` +- Fixed "When useShouldInterceptAjaxRequest is true, some ajax requests doesn't work" [#2197](https://github.com/pichillilorenzo/flutter_inappwebview/issues/2197) #### Platform Interface - Added `saveState`, `restoreState` methods to `PlatformInAppWebViewController` class +- Added `useOnAjaxReadyStateChange`, `useOnAjaxProgress` properties to `InAppWebViewSettings` #### Android Platform - Implemented `saveState`, `restoreState` InAppWebViewController methods diff --git a/flutter_inappwebview/lib/src/in_app_webview/headless_in_app_webview.dart b/flutter_inappwebview/lib/src/in_app_webview/headless_in_app_webview.dart index d08dadb6d..f86793aff 100644 --- a/flutter_inappwebview/lib/src/in_app_webview/headless_in_app_webview.dart +++ b/flutter_inappwebview/lib/src/in_app_webview/headless_in_app_webview.dart @@ -86,7 +86,7 @@ class HeadlessInAppWebView { @Deprecated('Use onNavigationResponse instead') FutureOr Function(InAppWebViewController controller, IOSWKNavigationResponse navigationResponse)? iosOnNavigationResponse, @Deprecated('Use shouldAllowDeprecatedTLS instead') FutureOr Function(InAppWebViewController controller, URLAuthenticationChallenge challenge)? iosShouldAllowDeprecatedTLS, - FutureOr Function(InAppWebViewController controller, AjaxRequest ajaxRequest)? onAjaxProgress, + FutureOr Function(InAppWebViewController controller, AjaxRequest ajaxRequest)? onAjaxProgress, FutureOr Function(InAppWebViewController controller, AjaxRequest ajaxRequest)? onAjaxReadyStateChange, void Function(InAppWebViewController controller, ConsoleMessage consoleMessage)? onConsoleMessage, FutureOr Function(InAppWebViewController controller, CreateWindowAction createWindowAction)? onCreateWindow, diff --git a/flutter_inappwebview/lib/src/in_app_webview/in_app_webview.dart b/flutter_inappwebview/lib/src/in_app_webview/in_app_webview.dart index a6b9070e4..b658e652e 100755 --- a/flutter_inappwebview/lib/src/in_app_webview/in_app_webview.dart +++ b/flutter_inappwebview/lib/src/in_app_webview/in_app_webview.dart @@ -86,7 +86,7 @@ class InAppWebView extends StatefulWidget { @Deprecated('Use onNavigationResponse instead') FutureOr Function(InAppWebViewController controller, IOSWKNavigationResponse navigationResponse)? iosOnNavigationResponse, @Deprecated('Use shouldAllowDeprecatedTLS instead') FutureOr Function(InAppWebViewController controller, URLAuthenticationChallenge challenge)? iosShouldAllowDeprecatedTLS, - FutureOr Function(InAppWebViewController controller, AjaxRequest ajaxRequest)? onAjaxProgress, + FutureOr Function(InAppWebViewController controller, AjaxRequest ajaxRequest)? onAjaxProgress, FutureOr Function(InAppWebViewController controller, AjaxRequest ajaxRequest)? onAjaxReadyStateChange, void Function(InAppWebViewController controller, ConsoleMessage consoleMessage)? onConsoleMessage, FutureOr Function(InAppWebViewController controller, CreateWindowAction createWindowAction)? onCreateWindow, diff --git a/flutter_inappwebview_android/CHANGELOG.md b/flutter_inappwebview_android/CHANGELOG.md index 76161c8c2..9360dccb2 100644 --- a/flutter_inappwebview_android/CHANGELOG.md +++ b/flutter_inappwebview_android/CHANGELOG.md @@ -3,6 +3,7 @@ - Updated flutter_inappwebview_platform_interface version to ^1.4.0-beta.3 - Implemented `saveState`, `restoreState` InAppWebViewController methods - Merged "Android: implemented PlatformPrintJobController.onComplete" [#2216](https://github.com/pichillilorenzo/flutter_inappwebview/pull/2216) (thanks to [Doflatango](https://github.com/Doflatango)) +- Fixed "When useShouldInterceptAjaxRequest is true, some ajax requests doesn't work" [#2197](https://github.com/pichillilorenzo/flutter_inappwebview/issues/2197) ## 1.2.0-beta.2 diff --git a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/plugin_scripts_js/InterceptAjaxRequestJS.java b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/plugin_scripts_js/InterceptAjaxRequestJS.java index 5ab19caf5..8ac66dcb4 100644 --- a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/plugin_scripts_js/InterceptAjaxRequestJS.java +++ b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/plugin_scripts_js/InterceptAjaxRequestJS.java @@ -10,20 +10,33 @@ public class InterceptAjaxRequestJS { public static final String INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT_GROUP_NAME = "IN_APP_WEBVIEW_INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT"; + public static String FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE() { return JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME() + "._useShouldInterceptAjaxRequest"; } + + public static String FLAG_VARIABLE_FOR_ON_AJAX_READY_STATE_CHANGE() { + return JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME() + "._useOnAjaxReadyStateChange"; + } + + public static String FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS() { + return JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME() + "._useOnAjaxProgress"; + } + public static String FLAG_VARIABLE_FOR_INTERCEPT_ONLY_ASYNC_AJAX_REQUESTS_JS_SOURCE() { return JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME() + "._interceptOnlyAsyncAjaxRequests"; } + public static PluginScript INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(@Nullable Set allowedOriginRules, - boolean forMainFrameOnly) { + boolean forMainFrameOnly, + boolean initialUseOnAjaxReadyStateChange, + boolean initialUseOnAjaxProgress) { return new PluginScript( InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT_GROUP_NAME, - InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_SOURCE(), + InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_SOURCE(initialUseOnAjaxReadyStateChange, initialUseOnAjaxProgress), UserScriptInjectionTime.AT_DOCUMENT_START, null, true, @@ -35,7 +48,7 @@ public static PluginScript INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(@Nullable Set public static PluginScript createInterceptOnlyAsyncAjaxRequestsPluginScript(boolean onlyAsync) { return new PluginScript( InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT_GROUP_NAME, - "window." + FLAG_VARIABLE_FOR_INTERCEPT_ONLY_ASYNC_AJAX_REQUESTS_JS_SOURCE() + " = " + onlyAsync +";", + "window." + FLAG_VARIABLE_FOR_INTERCEPT_ONLY_ASYNC_AJAX_REQUESTS_JS_SOURCE() + " = " + onlyAsync + ";", UserScriptInjectionTime.AT_DOCUMENT_START, null, true, @@ -44,11 +57,13 @@ public static PluginScript createInterceptOnlyAsyncAjaxRequestsPluginScript(bool ); } - public static String INTERCEPT_AJAX_REQUEST_JS_SOURCE() { + public static String INTERCEPT_AJAX_REQUEST_JS_SOURCE(boolean initialUseOnAjaxReadyStateChange, boolean initialUseOnAjaxProgress) { return "(function(ajax) {" + " var w = (window.top == null || window.top === window) ? window : window.top;" + " w." + FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE() + " = true;" + + " w." + FLAG_VARIABLE_FOR_ON_AJAX_READY_STATE_CHANGE() + " = " + initialUseOnAjaxReadyStateChange + ";" + + " w." + FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS() + " = " + initialUseOnAjaxProgress + ";" + " var send = ajax.prototype.send;" + " var open = ajax.prototype.open;" + " var setRequestHeader = ajax.prototype.setRequestHeader;" + @@ -98,8 +113,11 @@ public static String INTERCEPT_AJAX_REQUEST_JS_SOURCE() { " setRequestHeader.call(this, header, value);" + " };" + " function handleEvent(e) {" + - " var self = this;" + " var w = (window.top == null || window.top === window) ? window : window.top;" + + " if (w." + FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE() + " === false || w." + FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS() + " == null || w." + FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS() + " === false) {" + + " return;" + + " }" + + " var self = this;" + " if (w." + FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE() + " == null || w." + FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE() + " == true) {" + " var headers = this.getAllResponseHeaders();" + " var responseHeaders = {};" + @@ -154,9 +172,9 @@ public static String INTERCEPT_AJAX_REQUEST_JS_SOURCE() { " var w = (window.top == null || window.top === window) ? window : window.top;" + " var canBeIntercepted = self._flutter_inappwebview_isAsync || w." + FLAG_VARIABLE_FOR_INTERCEPT_ONLY_ASYNC_AJAX_REQUESTS_JS_SOURCE() + " === false;" + " if (canBeIntercepted && (w." + FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE() + " == null || w." + FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE() + " == true)) {" + - " if (!this._flutter_inappwebview_already_onreadystatechange_wrapped) {" + + " if (w." + FLAG_VARIABLE_FOR_ON_AJAX_READY_STATE_CHANGE() + " === true && !this._flutter_inappwebview_already_onreadystatechange_wrapped) {" + " this._flutter_inappwebview_already_onreadystatechange_wrapped = true;" + - " var onreadystatechange = this.onreadystatechange;" + + " var realOnreadystatechange = this.onreadystatechange;" + " this.onreadystatechange = function() {" + " var w = (window.top == null || window.top === window) ? window : window.top;" + " if (w." + FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE() + " == null || w." + FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE() + " == true) {" + @@ -198,13 +216,13 @@ public static String INTERCEPT_AJAX_REQUEST_JS_SOURCE() { " return;" + " };" + " }" + - " if (onreadystatechange != null) {" + - " onreadystatechange();" + + " if (realOnreadystatechange != null) {" + + " realOnreadystatechange();" + " }" + " });" + " });" + - " } else if (onreadystatechange != null) {" + - " onreadystatechange();" + + " } else if (realOnreadystatechange != null) {" + + " realOnreadystatechange();" + " }" + " };" + " }" + diff --git a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebView.java b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebView.java index df78efdcb..27a658979 100755 --- a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebView.java +++ b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebView.java @@ -614,8 +614,11 @@ public void prepareAndAddUserScripts() { interceptOnlyAsyncAjaxRequestsPluginScript = InterceptAjaxRequestJS.createInterceptOnlyAsyncAjaxRequestsPluginScript(customSettings.interceptOnlyAsyncAjaxRequests); if (customSettings.useShouldInterceptAjaxRequest) { userContentController.addPluginScript(interceptOnlyAsyncAjaxRequestsPluginScript); - userContentController.addPluginScript(InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(customSettings.pluginScriptsOriginAllowList, - customSettings.pluginScriptsForMainFrameOnly)); + userContentController.addPluginScript(InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT( + customSettings.pluginScriptsOriginAllowList, + customSettings.pluginScriptsForMainFrameOnly, + customSettings.useOnAjaxReadyStateChange, + customSettings.useOnAjaxProgress)); } if (customSettings.useShouldInterceptFetchRequest) { userContentController.addPluginScript(InterceptFetchRequestJS.INTERCEPT_FETCH_REQUEST_JS_PLUGIN_SCRIPT(customSettings.pluginScriptsOriginAllowList, @@ -835,11 +838,22 @@ public void setSettings(InAppWebViewSettings newCustomSettings, HashMap getCustomSettingsMap() { public void enablePluginScriptAtRuntime(final String flagVariable, final boolean enable, final PluginScript pluginScript) { - evaluateJavascript("window." + flagVariable, null, new ValueCallback() { + evaluateJavascript("((window.top == null || window.top === window) ? window : window.top)." + flagVariable, null, new ValueCallback() { @Override public void onReceiveValue(String value) { boolean alreadyLoaded = value != null && !value.equalsIgnoreCase("null"); if (alreadyLoaded) { - String enableSource = "window." + flagVariable + " = " + enable + ";"; + String enableSource = "((window.top == null || window.top === window) ? window : window.top)." + flagVariable + " = " + enable + ";"; evaluateJavascript(enableSource, null, null); if (!enable) { userContentController.removePluginScript(pluginScript); diff --git a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebViewSettings.java b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebViewSettings.java index 0b13b4406..19e9fd868 100755 --- a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebViewSettings.java +++ b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebViewSettings.java @@ -49,6 +49,8 @@ public class InAppWebViewSettings implements ISettings { public List>> contentBlockers = new ArrayList<>(); public Integer preferredContentMode = PreferredContentModeOptionType.RECOMMENDED.toValue(); public Boolean useShouldInterceptAjaxRequest = false; + public Boolean useOnAjaxReadyStateChange = false; + public Boolean useOnAjaxProgress = false; public Boolean interceptOnlyAsyncAjaxRequests = true; public Boolean useShouldInterceptFetchRequest = false; public Boolean incognito = false; @@ -219,6 +221,12 @@ public InAppWebViewSettings parse(@NonNull Map settings) { case "useShouldInterceptAjaxRequest": useShouldInterceptAjaxRequest = (Boolean) value; break; + case "useOnAjaxReadyStateChange": + useOnAjaxReadyStateChange = (Boolean) value; + break; + case "useOnAjaxProgress": + useOnAjaxProgress = (Boolean) value; + break; case "interceptOnlyAsyncAjaxRequests": interceptOnlyAsyncAjaxRequests = (Boolean) value; break; @@ -497,6 +505,8 @@ public Map toMap() { settings.put("contentBlockers", contentBlockers); settings.put("preferredContentMode", preferredContentMode); settings.put("useShouldInterceptAjaxRequest", useShouldInterceptAjaxRequest); + settings.put("useOnAjaxReadyStateChange", useOnAjaxReadyStateChange); + settings.put("useOnAjaxProgress", useOnAjaxProgress); settings.put("interceptOnlyAsyncAjaxRequests", interceptOnlyAsyncAjaxRequests); settings.put("useShouldInterceptFetchRequest", useShouldInterceptFetchRequest); settings.put("incognito", incognito); diff --git a/flutter_inappwebview_android/lib/src/in_app_webview/headless_in_app_webview.dart b/flutter_inappwebview_android/lib/src/in_app_webview/headless_in_app_webview.dart index ae3e4b1ee..32589db62 100644 --- a/flutter_inappwebview_android/lib/src/in_app_webview/headless_in_app_webview.dart +++ b/flutter_inappwebview_android/lib/src/in_app_webview/headless_in_app_webview.dart @@ -368,9 +368,19 @@ class AndroidHeadlessInAppWebView extends PlatformHeadlessInAppWebView settings.useOnDownloadStart == null) { settings.useOnDownloadStart = true; } - if (params.shouldInterceptAjaxRequest != null && - settings.useShouldInterceptAjaxRequest == null) { - settings.useShouldInterceptAjaxRequest = true; + if ((params.shouldInterceptAjaxRequest != null || + params.onAjaxProgress != null || + params.onAjaxReadyStateChange != null)) { + if (settings.useShouldInterceptAjaxRequest == null) { + settings.useShouldInterceptAjaxRequest = true; + } + if (params.onAjaxReadyStateChange != null && + settings.useOnAjaxReadyStateChange == null) { + settings.useOnAjaxReadyStateChange = true; + } + if (params.onAjaxProgress != null && settings.useOnAjaxProgress == null) { + settings.useOnAjaxProgress = true; + } } if (params.shouldInterceptFetchRequest != null && settings.useShouldInterceptFetchRequest == null) { diff --git a/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview.dart b/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview.dart index 928c171ed..a7c001b8d 100755 --- a/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview.dart +++ b/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview.dart @@ -431,10 +431,18 @@ class AndroidInAppWebViewWidget extends PlatformInAppWebViewWidget { settings.useOnDownloadStart = true; } if ((params.shouldInterceptAjaxRequest != null || - params.onAjaxProgress != null || - params.onAjaxReadyStateChange != null) && - settings.useShouldInterceptAjaxRequest == null) { - settings.useShouldInterceptAjaxRequest = true; + params.onAjaxProgress != null || + params.onAjaxReadyStateChange != null)) { + if (settings.useShouldInterceptAjaxRequest == null) { + settings.useShouldInterceptAjaxRequest = true; + } + if (params.onAjaxReadyStateChange != null && + settings.useOnAjaxReadyStateChange == null) { + settings.useOnAjaxReadyStateChange = true; + } + if (params.onAjaxProgress != null && settings.useOnAjaxProgress == null) { + settings.useOnAjaxProgress = true; + } } if (params.shouldInterceptFetchRequest != null && settings.useShouldInterceptFetchRequest == null) { diff --git a/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart index 7b2ff3c6b..919b7268f 100644 --- a/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart @@ -1455,13 +1455,13 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController if (webviewParams != null && webviewParams!.onAjaxReadyStateChange != null) - return (await webviewParams!.onAjaxReadyStateChange!( + return jsonEncode((await webviewParams!.onAjaxReadyStateChange!( _controllerFromPlatform, request)) - ?.toNativeValue(); + ?.toNativeValue()); else - return (await _inAppBrowserEventHandler! + return jsonEncode((await _inAppBrowserEventHandler! .onAjaxReadyStateChange(request)) - ?.toNativeValue(); + ?.toNativeValue()); } return null; case "onAjaxProgress": @@ -1474,13 +1474,13 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController if (webviewParams != null && webviewParams!.onAjaxProgress != null) - return (await webviewParams!.onAjaxProgress!( + return jsonEncode((await webviewParams!.onAjaxProgress!( _controllerFromPlatform, request)) - ?.toNativeValue(); + ?.toNativeValue()); else - return (await _inAppBrowserEventHandler! + return jsonEncode((await _inAppBrowserEventHandler! .onAjaxProgress(request)) - ?.toNativeValue(); + ?.toNativeValue()); } return null; case "shouldInterceptFetchRequest": diff --git a/flutter_inappwebview_ios/CHANGELOG.md b/flutter_inappwebview_ios/CHANGELOG.md index 5beff5de4..5bbf30252 100644 --- a/flutter_inappwebview_ios/CHANGELOG.md +++ b/flutter_inappwebview_ios/CHANGELOG.md @@ -6,6 +6,7 @@ - Merged "Add proxy support for iOS" [#2362](https://github.com/pichillilorenzo/flutter_inappwebview/pull/2362) (thanks to [yerkejs](https://github.com/yerkejs)) - Fixed "[iOS] Webview opened with windowId does not receive javascript handler callback." [#2393](https://github.com/pichillilorenzo/flutter_inappwebview/issues/2393) - Fixed internal javascript callback handlers when the WebView has windowId not null +- Fixed "When useShouldInterceptAjaxRequest is true, some ajax requests doesn't work" [#2197](https://github.com/pichillilorenzo/flutter_inappwebview/issues/2197) ## 1.2.0-beta.2 diff --git a/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebView.swift b/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebView.swift index 0d03b607d..52c0bae70 100755 --- a/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebView.swift +++ b/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebView.swift @@ -626,7 +626,10 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, if let interceptOnlyAsyncAjaxRequestsPluginScript = interceptOnlyAsyncAjaxRequestsPluginScript { configuration.userContentController.addPluginScript(interceptOnlyAsyncAjaxRequestsPluginScript) } - configuration.userContentController.addPluginScript(InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: pluginScriptsOriginAllowList, forMainFrameOnly: pluginScriptsForMainFrameOnly)) + configuration.userContentController.addPluginScript(InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: pluginScriptsOriginAllowList, + forMainFrameOnly: pluginScriptsForMainFrameOnly, + initialUseOnAjaxReadyStateChange: settings.useOnAjaxReadyStateChange, + initialUseOnAjaxProgress: settings.useOnAjaxProgress)) } if settings.useShouldInterceptFetchRequest { configuration.userContentController.addPluginScript(InterceptFetchRequestJS.INTERCEPT_FETCH_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: pluginScriptsOriginAllowList, forMainFrameOnly: pluginScriptsForMainFrameOnly)) @@ -1137,13 +1140,35 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, enablePluginScriptAtRuntime(flagVariable: InterceptAjaxRequestJS.FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE(), enable: newSettings.useShouldInterceptAjaxRequest, pluginScript: InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: newSettings.pluginScriptsOriginAllowList, - forMainFrameOnly: newSettings.pluginScriptsForMainFrameOnly)) + forMainFrameOnly: newSettings.pluginScriptsForMainFrameOnly, + initialUseOnAjaxReadyStateChange: newSettings.useOnAjaxReadyStateChange, + initialUseOnAjaxProgress: newSettings.useOnAjaxProgress)) } } else { newSettings.useShouldInterceptAjaxRequest = false } } + if newSettingsMap["useOnAjaxReadyStateChange"] != nil && settings?.useOnAjaxReadyStateChange != newSettings.useOnAjaxReadyStateChange { + if let applePayAPIEnabled = settings?.applePayAPIEnabled, !applePayAPIEnabled { + if javaScriptBridgeEnabled { + evaluateJavaScript("\(InterceptAjaxRequestJS.FLAG_VARIABLE_FOR_ON_AJAX_READY_STATE_CHANGE()) = \(newSettings.useOnAjaxReadyStateChange);") + } + } else { + newSettings.useOnAjaxReadyStateChange = false + } + } + + if newSettingsMap["useOnAjaxProgress"] != nil && settings?.useOnAjaxProgress != newSettings.useOnAjaxProgress { + if let applePayAPIEnabled = settings?.applePayAPIEnabled, !applePayAPIEnabled { + if javaScriptBridgeEnabled { + evaluateJavaScript("\(InterceptAjaxRequestJS.FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS()) = \(newSettings.useOnAjaxProgress);") + } + } else { + newSettings.useOnAjaxProgress = false + } + } + if newSettingsMap["interceptOnlyAsyncAjaxRequests"] != nil && settings?.interceptOnlyAsyncAjaxRequests != newSettings.interceptOnlyAsyncAjaxRequests { if let applePayAPIEnabled = settings?.applePayAPIEnabled, !applePayAPIEnabled, let interceptOnlyAsyncAjaxRequestsPluginScript = interceptOnlyAsyncAjaxRequestsPluginScript { diff --git a/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewSettings.swift b/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewSettings.swift index 94767c473..dc65eb0fc 100755 --- a/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewSettings.swift +++ b/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewSettings.swift @@ -27,6 +27,8 @@ public class InAppWebViewSettings: ISettings { var contentBlockers: [[String: [String : Any]]] = [] var minimumFontSize = 0 var useShouldInterceptAjaxRequest = false + var useOnAjaxReadyStateChange = false + var useOnAjaxProgress = false var interceptOnlyAsyncAjaxRequests = true var useShouldInterceptFetchRequest = false var incognito = false diff --git a/flutter_inappwebview_ios/ios/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift b/flutter_inappwebview_ios/ios/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift index 270cb648f..e8ca40c76 100644 --- a/flutter_inappwebview_ios/ios/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift +++ b/flutter_inappwebview_ios/ios/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift @@ -15,14 +15,22 @@ public class InterceptAjaxRequestJS { return "window.\(JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME())._useShouldInterceptAjaxRequest" } + public static func FLAG_VARIABLE_FOR_ON_AJAX_READY_STATE_CHANGE() -> String { + return "window.\(JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME())._useOnAjaxReadyStateChange" + } + + public static func FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS() -> String { + return "window.\(JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME())._useOnAjaxProgress" + } + public static func FLAG_VARIABLE_FOR_INTERCEPT_ONLY_ASYNC_AJAX_REQUESTS_JS_SOURCE() -> String { return "window.\(JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME())._interceptOnlyAsyncAjaxRequests" } - public static func INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: [String]?, forMainFrameOnly: Bool) -> PluginScript { + public static func INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: [String]?, forMainFrameOnly: Bool, initialUseOnAjaxReadyStateChange: Bool = false, initialUseOnAjaxProgress: Bool = false) -> PluginScript { return PluginScript( groupName: INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT_GROUP_NAME, - source: INTERCEPT_AJAX_REQUEST_JS_SOURCE(), + source: INTERCEPT_AJAX_REQUEST_JS_SOURCE(initialUseOnAjaxReadyStateChange: initialUseOnAjaxReadyStateChange, initialUseOnAjaxProgress: initialUseOnAjaxProgress), injectionTime: .atDocumentStart, forMainFrameOnly: forMainFrameOnly, allowedOriginRules: allowedOriginRules, @@ -41,9 +49,11 @@ public class InterceptAjaxRequestJS { ); } - public static func INTERCEPT_AJAX_REQUEST_JS_SOURCE() -> String { + public static func INTERCEPT_AJAX_REQUEST_JS_SOURCE(initialUseOnAjaxReadyStateChange: Bool, initialUseOnAjaxProgress: Bool) -> String { return """ \(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) = true; + \(FLAG_VARIABLE_FOR_ON_AJAX_READY_STATE_CHANGE()) = \(initialUseOnAjaxReadyStateChange); + \(FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS()) = \(initialUseOnAjaxProgress); (function(ajax) { var send = ajax.prototype.send; var open = ajax.prototype.open; @@ -94,6 +104,9 @@ public class InterceptAjaxRequestJS { setRequestHeader.call(this, header, value); }; function handleEvent(e) { + if (\(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) === false || \(FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS()) == null || \(FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS()) === false) { + return; + } var self = this; if (\(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == null || \(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == true) { var headers = this.getAllResponseHeaders(); @@ -148,9 +161,9 @@ public class InterceptAjaxRequestJS { var self = this; var canBeIntercepted = self._flutter_inappwebview_isAsync || \(FLAG_VARIABLE_FOR_INTERCEPT_ONLY_ASYNC_AJAX_REQUESTS_JS_SOURCE()) === false; if (canBeIntercepted && (\(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == null || \(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == true)) { - if (!this._flutter_inappwebview_already_onreadystatechange_wrapped) { + if (\(FLAG_VARIABLE_FOR_ON_AJAX_READY_STATE_CHANGE()) === true && !this._flutter_inappwebview_already_onreadystatechange_wrapped) { this._flutter_inappwebview_already_onreadystatechange_wrapped = true; - var onreadystatechange = this.onreadystatechange; + var realOnreadystatechange = this.onreadystatechange; this.onreadystatechange = function() { if (\(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == null || \(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == true) { var headers = this.getAllResponseHeaders(); @@ -191,13 +204,13 @@ public class InterceptAjaxRequestJS { return; }; } - if (onreadystatechange != null) { - onreadystatechange(); + if (realOnreadystatechange != null) { + realOnreadystatechange(); } }); }); - } else if (onreadystatechange != null) { - onreadystatechange(); + } else if (realOnreadystatechange != null) { + realOnreadystatechange(); } }; } diff --git a/flutter_inappwebview_ios/lib/src/in_app_webview/headless_in_app_webview.dart b/flutter_inappwebview_ios/lib/src/in_app_webview/headless_in_app_webview.dart index 19a112a8c..174329328 100644 --- a/flutter_inappwebview_ios/lib/src/in_app_webview/headless_in_app_webview.dart +++ b/flutter_inappwebview_ios/lib/src/in_app_webview/headless_in_app_webview.dart @@ -367,9 +367,18 @@ class IOSHeadlessInAppWebView extends PlatformHeadlessInAppWebView settings.useOnDownloadStart == null) { settings.useOnDownloadStart = true; } - if (params.shouldInterceptAjaxRequest != null && - settings.useShouldInterceptAjaxRequest == null) { - settings.useShouldInterceptAjaxRequest = true; + if ((params.shouldInterceptAjaxRequest != null || + params.onAjaxProgress != null || + params.onAjaxReadyStateChange != null)) { + if (settings.useShouldInterceptAjaxRequest == null) { + settings.useShouldInterceptAjaxRequest = true; + } + if (params.onAjaxReadyStateChange != null && settings.useOnAjaxReadyStateChange == null) { + settings.useOnAjaxReadyStateChange = true; + } + if (params.onAjaxProgress != null && settings.useOnAjaxProgress == null) { + settings.useOnAjaxProgress = true; + } } if (params.shouldInterceptFetchRequest != null && settings.useShouldInterceptFetchRequest == null) { diff --git a/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview.dart b/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview.dart index ba2ceb4fc..e2b9d622d 100755 --- a/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview.dart +++ b/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview.dart @@ -2,12 +2,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; -import 'headless_in_app_webview.dart'; import '../find_interaction/find_interaction_controller.dart'; -import 'in_app_webview_controller.dart'; -import '../pull_to_refresh/main.dart'; import '../pull_to_refresh/pull_to_refresh_controller.dart'; +import 'headless_in_app_webview.dart'; +import 'in_app_webview_controller.dart'; /// Object specifying creation parameters for creating a [PlatformInAppWebViewWidget]. /// @@ -372,10 +371,18 @@ class IOSInAppWebViewWidget extends PlatformInAppWebViewWidget { settings.useOnDownloadStart = true; } if ((params.shouldInterceptAjaxRequest != null || - params.onAjaxProgress != null || - params.onAjaxReadyStateChange != null) && - settings.useShouldInterceptAjaxRequest == null) { - settings.useShouldInterceptAjaxRequest = true; + params.onAjaxProgress != null || + params.onAjaxReadyStateChange != null)) { + if (settings.useShouldInterceptAjaxRequest == null) { + settings.useShouldInterceptAjaxRequest = true; + } + if (params.onAjaxReadyStateChange != null && + settings.useOnAjaxReadyStateChange == null) { + settings.useOnAjaxReadyStateChange = true; + } + if (params.onAjaxProgress != null && settings.useOnAjaxProgress == null) { + settings.useOnAjaxProgress = true; + } } if (params.shouldInterceptFetchRequest != null && settings.useShouldInterceptFetchRequest == null) { diff --git a/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart index 3dba6b4bc..f807fb8ff 100644 --- a/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart @@ -1451,13 +1451,13 @@ class IOSInAppWebViewController extends PlatformInAppWebViewController if (webviewParams != null && webviewParams!.onAjaxReadyStateChange != null) - return (await webviewParams!.onAjaxReadyStateChange!( + return jsonEncode((await webviewParams!.onAjaxReadyStateChange!( _controllerFromPlatform, request)) - ?.toNativeValue(); + ?.toNativeValue()); else - return (await _inAppBrowserEventHandler! + return jsonEncode((await _inAppBrowserEventHandler! .onAjaxReadyStateChange(request)) - ?.toNativeValue(); + ?.toNativeValue()); } return null; case "onAjaxProgress": @@ -1470,13 +1470,13 @@ class IOSInAppWebViewController extends PlatformInAppWebViewController if (webviewParams != null && webviewParams!.onAjaxProgress != null) - return (await webviewParams!.onAjaxProgress!( + return jsonEncode((await webviewParams!.onAjaxProgress!( _controllerFromPlatform, request)) - ?.toNativeValue(); + ?.toNativeValue()); else - return (await _inAppBrowserEventHandler! + return jsonEncode((await _inAppBrowserEventHandler! .onAjaxProgress(request)) - ?.toNativeValue(); + ?.toNativeValue()); } return null; case "shouldInterceptFetchRequest": diff --git a/flutter_inappwebview_macos/CHANGELOG.md b/flutter_inappwebview_macos/CHANGELOG.md index 3503989a0..825781e37 100644 --- a/flutter_inappwebview_macos/CHANGELOG.md +++ b/flutter_inappwebview_macos/CHANGELOG.md @@ -5,6 +5,7 @@ - Implemented `PlatformProxyController` class - Fixed internal javascript callback handlers when the WebView has windowId not null - Fixed crash of unhandled `onPrintRequest` WebView event +- Fixed "When useShouldInterceptAjaxRequest is true, some ajax requests doesn't work" [#2197](https://github.com/pichillilorenzo/flutter_inappwebview/issues/2197) ## 1.2.0-beta.2 diff --git a/flutter_inappwebview_macos/lib/src/in_app_webview/headless_in_app_webview.dart b/flutter_inappwebview_macos/lib/src/in_app_webview/headless_in_app_webview.dart index fb10ec681..eb4911ef7 100644 --- a/flutter_inappwebview_macos/lib/src/in_app_webview/headless_in_app_webview.dart +++ b/flutter_inappwebview_macos/lib/src/in_app_webview/headless_in_app_webview.dart @@ -361,9 +361,19 @@ class MacOSHeadlessInAppWebView extends PlatformHeadlessInAppWebView settings.useOnDownloadStart == null) { settings.useOnDownloadStart = true; } - if (params.shouldInterceptAjaxRequest != null && - settings.useShouldInterceptAjaxRequest == null) { - settings.useShouldInterceptAjaxRequest = true; + if ((params.shouldInterceptAjaxRequest != null || + params.onAjaxProgress != null || + params.onAjaxReadyStateChange != null)) { + if (settings.useShouldInterceptAjaxRequest == null) { + settings.useShouldInterceptAjaxRequest = true; + } + if (params.onAjaxReadyStateChange != null && + settings.useOnAjaxReadyStateChange == null) { + settings.useOnAjaxReadyStateChange = true; + } + if (params.onAjaxProgress != null && settings.useOnAjaxProgress == null) { + settings.useOnAjaxProgress = true; + } } if (params.shouldInterceptFetchRequest != null && settings.useShouldInterceptFetchRequest == null) { diff --git a/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview.dart b/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview.dart index 4d268b261..98f8b15bc 100755 --- a/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview.dart +++ b/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview.dart @@ -365,10 +365,18 @@ class MacOSInAppWebViewWidget extends PlatformInAppWebViewWidget { settings.useOnDownloadStart = true; } if ((params.shouldInterceptAjaxRequest != null || - params.onAjaxProgress != null || - params.onAjaxReadyStateChange != null) && - settings.useShouldInterceptAjaxRequest == null) { - settings.useShouldInterceptAjaxRequest = true; + params.onAjaxProgress != null || + params.onAjaxReadyStateChange != null)) { + if (settings.useShouldInterceptAjaxRequest == null) { + settings.useShouldInterceptAjaxRequest = true; + } + if (params.onAjaxReadyStateChange != null && + settings.useOnAjaxReadyStateChange == null) { + settings.useOnAjaxReadyStateChange = true; + } + if (params.onAjaxProgress != null && settings.useOnAjaxProgress == null) { + settings.useOnAjaxProgress = true; + } } if (params.shouldInterceptFetchRequest != null && settings.useShouldInterceptFetchRequest == null) { diff --git a/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview_controller.dart index 7c99c23f9..428dbe9dc 100644 --- a/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview_controller.dart @@ -1458,13 +1458,13 @@ class MacOSInAppWebViewController extends PlatformInAppWebViewController if (webviewParams != null && webviewParams!.onAjaxReadyStateChange != null) - return (await webviewParams!.onAjaxReadyStateChange!( + return jsonEncode((await webviewParams!.onAjaxReadyStateChange!( _controllerFromPlatform, request)) - ?.toNativeValue(); + ?.toNativeValue()); else - return (await _inAppBrowserEventHandler! + return jsonEncode((await _inAppBrowserEventHandler! .onAjaxReadyStateChange(request)) - ?.toNativeValue(); + ?.toNativeValue()); } return null; case "onAjaxProgress": @@ -1477,13 +1477,13 @@ class MacOSInAppWebViewController extends PlatformInAppWebViewController if (webviewParams != null && webviewParams!.onAjaxProgress != null) - return (await webviewParams!.onAjaxProgress!( + return jsonEncode((await webviewParams!.onAjaxProgress!( _controllerFromPlatform, request)) - ?.toNativeValue(); + ?.toNativeValue()); else - return (await _inAppBrowserEventHandler! + return jsonEncode((await _inAppBrowserEventHandler! .onAjaxProgress(request)) - ?.toNativeValue(); + ?.toNativeValue()); } return null; case "shouldInterceptFetchRequest": diff --git a/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebView.swift b/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebView.swift index 5f11efde8..425ce3551 100755 --- a/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebView.swift +++ b/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebView.swift @@ -237,7 +237,10 @@ public class InAppWebView: WKWebView, WKUIDelegate, if let interceptOnlyAsyncAjaxRequestsPluginScript = interceptOnlyAsyncAjaxRequestsPluginScript { configuration.userContentController.addPluginScript(interceptOnlyAsyncAjaxRequestsPluginScript) } - configuration.userContentController.addPluginScript(InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: pluginScriptsOriginAllowList, forMainFrameOnly: pluginScriptsForMainFrameOnly)) + configuration.userContentController.addPluginScript(InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: pluginScriptsOriginAllowList, + forMainFrameOnly: pluginScriptsForMainFrameOnly, + initialUseOnAjaxReadyStateChange: settings.useOnAjaxReadyStateChange, + initialUseOnAjaxProgress: settings.useOnAjaxProgress)) } if settings.useShouldInterceptFetchRequest { configuration.userContentController.addPluginScript(InterceptFetchRequestJS.INTERCEPT_FETCH_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: pluginScriptsOriginAllowList, forMainFrameOnly: pluginScriptsForMainFrameOnly)) @@ -632,13 +635,35 @@ public class InAppWebView: WKWebView, WKUIDelegate, enablePluginScriptAtRuntime(flagVariable: InterceptAjaxRequestJS.FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE(), enable: newSettings.useShouldInterceptAjaxRequest, pluginScript: InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: newSettings.pluginScriptsOriginAllowList, - forMainFrameOnly: newSettings.pluginScriptsForMainFrameOnly)) + forMainFrameOnly: newSettings.pluginScriptsForMainFrameOnly, + initialUseOnAjaxReadyStateChange: newSettings.useOnAjaxReadyStateChange, + initialUseOnAjaxProgress: newSettings.useOnAjaxProgress)) } } else { newSettings.useShouldInterceptAjaxRequest = false } } + if newSettingsMap["useOnAjaxReadyStateChange"] != nil && settings?.useOnAjaxReadyStateChange != newSettings.useOnAjaxReadyStateChange { + if let applePayAPIEnabled = settings?.applePayAPIEnabled, !applePayAPIEnabled { + if javaScriptBridgeEnabled { + evaluateJavaScript("\(InterceptAjaxRequestJS.FLAG_VARIABLE_FOR_ON_AJAX_READY_STATE_CHANGE()) = \(newSettings.useOnAjaxReadyStateChange);") + } + } else { + newSettings.useOnAjaxReadyStateChange = false + } + } + + if newSettingsMap["useOnAjaxProgress"] != nil && settings?.useOnAjaxProgress != newSettings.useOnAjaxProgress { + if let applePayAPIEnabled = settings?.applePayAPIEnabled, !applePayAPIEnabled { + if javaScriptBridgeEnabled { + evaluateJavaScript("\(InterceptAjaxRequestJS.FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS()) = \(newSettings.useOnAjaxProgress);") + } + } else { + newSettings.useOnAjaxProgress = false + } + } + if newSettingsMap["interceptOnlyAsyncAjaxRequests"] != nil && settings?.interceptOnlyAsyncAjaxRequests != newSettings.interceptOnlyAsyncAjaxRequests { if let applePayAPIEnabled = settings?.applePayAPIEnabled, !applePayAPIEnabled, let interceptOnlyAsyncAjaxRequestsPluginScript = interceptOnlyAsyncAjaxRequestsPluginScript { diff --git a/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewSettings.swift b/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewSettings.swift index fadecf0a0..d2785dfca 100755 --- a/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewSettings.swift +++ b/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewSettings.swift @@ -25,6 +25,8 @@ public class InAppWebViewSettings: ISettings { var contentBlockers: [[String: [String : Any]]] = [] var minimumFontSize = 0 var useShouldInterceptAjaxRequest = false + var useOnAjaxReadyStateChange = false + var useOnAjaxProgress = false var interceptOnlyAsyncAjaxRequests = true var useShouldInterceptFetchRequest = false var incognito = false diff --git a/flutter_inappwebview_macos/macos/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift b/flutter_inappwebview_macos/macos/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift index 270cb648f..e8ca40c76 100644 --- a/flutter_inappwebview_macos/macos/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift +++ b/flutter_inappwebview_macos/macos/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift @@ -15,14 +15,22 @@ public class InterceptAjaxRequestJS { return "window.\(JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME())._useShouldInterceptAjaxRequest" } + public static func FLAG_VARIABLE_FOR_ON_AJAX_READY_STATE_CHANGE() -> String { + return "window.\(JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME())._useOnAjaxReadyStateChange" + } + + public static func FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS() -> String { + return "window.\(JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME())._useOnAjaxProgress" + } + public static func FLAG_VARIABLE_FOR_INTERCEPT_ONLY_ASYNC_AJAX_REQUESTS_JS_SOURCE() -> String { return "window.\(JavaScriptBridgeJS.get_JAVASCRIPT_BRIDGE_NAME())._interceptOnlyAsyncAjaxRequests" } - public static func INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: [String]?, forMainFrameOnly: Bool) -> PluginScript { + public static func INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT(allowedOriginRules: [String]?, forMainFrameOnly: Bool, initialUseOnAjaxReadyStateChange: Bool = false, initialUseOnAjaxProgress: Bool = false) -> PluginScript { return PluginScript( groupName: INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT_GROUP_NAME, - source: INTERCEPT_AJAX_REQUEST_JS_SOURCE(), + source: INTERCEPT_AJAX_REQUEST_JS_SOURCE(initialUseOnAjaxReadyStateChange: initialUseOnAjaxReadyStateChange, initialUseOnAjaxProgress: initialUseOnAjaxProgress), injectionTime: .atDocumentStart, forMainFrameOnly: forMainFrameOnly, allowedOriginRules: allowedOriginRules, @@ -41,9 +49,11 @@ public class InterceptAjaxRequestJS { ); } - public static func INTERCEPT_AJAX_REQUEST_JS_SOURCE() -> String { + public static func INTERCEPT_AJAX_REQUEST_JS_SOURCE(initialUseOnAjaxReadyStateChange: Bool, initialUseOnAjaxProgress: Bool) -> String { return """ \(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) = true; + \(FLAG_VARIABLE_FOR_ON_AJAX_READY_STATE_CHANGE()) = \(initialUseOnAjaxReadyStateChange); + \(FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS()) = \(initialUseOnAjaxProgress); (function(ajax) { var send = ajax.prototype.send; var open = ajax.prototype.open; @@ -94,6 +104,9 @@ public class InterceptAjaxRequestJS { setRequestHeader.call(this, header, value); }; function handleEvent(e) { + if (\(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) === false || \(FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS()) == null || \(FLAG_VARIABLE_FOR_ON_AJAX_PROGRESS()) === false) { + return; + } var self = this; if (\(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == null || \(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == true) { var headers = this.getAllResponseHeaders(); @@ -148,9 +161,9 @@ public class InterceptAjaxRequestJS { var self = this; var canBeIntercepted = self._flutter_inappwebview_isAsync || \(FLAG_VARIABLE_FOR_INTERCEPT_ONLY_ASYNC_AJAX_REQUESTS_JS_SOURCE()) === false; if (canBeIntercepted && (\(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == null || \(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == true)) { - if (!this._flutter_inappwebview_already_onreadystatechange_wrapped) { + if (\(FLAG_VARIABLE_FOR_ON_AJAX_READY_STATE_CHANGE()) === true && !this._flutter_inappwebview_already_onreadystatechange_wrapped) { this._flutter_inappwebview_already_onreadystatechange_wrapped = true; - var onreadystatechange = this.onreadystatechange; + var realOnreadystatechange = this.onreadystatechange; this.onreadystatechange = function() { if (\(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == null || \(FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE()) == true) { var headers = this.getAllResponseHeaders(); @@ -191,13 +204,13 @@ public class InterceptAjaxRequestJS { return; }; } - if (onreadystatechange != null) { - onreadystatechange(); + if (realOnreadystatechange != null) { + realOnreadystatechange(); } }); }); - } else if (onreadystatechange != null) { - onreadystatechange(); + } else if (realOnreadystatechange != null) { + realOnreadystatechange(); } }; } diff --git a/flutter_inappwebview_platform_interface/CHANGELOG.md b/flutter_inappwebview_platform_interface/CHANGELOG.md index 3b96cbe40..4c4eb434c 100644 --- a/flutter_inappwebview_platform_interface/CHANGELOG.md +++ b/flutter_inappwebview_platform_interface/CHANGELOG.md @@ -1,6 +1,7 @@ ## 1.4.0-beta.3 - Added `saveState`, `restoreState` methods to `PlatformInAppWebViewController` class +- Added `useOnAjaxReadyStateChange`, `useOnAjaxProgress` properties to `InAppWebViewSettings` ## 1.4.0-beta.2 diff --git a/flutter_inappwebview_platform_interface/lib/src/in_app_browser/platform_in_app_browser.dart b/flutter_inappwebview_platform_interface/lib/src/in_app_browser/platform_in_app_browser.dart index 5e9f3b9bc..018bccab7 100755 --- a/flutter_inappwebview_platform_interface/lib/src/in_app_browser/platform_in_app_browser.dart +++ b/flutter_inappwebview_platform_interface/lib/src/in_app_browser/platform_in_app_browser.dart @@ -24,6 +24,7 @@ import 'in_app_browser_menu_item.dart'; import 'in_app_browser_settings.dart'; import '../debug_logging_settings.dart'; import '../pull_to_refresh/platform_pull_to_refresh_controller.dart'; +import '../platform_webview_feature.dart'; /// Object specifying creation parameters for creating a [PlatformInAppBrowser]. /// @@ -873,11 +874,17 @@ abstract class PlatformInAppBrowserEvents { ///Event fired when an `XMLHttpRequest` is sent to a server. ///It gives the host application a chance to take control over the request before sending it. + ///This event is implemented using JavaScript under the hood. + /// + ///Due to the async nature of this event implementation, it will intercept only async `XMLHttpRequest`s ([AjaxRequest.isAsync] with `true`). + ///To be able to intercept sync `XMLHttpRequest`s, use [InAppWebViewSettings.interceptOnlyAsyncAjaxRequests] to `false`. + ///If necessary, you should implement your own logic using for example an [UserScript] overriding the + ///[XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) JavaScript object. /// ///[ajaxRequest] represents the `XMLHttpRequest`. /// ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptAjaxRequest] setting to `true`. - ///Also, unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that + ///Also, on Android that doesn't support the [WebViewFeature.DOCUMENT_START_SCRIPT], unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that ///can inject javascript code right after the document element is created but before any other content is loaded, in Android the javascript code ///used to intercept ajax requests is loaded as soon as possible so it won't be instantaneous as iOS but just after some milliseconds (< ~100ms). ///Inside the `window.addEventListener("flutterInAppWebViewPlatformReady")` event, the ajax requests will be intercept for sure. @@ -892,12 +899,18 @@ abstract class PlatformInAppBrowserEvents { ///Event fired whenever the `readyState` attribute of an `XMLHttpRequest` changes. ///It gives the host application a chance to abort the request. + ///This event is implemented using JavaScript under the hood. + /// + ///Due to the async nature of this event implementation, + ///using it could cause some issues, so, be careful when using it. + ///In this case, you should implement your own logic using for example an [UserScript] overriding the + ///[XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) JavaScript object. /// ///[ajaxRequest] represents the [XMLHttpRequest]. /// - ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptAjaxRequest] setting to `true`. - ///Also, unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that - ///can inject javascript code right after the document element is created but before any other content is loaded, in Android the javascript code + ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptAjaxRequest] and [InAppWebViewSettings.useOnAjaxReadyStateChange] settings to `true`. + ///Also, on Android that doesn't support the [WebViewFeature.DOCUMENT_START_SCRIPT], unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that + ///can inject javascript code right after the document element is created but before any other content is loaded, the javascript code ///used to intercept ajax requests is loaded as soon as possible so it won't be instantaneous as iOS but just after some milliseconds (< ~100ms). ///Inside the `window.addEventListener("flutterInAppWebViewPlatformReady")` event, the ajax requests will be intercept for sure. /// @@ -912,11 +925,12 @@ abstract class PlatformInAppBrowserEvents { ///Event fired as an `XMLHttpRequest` progress. ///It gives the host application a chance to abort the request. + ///This event is implemented using JavaScript under the hood. /// ///[ajaxRequest] represents the [XMLHttpRequest]. /// - ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptAjaxRequest] setting to `true`. - ///Also, unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that + ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptAjaxRequest] and [InAppWebViewSettings.useOnAjaxProgress] settings to `true`. + ///Also, on Android that doesn't support the [WebViewFeature.DOCUMENT_START_SCRIPT], unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that ///can inject javascript code right after the document element is created but before any other content is loaded, in Android the javascript code ///used to intercept ajax requests is loaded as soon as possible so it won't be instantaneous as iOS but just after some milliseconds (< ~100ms). ///Inside the `window.addEventListener("flutterInAppWebViewPlatformReady")` event, the ajax requests will be intercept for sure. @@ -931,11 +945,12 @@ abstract class PlatformInAppBrowserEvents { ///Event fired when a request is sent to a server through [Fetch API](https://developer.mozilla.org/it/docs/Web/API/Fetch_API). ///It gives the host application a chance to take control over the request before sending it. + ///This event is implemented using JavaScript under the hood. /// ///[fetchRequest] represents a resource request. /// ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptFetchRequest] setting to `true`. - ///Also, unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that + ///Also, on Android that doesn't support the [WebViewFeature.DOCUMENT_START_SCRIPT], unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that ///can inject javascript code right after the document element is created but before any other content is loaded, in Android the javascript code ///used to intercept fetch requests is loaded as soon as possible so it won't be instantaneous as iOS but just after some milliseconds (< ~100ms). ///Inside the `window.addEventListener("flutterInAppWebViewPlatformReady")` event, the fetch requests will be intercept for sure. diff --git a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.dart b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.dart index d0e5ffd15..88587804c 100755 --- a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.dart +++ b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.dart @@ -264,15 +264,46 @@ class InAppWebViewSettings_ { ///Due to the async nature of [PlatformWebViewCreationParams.shouldInterceptAjaxRequest] event implementation, ///it will intercept only async `XMLHttpRequest`s ([AjaxRequest.isAsync] with `true`). ///To be able to intercept sync `XMLHttpRequest`s, use [InAppWebViewSettings.interceptOnlyAsyncAjaxRequests] to `false`. + ///If necessary, you should implement your own logic using for example an [UserScript] overriding the + ///[XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) JavaScript object. /// - ///If the [PlatformWebViewCreationParams.shouldInterceptAjaxRequest] event or - ///any other Ajax event is implemented and this value is `null`, + ///If the [PlatformWebViewCreationParams.shouldInterceptAjaxRequest] event is implemented and this value is `null`, ///it will be automatically inferred as `true`, otherwise, the default value is `false`. ///This logic will not be applied for [PlatformInAppBrowser], where you must set the value manually. @SupportedPlatforms( platforms: [AndroidPlatform(), IOSPlatform(), MacOSPlatform()]) bool? useShouldInterceptAjaxRequest; + ///Set to `true` to be able to listen at the [PlatformWebViewCreationParams.onAjaxReadyStateChange] event. + ///Also, [useShouldInterceptAjaxRequest] must be set to `true` to take effect. + /// + ///Due to the async nature of [PlatformWebViewCreationParams.onAjaxReadyStateChange] event implementation, + ///using it could cause some issues, so, be careful when using it. + ///In this case, you should implement your own logic using for example an [UserScript] overriding the + ///[XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) JavaScript object. + /// + ///If the [PlatformWebViewCreationParams.onAjaxReadyStateChange] event is implemented and this value is `null`, + ///it will be automatically inferred as `true`, otherwise, the default value is `false`. + ///This logic will not be applied for [PlatformInAppBrowser], where you must set the value manually. + @SupportedPlatforms( + platforms: [AndroidPlatform(), IOSPlatform(), MacOSPlatform()]) + bool? useOnAjaxReadyStateChange; + + ///Set to `true` to be able to listen at the [PlatformWebViewCreationParams.onAjaxProgress] event. + ///Also, [useShouldInterceptAjaxRequest] must be set to `true` to take effect. + /// + ///Due to the async nature of [PlatformWebViewCreationParams.onAjaxProgress] event implementation, + ///using it could cause some issues, so, be careful when using it. + ///In this case, you should implement your own logic using for example an [UserScript] overriding the + ///[XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) JavaScript object. + /// + ///If the [PlatformWebViewCreationParams.onAjaxProgress] event is implemented and this value is `null`, + ///it will be automatically inferred as `true`, otherwise, the default value is `false`. + ///This logic will not be applied for [PlatformInAppBrowser], where you must set the value manually. + @SupportedPlatforms( + platforms: [AndroidPlatform(), IOSPlatform(), MacOSPlatform()]) + bool? useOnAjaxProgress; + ///Set to `false` to be able to listen to also sync `XMLHttpRequest`s at the ///[PlatformWebViewCreationParams.shouldInterceptAjaxRequest] event. /// @@ -2078,6 +2109,8 @@ as it can cause framerate drops on animations in Android 9 and lower (see [Hybri this.contentBlockers = const [], this.preferredContentMode = UserPreferredContentMode_.RECOMMENDED, this.useShouldInterceptAjaxRequest, + this.useOnAjaxReadyStateChange, + this.useOnAjaxProgress, this.interceptOnlyAsyncAjaxRequests = true, this.useShouldInterceptFetchRequest, this.incognito = false, diff --git a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.g.dart b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.g.dart index eaf9c52f4..5fd8875cf 100644 --- a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.g.dart +++ b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.g.dart @@ -1397,6 +1397,42 @@ class InAppWebViewSettings { ///- Android native WebView bool? useHybridComposition; + ///Set to `true` to be able to listen at the [PlatformWebViewCreationParams.onAjaxProgress] event. + ///Also, [useShouldInterceptAjaxRequest] must be set to `true` to take effect. + /// + ///Due to the async nature of [PlatformWebViewCreationParams.onAjaxProgress] event implementation, + ///using it could cause some issues, so, be careful when using it. + ///In this case, you should implement your own logic using for example an [UserScript] overriding the + ///[XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) JavaScript object. + /// + ///If the [PlatformWebViewCreationParams.onAjaxProgress] event is implemented and this value is `null`, + ///it will be automatically inferred as `true`, otherwise, the default value is `false`. + ///This logic will not be applied for [PlatformInAppBrowser], where you must set the value manually. + /// + ///**Officially Supported Platforms/Implementations**: + ///- Android native WebView + ///- iOS + ///- MacOS + bool? useOnAjaxProgress; + + ///Set to `true` to be able to listen at the [PlatformWebViewCreationParams.onAjaxReadyStateChange] event. + ///Also, [useShouldInterceptAjaxRequest] must be set to `true` to take effect. + /// + ///Due to the async nature of [PlatformWebViewCreationParams.onAjaxReadyStateChange] event implementation, + ///using it could cause some issues, so, be careful when using it. + ///In this case, you should implement your own logic using for example an [UserScript] overriding the + ///[XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) JavaScript object. + /// + ///If the [PlatformWebViewCreationParams.onAjaxReadyStateChange] event is implemented and this value is `null`, + ///it will be automatically inferred as `true`, otherwise, the default value is `false`. + ///This logic will not be applied for [PlatformInAppBrowser], where you must set the value manually. + /// + ///**Officially Supported Platforms/Implementations**: + ///- Android native WebView + ///- iOS + ///- MacOS + bool? useOnAjaxReadyStateChange; + ///Set to `true` to be able to listen at the [PlatformWebViewCreationParams.onDownloadStartRequest] event. /// ///If the [PlatformWebViewCreationParams.onDownloadStartRequest] event is implemented and this value is `null`, @@ -1447,9 +1483,10 @@ class InAppWebViewSettings { ///Due to the async nature of [PlatformWebViewCreationParams.shouldInterceptAjaxRequest] event implementation, ///it will intercept only async `XMLHttpRequest`s ([AjaxRequest.isAsync] with `true`). ///To be able to intercept sync `XMLHttpRequest`s, use [InAppWebViewSettings.interceptOnlyAsyncAjaxRequests] to `false`. + ///If necessary, you should implement your own logic using for example an [UserScript] overriding the + ///[XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) JavaScript object. /// - ///If the [PlatformWebViewCreationParams.shouldInterceptAjaxRequest] event or - ///any other Ajax event is implemented and this value is `null`, + ///If the [PlatformWebViewCreationParams.shouldInterceptAjaxRequest] event is implemented and this value is `null`, ///it will be automatically inferred as `true`, otherwise, the default value is `false`. ///This logic will not be applied for [PlatformInAppBrowser], where you must set the value manually. /// @@ -1565,6 +1602,8 @@ class InAppWebViewSettings { this.contentBlockers = const [], this.preferredContentMode = UserPreferredContentMode.RECOMMENDED, this.useShouldInterceptAjaxRequest, + this.useOnAjaxReadyStateChange, + this.useOnAjaxProgress, this.interceptOnlyAsyncAjaxRequests = true, this.useShouldInterceptFetchRequest, this.incognito = false, @@ -1852,6 +1891,8 @@ class InAppWebViewSettings { underPageBackgroundColor: map['underPageBackgroundColor'] != null ? UtilColor.fromStringRepresentation(map['underPageBackgroundColor']) : null, + useOnAjaxProgress: map['useOnAjaxProgress'], + useOnAjaxReadyStateChange: map['useOnAjaxReadyStateChange'], useOnDownloadStart: map['useOnDownloadStart'], useOnLoadResource: map['useOnLoadResource'], useOnNavigationResponse: map['useOnNavigationResponse'], @@ -2305,6 +2346,8 @@ class InAppWebViewSettings { "underPageBackgroundColor": underPageBackgroundColor?.toHex(), "upgradeKnownHostsToHTTPS": upgradeKnownHostsToHTTPS, "useHybridComposition": useHybridComposition, + "useOnAjaxProgress": useOnAjaxProgress, + "useOnAjaxReadyStateChange": useOnAjaxReadyStateChange, "useOnDownloadStart": useOnDownloadStart, "useOnLoadResource": useOnLoadResource, "useOnNavigationResponse": useOnNavigationResponse, @@ -2340,6 +2383,6 @@ class InAppWebViewSettings { @override String toString() { - return 'InAppWebViewSettings{accessibilityIgnoresInvertColors: $accessibilityIgnoresInvertColors, algorithmicDarkeningAllowed: $algorithmicDarkeningAllowed, allowBackgroundAudioPlaying: $allowBackgroundAudioPlaying, allowContentAccess: $allowContentAccess, allowFileAccess: $allowFileAccess, allowFileAccessFromFileURLs: $allowFileAccessFromFileURLs, allowUniversalAccessFromFileURLs: $allowUniversalAccessFromFileURLs, allowingReadAccessTo: $allowingReadAccessTo, allowsAirPlayForMediaPlayback: $allowsAirPlayForMediaPlayback, allowsBackForwardNavigationGestures: $allowsBackForwardNavigationGestures, allowsInlineMediaPlayback: $allowsInlineMediaPlayback, allowsLinkPreview: $allowsLinkPreview, allowsPictureInPictureMediaPlayback: $allowsPictureInPictureMediaPlayback, alpha: $alpha, alwaysBounceHorizontal: $alwaysBounceHorizontal, alwaysBounceVertical: $alwaysBounceVertical, appCachePath: $appCachePath, applePayAPIEnabled: $applePayAPIEnabled, applicationNameForUserAgent: $applicationNameForUserAgent, automaticallyAdjustsScrollIndicatorInsets: $automaticallyAdjustsScrollIndicatorInsets, blockNetworkImage: $blockNetworkImage, blockNetworkLoads: $blockNetworkLoads, browserAcceleratorKeysEnabled: $browserAcceleratorKeysEnabled, builtInZoomControls: $builtInZoomControls, cacheEnabled: $cacheEnabled, cacheMode: $cacheMode, contentBlockers: $contentBlockers, contentInsetAdjustmentBehavior: $contentInsetAdjustmentBehavior, cursiveFontFamily: $cursiveFontFamily, dataDetectorTypes: $dataDetectorTypes, databaseEnabled: $databaseEnabled, decelerationRate: $decelerationRate, defaultFixedFontSize: $defaultFixedFontSize, defaultFontSize: $defaultFontSize, defaultTextEncodingName: $defaultTextEncodingName, defaultVideoPoster: $defaultVideoPoster, disableContextMenu: $disableContextMenu, disableDefaultErrorPage: $disableDefaultErrorPage, disableHorizontalScroll: $disableHorizontalScroll, disableInputAccessoryView: $disableInputAccessoryView, disableLongPressContextMenuOnLinks: $disableLongPressContextMenuOnLinks, disableVerticalScroll: $disableVerticalScroll, disabledActionModeMenuItems: $disabledActionModeMenuItems, disallowOverScroll: $disallowOverScroll, displayZoomControls: $displayZoomControls, domStorageEnabled: $domStorageEnabled, enableViewportScale: $enableViewportScale, enterpriseAuthenticationAppLinkPolicyEnabled: $enterpriseAuthenticationAppLinkPolicyEnabled, fantasyFontFamily: $fantasyFontFamily, fixedFontFamily: $fixedFontFamily, generalAutofillEnabled: $generalAutofillEnabled, geolocationEnabled: $geolocationEnabled, handleAcceleratorKeyPressed: $handleAcceleratorKeyPressed, hardwareAcceleration: $hardwareAcceleration, hiddenPdfToolbarItems: $hiddenPdfToolbarItems, horizontalScrollBarEnabled: $horizontalScrollBarEnabled, horizontalScrollbarThumbColor: $horizontalScrollbarThumbColor, horizontalScrollbarTrackColor: $horizontalScrollbarTrackColor, iframeAllow: $iframeAllow, iframeAllowFullscreen: $iframeAllowFullscreen, iframeAriaHidden: $iframeAriaHidden, iframeCsp: $iframeCsp, iframeName: $iframeName, iframeReferrerPolicy: $iframeReferrerPolicy, iframeRole: $iframeRole, iframeSandbox: $iframeSandbox, ignoresViewportScaleLimits: $ignoresViewportScaleLimits, incognito: $incognito, initialScale: $initialScale, interceptOnlyAsyncAjaxRequests: $interceptOnlyAsyncAjaxRequests, isDirectionalLockEnabled: $isDirectionalLockEnabled, isElementFullscreenEnabled: $isElementFullscreenEnabled, isFindInteractionEnabled: $isFindInteractionEnabled, isFraudulentWebsiteWarningEnabled: $isFraudulentWebsiteWarningEnabled, isInspectable: $isInspectable, isPagingEnabled: $isPagingEnabled, isSiteSpecificQuirksModeEnabled: $isSiteSpecificQuirksModeEnabled, isTextInteractionEnabled: $isTextInteractionEnabled, isUserInteractionEnabled: $isUserInteractionEnabled, javaScriptBridgeEnabled: $javaScriptBridgeEnabled, javaScriptBridgeForMainFrameOnly: $javaScriptBridgeForMainFrameOnly, javaScriptBridgeOriginAllowList: $javaScriptBridgeOriginAllowList, javaScriptCanOpenWindowsAutomatically: $javaScriptCanOpenWindowsAutomatically, javaScriptEnabled: $javaScriptEnabled, javaScriptHandlersForMainFrameOnly: $javaScriptHandlersForMainFrameOnly, javaScriptHandlersOriginAllowList: $javaScriptHandlersOriginAllowList, layoutAlgorithm: $layoutAlgorithm, limitsNavigationsToAppBoundDomains: $limitsNavigationsToAppBoundDomains, loadWithOverviewMode: $loadWithOverviewMode, loadsImagesAutomatically: $loadsImagesAutomatically, maximumViewportInset: $maximumViewportInset, maximumZoomScale: $maximumZoomScale, mediaPlaybackRequiresUserGesture: $mediaPlaybackRequiresUserGesture, mediaType: $mediaType, minimumFontSize: $minimumFontSize, minimumLogicalFontSize: $minimumLogicalFontSize, minimumViewportInset: $minimumViewportInset, minimumZoomScale: $minimumZoomScale, mixedContentMode: $mixedContentMode, needInitialFocus: $needInitialFocus, networkAvailable: $networkAvailable, nonClientRegionSupportEnabled: $nonClientRegionSupportEnabled, offscreenPreRaster: $offscreenPreRaster, overScrollMode: $overScrollMode, pageZoom: $pageZoom, passwordAutosaveEnabled: $passwordAutosaveEnabled, pinchZoomEnabled: $pinchZoomEnabled, pluginScriptsForMainFrameOnly: $pluginScriptsForMainFrameOnly, pluginScriptsOriginAllowList: $pluginScriptsOriginAllowList, preferredContentMode: $preferredContentMode, regexToAllowSyncUrlLoading: $regexToAllowSyncUrlLoading, regexToCancelSubFramesLoading: $regexToCancelSubFramesLoading, rendererPriorityPolicy: $rendererPriorityPolicy, reputationCheckingRequired: $reputationCheckingRequired, requestedWithHeaderOriginAllowList: $requestedWithHeaderOriginAllowList, resourceCustomSchemes: $resourceCustomSchemes, safeBrowsingEnabled: $safeBrowsingEnabled, sansSerifFontFamily: $sansSerifFontFamily, scrollBarDefaultDelayBeforeFade: $scrollBarDefaultDelayBeforeFade, scrollBarFadeDuration: $scrollBarFadeDuration, scrollBarStyle: $scrollBarStyle, scrollMultiplier: $scrollMultiplier, scrollbarFadingEnabled: $scrollbarFadingEnabled, scrollsToTop: $scrollsToTop, selectionGranularity: $selectionGranularity, serifFontFamily: $serifFontFamily, sharedCookiesEnabled: $sharedCookiesEnabled, shouldPrintBackgrounds: $shouldPrintBackgrounds, standardFontFamily: $standardFontFamily, statusBarEnabled: $statusBarEnabled, supportMultipleWindows: $supportMultipleWindows, supportZoom: $supportZoom, suppressesIncrementalRendering: $suppressesIncrementalRendering, textZoom: $textZoom, thirdPartyCookiesEnabled: $thirdPartyCookiesEnabled, transparentBackground: $transparentBackground, underPageBackgroundColor: $underPageBackgroundColor, upgradeKnownHostsToHTTPS: $upgradeKnownHostsToHTTPS, useHybridComposition: $useHybridComposition, useOnDownloadStart: $useOnDownloadStart, useOnLoadResource: $useOnLoadResource, useOnNavigationResponse: $useOnNavigationResponse, useOnRenderProcessGone: $useOnRenderProcessGone, useShouldInterceptAjaxRequest: $useShouldInterceptAjaxRequest, useShouldInterceptFetchRequest: $useShouldInterceptFetchRequest, useShouldInterceptRequest: $useShouldInterceptRequest, useShouldOverrideUrlLoading: $useShouldOverrideUrlLoading, useWideViewPort: $useWideViewPort, userAgent: $userAgent, verticalScrollBarEnabled: $verticalScrollBarEnabled, verticalScrollbarPosition: $verticalScrollbarPosition, verticalScrollbarThumbColor: $verticalScrollbarThumbColor, verticalScrollbarTrackColor: $verticalScrollbarTrackColor, webViewAssetLoader: $webViewAssetLoader}'; + return 'InAppWebViewSettings{accessibilityIgnoresInvertColors: $accessibilityIgnoresInvertColors, algorithmicDarkeningAllowed: $algorithmicDarkeningAllowed, allowBackgroundAudioPlaying: $allowBackgroundAudioPlaying, allowContentAccess: $allowContentAccess, allowFileAccess: $allowFileAccess, allowFileAccessFromFileURLs: $allowFileAccessFromFileURLs, allowUniversalAccessFromFileURLs: $allowUniversalAccessFromFileURLs, allowingReadAccessTo: $allowingReadAccessTo, allowsAirPlayForMediaPlayback: $allowsAirPlayForMediaPlayback, allowsBackForwardNavigationGestures: $allowsBackForwardNavigationGestures, allowsInlineMediaPlayback: $allowsInlineMediaPlayback, allowsLinkPreview: $allowsLinkPreview, allowsPictureInPictureMediaPlayback: $allowsPictureInPictureMediaPlayback, alpha: $alpha, alwaysBounceHorizontal: $alwaysBounceHorizontal, alwaysBounceVertical: $alwaysBounceVertical, appCachePath: $appCachePath, applePayAPIEnabled: $applePayAPIEnabled, applicationNameForUserAgent: $applicationNameForUserAgent, automaticallyAdjustsScrollIndicatorInsets: $automaticallyAdjustsScrollIndicatorInsets, blockNetworkImage: $blockNetworkImage, blockNetworkLoads: $blockNetworkLoads, browserAcceleratorKeysEnabled: $browserAcceleratorKeysEnabled, builtInZoomControls: $builtInZoomControls, cacheEnabled: $cacheEnabled, cacheMode: $cacheMode, contentBlockers: $contentBlockers, contentInsetAdjustmentBehavior: $contentInsetAdjustmentBehavior, cursiveFontFamily: $cursiveFontFamily, dataDetectorTypes: $dataDetectorTypes, databaseEnabled: $databaseEnabled, decelerationRate: $decelerationRate, defaultFixedFontSize: $defaultFixedFontSize, defaultFontSize: $defaultFontSize, defaultTextEncodingName: $defaultTextEncodingName, defaultVideoPoster: $defaultVideoPoster, disableContextMenu: $disableContextMenu, disableDefaultErrorPage: $disableDefaultErrorPage, disableHorizontalScroll: $disableHorizontalScroll, disableInputAccessoryView: $disableInputAccessoryView, disableLongPressContextMenuOnLinks: $disableLongPressContextMenuOnLinks, disableVerticalScroll: $disableVerticalScroll, disabledActionModeMenuItems: $disabledActionModeMenuItems, disallowOverScroll: $disallowOverScroll, displayZoomControls: $displayZoomControls, domStorageEnabled: $domStorageEnabled, enableViewportScale: $enableViewportScale, enterpriseAuthenticationAppLinkPolicyEnabled: $enterpriseAuthenticationAppLinkPolicyEnabled, fantasyFontFamily: $fantasyFontFamily, fixedFontFamily: $fixedFontFamily, generalAutofillEnabled: $generalAutofillEnabled, geolocationEnabled: $geolocationEnabled, handleAcceleratorKeyPressed: $handleAcceleratorKeyPressed, hardwareAcceleration: $hardwareAcceleration, hiddenPdfToolbarItems: $hiddenPdfToolbarItems, horizontalScrollBarEnabled: $horizontalScrollBarEnabled, horizontalScrollbarThumbColor: $horizontalScrollbarThumbColor, horizontalScrollbarTrackColor: $horizontalScrollbarTrackColor, iframeAllow: $iframeAllow, iframeAllowFullscreen: $iframeAllowFullscreen, iframeAriaHidden: $iframeAriaHidden, iframeCsp: $iframeCsp, iframeName: $iframeName, iframeReferrerPolicy: $iframeReferrerPolicy, iframeRole: $iframeRole, iframeSandbox: $iframeSandbox, ignoresViewportScaleLimits: $ignoresViewportScaleLimits, incognito: $incognito, initialScale: $initialScale, interceptOnlyAsyncAjaxRequests: $interceptOnlyAsyncAjaxRequests, isDirectionalLockEnabled: $isDirectionalLockEnabled, isElementFullscreenEnabled: $isElementFullscreenEnabled, isFindInteractionEnabled: $isFindInteractionEnabled, isFraudulentWebsiteWarningEnabled: $isFraudulentWebsiteWarningEnabled, isInspectable: $isInspectable, isPagingEnabled: $isPagingEnabled, isSiteSpecificQuirksModeEnabled: $isSiteSpecificQuirksModeEnabled, isTextInteractionEnabled: $isTextInteractionEnabled, isUserInteractionEnabled: $isUserInteractionEnabled, javaScriptBridgeEnabled: $javaScriptBridgeEnabled, javaScriptBridgeForMainFrameOnly: $javaScriptBridgeForMainFrameOnly, javaScriptBridgeOriginAllowList: $javaScriptBridgeOriginAllowList, javaScriptCanOpenWindowsAutomatically: $javaScriptCanOpenWindowsAutomatically, javaScriptEnabled: $javaScriptEnabled, javaScriptHandlersForMainFrameOnly: $javaScriptHandlersForMainFrameOnly, javaScriptHandlersOriginAllowList: $javaScriptHandlersOriginAllowList, layoutAlgorithm: $layoutAlgorithm, limitsNavigationsToAppBoundDomains: $limitsNavigationsToAppBoundDomains, loadWithOverviewMode: $loadWithOverviewMode, loadsImagesAutomatically: $loadsImagesAutomatically, maximumViewportInset: $maximumViewportInset, maximumZoomScale: $maximumZoomScale, mediaPlaybackRequiresUserGesture: $mediaPlaybackRequiresUserGesture, mediaType: $mediaType, minimumFontSize: $minimumFontSize, minimumLogicalFontSize: $minimumLogicalFontSize, minimumViewportInset: $minimumViewportInset, minimumZoomScale: $minimumZoomScale, mixedContentMode: $mixedContentMode, needInitialFocus: $needInitialFocus, networkAvailable: $networkAvailable, nonClientRegionSupportEnabled: $nonClientRegionSupportEnabled, offscreenPreRaster: $offscreenPreRaster, overScrollMode: $overScrollMode, pageZoom: $pageZoom, passwordAutosaveEnabled: $passwordAutosaveEnabled, pinchZoomEnabled: $pinchZoomEnabled, pluginScriptsForMainFrameOnly: $pluginScriptsForMainFrameOnly, pluginScriptsOriginAllowList: $pluginScriptsOriginAllowList, preferredContentMode: $preferredContentMode, regexToAllowSyncUrlLoading: $regexToAllowSyncUrlLoading, regexToCancelSubFramesLoading: $regexToCancelSubFramesLoading, rendererPriorityPolicy: $rendererPriorityPolicy, reputationCheckingRequired: $reputationCheckingRequired, requestedWithHeaderOriginAllowList: $requestedWithHeaderOriginAllowList, resourceCustomSchemes: $resourceCustomSchemes, safeBrowsingEnabled: $safeBrowsingEnabled, sansSerifFontFamily: $sansSerifFontFamily, scrollBarDefaultDelayBeforeFade: $scrollBarDefaultDelayBeforeFade, scrollBarFadeDuration: $scrollBarFadeDuration, scrollBarStyle: $scrollBarStyle, scrollMultiplier: $scrollMultiplier, scrollbarFadingEnabled: $scrollbarFadingEnabled, scrollsToTop: $scrollsToTop, selectionGranularity: $selectionGranularity, serifFontFamily: $serifFontFamily, sharedCookiesEnabled: $sharedCookiesEnabled, shouldPrintBackgrounds: $shouldPrintBackgrounds, standardFontFamily: $standardFontFamily, statusBarEnabled: $statusBarEnabled, supportMultipleWindows: $supportMultipleWindows, supportZoom: $supportZoom, suppressesIncrementalRendering: $suppressesIncrementalRendering, textZoom: $textZoom, thirdPartyCookiesEnabled: $thirdPartyCookiesEnabled, transparentBackground: $transparentBackground, underPageBackgroundColor: $underPageBackgroundColor, upgradeKnownHostsToHTTPS: $upgradeKnownHostsToHTTPS, useHybridComposition: $useHybridComposition, useOnAjaxProgress: $useOnAjaxProgress, useOnAjaxReadyStateChange: $useOnAjaxReadyStateChange, useOnDownloadStart: $useOnDownloadStart, useOnLoadResource: $useOnLoadResource, useOnNavigationResponse: $useOnNavigationResponse, useOnRenderProcessGone: $useOnRenderProcessGone, useShouldInterceptAjaxRequest: $useShouldInterceptAjaxRequest, useShouldInterceptFetchRequest: $useShouldInterceptFetchRequest, useShouldInterceptRequest: $useShouldInterceptRequest, useShouldOverrideUrlLoading: $useShouldOverrideUrlLoading, useWideViewPort: $useWideViewPort, userAgent: $userAgent, verticalScrollBarEnabled: $verticalScrollBarEnabled, verticalScrollbarPosition: $verticalScrollbarPosition, verticalScrollbarThumbColor: $verticalScrollbarThumbColor, verticalScrollbarTrackColor: $verticalScrollbarTrackColor, webViewAssetLoader: $webViewAssetLoader}'; } } diff --git a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_webview.dart b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_webview.dart index f111da0f1..9f4de1de9 100644 --- a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_webview.dart +++ b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_webview.dart @@ -13,6 +13,7 @@ import 'platform_inappwebview_controller.dart'; import '../print_job/main.dart'; import 'platform_inappwebview_widget.dart'; import 'platform_headless_in_app_webview.dart'; +import '../platform_webview_feature.dart'; ///{@template flutter_inappwebview_platform_interface.PlatformWebViewCreationParams} ///Class that represents a WebView. Used by [PlatformInAppWebViewWidget], @@ -428,14 +429,17 @@ class PlatformWebViewCreationParams { ///{@template flutter_inappwebview_platform_interface.PlatformWebViewCreationParams.shouldInterceptAjaxRequest} ///Event fired when an `XMLHttpRequest` is sent to a server. ///It gives the host application a chance to take control over the request before sending it. + ///This event is implemented using JavaScript under the hood. /// ///Due to the async nature of this event implementation, it will intercept only async `XMLHttpRequest`s ([AjaxRequest.isAsync] with `true`). ///To be able to intercept sync `XMLHttpRequest`s, use [InAppWebViewSettings.interceptOnlyAsyncAjaxRequests] to `false`. + ///If necessary, you should implement your own logic using for example an [UserScript] overriding the + ///[XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) JavaScript object. /// ///[ajaxRequest] represents the `XMLHttpRequest`. /// ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptAjaxRequest] setting to `true`. - ///Also, unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that + ///Also, on Android that doesn't support the [WebViewFeature.DOCUMENT_START_SCRIPT], unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that ///can inject javascript code right after the document element is created but before any other content is loaded, in Android the javascript code ///used to intercept ajax requests is loaded as soon as possible so it won't be instantaneous as iOS but just after some milliseconds (< ~100ms). ///Inside the `window.addEventListener("flutterInAppWebViewPlatformReady")` event, the ajax requests will be intercept for sure. @@ -451,12 +455,18 @@ class PlatformWebViewCreationParams { ///{@template flutter_inappwebview_platform_interface.PlatformWebViewCreationParams.onAjaxReadyStateChange} ///Event fired whenever the `readyState` attribute of an `XMLHttpRequest` changes. ///It gives the host application a chance to abort the request. + ///This event is implemented using JavaScript under the hood. + /// + ///Due to the async nature of this event implementation, + ///using it could cause some issues, so, be careful when using it. + ///In this case, you should implement your own logic using for example an [UserScript] overriding the + ///[XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) JavaScript object. /// ///[ajaxRequest] represents the [XMLHttpRequest]. /// - ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptAjaxRequest] setting to `true`. - ///Also, unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that - ///can inject javascript code right after the document element is created but before any other content is loaded, in Android the javascript code + ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptAjaxRequest] and [InAppWebViewSettings.useOnAjaxReadyStateChange] settings to `true`. + ///Also, on Android that doesn't support the [WebViewFeature.DOCUMENT_START_SCRIPT], unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that + ///can inject javascript code right after the document element is created but before any other content is loaded, the javascript code ///used to intercept ajax requests is loaded as soon as possible so it won't be instantaneous as iOS but just after some milliseconds (< ~100ms). ///Inside the `window.addEventListener("flutterInAppWebViewPlatformReady")` event, the ajax requests will be intercept for sure. /// @@ -471,11 +481,12 @@ class PlatformWebViewCreationParams { ///{@template flutter_inappwebview_platform_interface.PlatformWebViewCreationParams.onAjaxProgress} ///Event fired as an `XMLHttpRequest` progress. ///It gives the host application a chance to abort the request. + ///This event is implemented using JavaScript under the hood. /// ///[ajaxRequest] represents the [XMLHttpRequest]. /// - ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptAjaxRequest] setting to `true`. - ///Also, unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that + ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptAjaxRequest] and [InAppWebViewSettings.useOnAjaxProgress] settings to `true`. + ///Also, on Android that doesn't support the [WebViewFeature.DOCUMENT_START_SCRIPT], unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that ///can inject javascript code right after the document element is created but before any other content is loaded, in Android the javascript code ///used to intercept ajax requests is loaded as soon as possible so it won't be instantaneous as iOS but just after some milliseconds (< ~100ms). ///Inside the `window.addEventListener("flutterInAppWebViewPlatformReady")` event, the ajax requests will be intercept for sure. @@ -491,11 +502,12 @@ class PlatformWebViewCreationParams { ///{@template flutter_inappwebview_platform_interface.PlatformWebViewCreationParams.shouldInterceptFetchRequest} ///Event fired when a request is sent to a server through [Fetch API](https://developer.mozilla.org/it/docs/Web/API/Fetch_API). ///It gives the host application a chance to take control over the request before sending it. + ///This event is implemented using JavaScript under the hood. /// ///[fetchRequest] represents a resource request. /// ///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewSettings.useShouldInterceptFetchRequest] setting to `true`. - ///Also, unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that + ///Also, on Android that doesn't support the [WebViewFeature.DOCUMENT_START_SCRIPT], unlike iOS that has [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) that ///can inject javascript code right after the document element is created but before any other content is loaded, in Android the javascript code ///used to intercept fetch requests is loaded as soon as possible so it won't be instantaneous as iOS but just after some milliseconds (< ~100ms). ///Inside the `window.addEventListener("flutterInAppWebViewPlatformReady")` event, the fetch requests will be intercept for sure. diff --git a/flutter_inappwebview_windows/example/pubspec.lock b/flutter_inappwebview_windows/example/pubspec.lock index 750a69803..7366198f1 100644 --- a/flutter_inappwebview_windows/example/pubspec.lock +++ b/flutter_inappwebview_windows/example/pubspec.lock @@ -86,18 +86,17 @@ packages: flutter_inappwebview_platform_interface: dependency: transitive description: - name: flutter_inappwebview_platform_interface - sha256: "2c99bf767900ba029d825bc6f494d30169ee83cdaa038d86e85fe70571d0a655" - url: "https://pub.dev" - source: hosted - version: "1.4.0-beta.2" + path: "../../flutter_inappwebview_platform_interface" + relative: true + source: path + version: "1.4.0-beta.3" flutter_inappwebview_windows: dependency: "direct main" description: path: ".." relative: true source: path - version: "0.7.0-beta.2" + version: "0.7.0-beta.3" flutter_lints: dependency: "direct dev" description: diff --git a/flutter_inappwebview_windows/lib/src/in_app_webview/headless_in_app_webview.dart b/flutter_inappwebview_windows/lib/src/in_app_webview/headless_in_app_webview.dart index c20686d0f..5c3034b76 100644 --- a/flutter_inappwebview_windows/lib/src/in_app_webview/headless_in_app_webview.dart +++ b/flutter_inappwebview_windows/lib/src/in_app_webview/headless_in_app_webview.dart @@ -376,9 +376,19 @@ class WindowsHeadlessInAppWebView extends PlatformHeadlessInAppWebView settings.useOnDownloadStart == null) { settings.useOnDownloadStart = true; } - if (params.shouldInterceptAjaxRequest != null && - settings.useShouldInterceptAjaxRequest == null) { - settings.useShouldInterceptAjaxRequest = true; + if ((params.shouldInterceptAjaxRequest != null || + params.onAjaxProgress != null || + params.onAjaxReadyStateChange != null)) { + if (settings.useShouldInterceptAjaxRequest == null) { + settings.useShouldInterceptAjaxRequest = true; + } + if (params.onAjaxReadyStateChange != null && + settings.useOnAjaxReadyStateChange == null) { + settings.useOnAjaxReadyStateChange = true; + } + if (params.onAjaxProgress != null && settings.useOnAjaxProgress == null) { + settings.useOnAjaxProgress = true; + } } if (params.shouldInterceptFetchRequest != null && settings.useShouldInterceptFetchRequest == null) { diff --git a/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview.dart b/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview.dart index 245286826..d916e4a86 100644 --- a/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview.dart +++ b/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview.dart @@ -369,10 +369,18 @@ class WindowsInAppWebViewWidget extends PlatformInAppWebViewWidget { settings.useOnDownloadStart = true; } if ((params.shouldInterceptAjaxRequest != null || - params.onAjaxProgress != null || - params.onAjaxReadyStateChange != null) && - settings.useShouldInterceptAjaxRequest == null) { - settings.useShouldInterceptAjaxRequest = true; + params.onAjaxProgress != null || + params.onAjaxReadyStateChange != null)) { + if (settings.useShouldInterceptAjaxRequest == null) { + settings.useShouldInterceptAjaxRequest = true; + } + if (params.onAjaxReadyStateChange != null && + settings.useOnAjaxReadyStateChange == null) { + settings.useOnAjaxReadyStateChange = true; + } + if (params.onAjaxProgress != null && settings.useOnAjaxProgress == null) { + settings.useOnAjaxProgress = true; + } } if (params.shouldInterceptFetchRequest != null && settings.useShouldInterceptFetchRequest == null) { diff --git a/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart index 3d9832aab..03e5dc040 100644 --- a/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart @@ -1536,13 +1536,13 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController if (webviewParams != null && webviewParams!.onAjaxReadyStateChange != null) - return (await webviewParams!.onAjaxReadyStateChange!( + return jsonEncode((await webviewParams!.onAjaxReadyStateChange!( _controllerFromPlatform, request)) - ?.toNativeValue(); + ?.toNativeValue()); else - return (await _inAppBrowserEventHandler! + return jsonEncode((await _inAppBrowserEventHandler! .onAjaxReadyStateChange(request)) - ?.toNativeValue(); + ?.toNativeValue()); } return null; case "onAjaxProgress": @@ -1555,13 +1555,13 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController if (webviewParams != null && webviewParams!.onAjaxProgress != null) - return (await webviewParams!.onAjaxProgress!( + return jsonEncode((await webviewParams!.onAjaxProgress!( _controllerFromPlatform, request)) - ?.toNativeValue(); + ?.toNativeValue()); else - return (await _inAppBrowserEventHandler! + return jsonEncode((await _inAppBrowserEventHandler! .onAjaxProgress(request)) - ?.toNativeValue(); + ?.toNativeValue()); } return null; case "shouldInterceptFetchRequest":