From d360a53a5aea68c7ce9d2725c3e0da3214a61a71 Mon Sep 17 00:00:00 2001 From: HobsonCheng <2114169965@qq.com> Date: Wed, 25 Mar 2020 11:51:33 +0800 Subject: [PATCH 1/2] Update InAppWebViewClient.java --- .../InAppWebView/InAppWebViewClient.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java index 84ad883bb..33baafc48 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java @@ -168,26 +168,7 @@ public void notImplemented() { public void onPageStarted(WebView view, String url, Bitmap favicon) { InAppWebView webView = (InAppWebView) view; - - String js = InAppWebView.consoleLogJS.replaceAll("[\r\n]+", ""); - js += JavaScriptBridgeInterface.flutterInAppBroserJSClass.replaceAll("[\r\n]+", ""); - if (webView.options.useShouldInterceptAjaxRequest) { - js += InAppWebView.interceptAjaxRequestsJS.replaceAll("[\r\n]+", ""); - } - if (webView.options.useShouldInterceptFetchRequest) { - js += InAppWebView.interceptFetchRequestsJS.replaceAll("[\r\n]+", ""); - } - if (webView.options.useOnLoadResource) { - js += InAppWebView.resourceObserverJS.replaceAll("[\r\n]+", ""); - } - js += InAppWebView.printJS.replaceAll("[\r\n]+", ""); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - webView.evaluateJavascript(js, (ValueCallback) null); - } else { - webView.loadUrl("javascript:" + js); - } - + super.onPageStarted(view, url, favicon); webView.isLoading = true; @@ -230,6 +211,26 @@ public void onPageFinished(WebView view, String url) { } else { webView.loadUrl("javascript:" + js); } + + js = InAppWebView.consoleLogJS.replaceAll("[\r\n]+", ""); + js += JavaScriptBridgeInterface.flutterInAppBroserJSClass.replaceAll("[\r\n]+", ""); + if (webView.options.useShouldInterceptAjaxRequest) { + js += InAppWebView.interceptAjaxRequestsJS.replaceAll("[\r\n]+", ""); + } + if (webView.options.useShouldInterceptFetchRequest) { + js += InAppWebView.interceptFetchRequestsJS.replaceAll("[\r\n]+", ""); + } + if (webView.options.useOnLoadResource) { + js += InAppWebView.resourceObserverJS.replaceAll("[\r\n]+", ""); + } + js += InAppWebView.printJS.replaceAll("[\r\n]+", ""); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + webView.evaluateJavascript(js, (ValueCallback) null); + } else { + webView.loadUrl("javascript:" + js); + } + Map obj = new HashMap<>(); if (inAppBrowserActivity != null) From f052cb7a48d2a3a84a4f7274513d306cce77eed1 Mon Sep 17 00:00:00 2001 From: HobsonCheng <2114169965@qq.com> Date: Wed, 25 Mar 2020 14:24:50 +0800 Subject: [PATCH 2/2] Update InAppWebViewClient.java --- .../InAppWebView/InAppWebViewClient.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java index 33baafc48..f0e485945 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java @@ -204,15 +204,7 @@ public void onPageFinished(WebView view, String url) { view.clearFocus(); view.requestFocus(); - String js = InAppWebView.platformReadyJS.replaceAll("[\r\n]+", ""); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - webView.evaluateJavascript(js, (ValueCallback) null); - } else { - webView.loadUrl("javascript:" + js); - } - - js = InAppWebView.consoleLogJS.replaceAll("[\r\n]+", ""); + String js = InAppWebView.consoleLogJS.replaceAll("[\r\n]+", ""); js += JavaScriptBridgeInterface.flutterInAppBroserJSClass.replaceAll("[\r\n]+", ""); if (webView.options.useShouldInterceptAjaxRequest) { js += InAppWebView.interceptAjaxRequestsJS.replaceAll("[\r\n]+", ""); @@ -230,6 +222,14 @@ public void onPageFinished(WebView view, String url) { } else { webView.loadUrl("javascript:" + js); } + + js = InAppWebView.platformReadyJS.replaceAll("[\r\n]+", ""); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + webView.evaluateJavascript(js, (ValueCallback) null); + } else { + webView.loadUrl("javascript:" + js); + } Map obj = new HashMap<>();