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..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 @@ -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; @@ -223,13 +204,33 @@ public void onPageFinished(WebView view, String url) { view.clearFocus(); view.requestFocus(); - String js = InAppWebView.platformReadyJS.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]+", ""); + } + 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); } + + 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<>(); if (inAppBrowserActivity != null)