From bfe5971d84d38c62e2c924c73a9b24830b81b5e9 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Wed, 6 Dec 2023 18:05:18 +0100 Subject: [PATCH] fixed InterceptAjaxRequestJS Failed to set responseType property also on iOS and macOS, fixed shouldInterceptAjaxRequest javascript code when overriding XMLHttpRequest.open method parameters --- .../plugin_scripts_js/InterceptAjaxRequestJS.java | 7 +++++-- .../Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift | 9 ++++++--- .../Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift | 9 ++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) 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 2ad476f1..4a892dc7 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 @@ -233,10 +233,13 @@ public class InterceptAjaxRequestJS { " }" + " setRequestHeader.call(self, header, value);" + " };" + - " if ((self._flutter_inappwebview_method != result.method && result.method != null) || (self._flutter_inappwebview_url != result.url && result.url != null)) {" + + " if ((self._flutter_inappwebview_method != result.method && result.method != null) ||" + + " (self._flutter_inappwebview_url != result.url && result.url != null) ||" + + " (self._flutter_inappwebview_isAsync != result.isAsync && result.isAsync != null) ||" + + " (self._flutter_inappwebview_user != result.user && result.user != null) ||" + + " (self._flutter_inappwebview_password != result.password && result.password != null)) {" + " self.abort();" + " self.open(result.method, result.url, result.isAsync, result.user, result.password);" + - " return;" + " }" + " }" + " send.call(self, data);" + diff --git a/flutter_inappwebview_ios/ios/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift b/flutter_inappwebview_ios/ios/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift index b5d3a54f..be260499 100644 --- a/flutter_inappwebview_ios/ios/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift +++ b/flutter_inappwebview_ios/ios/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift @@ -219,7 +219,7 @@ let INTERCEPT_AJAX_REQUEST_JS_SOURCE = """ data = new Uint8Array(result.data); } self.withCredentials = result.withCredentials; - if (result.responseType != null) { + if (result.responseType != null && self.isAsync) { self.responseType = result.responseType; }; if (result.headers != null) { @@ -234,10 +234,13 @@ let INTERCEPT_AJAX_REQUEST_JS_SOURCE = """ setRequestHeader.call(self, header, value); }; } - if ((self._flutter_inappwebview_method != result.method && result.method != null) || (self._flutter_inappwebview_url != result.url && result.url != null)) { + if ((self._flutter_inappwebview_method != result.method && result.method != null) || + (self._flutter_inappwebview_url != result.url && result.url != null) || + (self._flutter_inappwebview_isAsync != result.isAsync && result.isAsync != null) || + (self._flutter_inappwebview_user != result.user && result.user != null) || + (self._flutter_inappwebview_password != result.password && result.password != null)) { self.abort(); self.open(result.method, result.url, result.isAsync, result.user, result.password); - return; } } send.call(self, data); diff --git a/flutter_inappwebview_macos/macos/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift b/flutter_inappwebview_macos/macos/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift index b5d3a54f..be260499 100644 --- a/flutter_inappwebview_macos/macos/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift +++ b/flutter_inappwebview_macos/macos/Classes/PluginScriptsJS/InterceptAjaxRequestJS.swift @@ -219,7 +219,7 @@ let INTERCEPT_AJAX_REQUEST_JS_SOURCE = """ data = new Uint8Array(result.data); } self.withCredentials = result.withCredentials; - if (result.responseType != null) { + if (result.responseType != null && self.isAsync) { self.responseType = result.responseType; }; if (result.headers != null) { @@ -234,10 +234,13 @@ let INTERCEPT_AJAX_REQUEST_JS_SOURCE = """ setRequestHeader.call(self, header, value); }; } - if ((self._flutter_inappwebview_method != result.method && result.method != null) || (self._flutter_inappwebview_url != result.url && result.url != null)) { + if ((self._flutter_inappwebview_method != result.method && result.method != null) || + (self._flutter_inappwebview_url != result.url && result.url != null) || + (self._flutter_inappwebview_isAsync != result.isAsync && result.isAsync != null) || + (self._flutter_inappwebview_user != result.user && result.user != null) || + (self._flutter_inappwebview_password != result.password && result.password != null)) { self.abort(); self.open(result.method, result.url, result.isAsync, result.user, result.password); - return; } } send.call(self, data);