[
https://issues.apache.org/jira/browse/CB-5756?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13869865#comment-13869865
]
Ian Clelland commented on CB-5756:
----------------------------------
I've *mostly* confirmed this behaviour on a Nexus 7 running Android 4.4.2 (The
source for loadUrl doesn't appear to have changed between 4.4_r1.1 and 4.4.2)
The apache page loads, and then the JS runs, and the page is left blank.
Oddly, the mobile spec tests for CSS/JS injection were almost all running fine.
The only failure that I was able to see was with the Script LIteral Injection
test, where the page was replaced with the contents "abc" -- the return value
of the JS. All of the other tests passed.
Using evaluateJavascript, everything appears to be working correctly.
> InAppBrowser example fails on Android 4.4
> -----------------------------------------
>
> Key: CB-5756
> URL: https://issues.apache.org/jira/browse/CB-5756
> Project: Apache Cordova
> Issue Type: Bug
> Components: Android, Plugin InAppBrowser
> Affects Versions: 3.3.0
> Environment: Android 4.4
> Reporter: Marcus Pridham
> Assignee: Ian Clelland
>
> 1. Create cordova project and add InAppBrowser plugin
> 2. Replace index.html contents with the Full Example for executeScript in
> the API docs at
> http://cordova.apache.org/docs/en/3.3.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser
> 3. Build run the application.
> 4. When the InAppBrowser loads the it displays the string
> http://cordova.apache.org/images/cordova_bot.png.
> The example is suppose to load the Apache site and replace the logo with the
> cordova bot. If you open the AndroidManifest.xml and change the
> targetSdkVersion from 19 to 18 it works as expected.
> The problems seems to be caused by a change in behaviour in 4.4 with using
> loadUrl("javascript:..."). See the loadUrl method in
> https://android.googlesource.com/platform/frameworks/webview/+/android-4.4_r1.1/chromium/java/com/android/webview/chromium/WebViewChromium.java.
> If the target sdk is kitkat the result of the JS Url replaces the content
> of the current page...
> The fix seems to be to use a new 4.4 method to the webview called
> evaluateJavaScript.
> http://developer.android.com/reference/android/webkit/WebView.html#evaluateJavascript(java.lang.String,%20android.webkit.ValueCallback<java.lang.String>)
> In InAppBrowser.java:
> Change this:
> {code}
> final String finalScriptToInject = scriptToInject;
> // This action will have the side-effect of blurring the currently
> focused element
> this.cordova.getActivity().runOnUiThread(new Runnable() {
> @Override
> public void run() {
> inAppWebView.loadUrl("javascript:" + finalScriptToInject);
> }
> });
> {code}
>
> To:
>
> {code}
> final String finalScriptToInject = scriptToInject;
>
> // This action will have the side-effect of blurring the
> currently focused element
> this.cordova.getActivity().runOnUiThread(new Runnable() {
> @Override
> public void run() {
> if
> (cordova.getActivity().getApplicationInfo().targetSdkVersion <
> Build.VERSION_CODES.KITKAT)
> {
> inAppWebView.loadUrl("javascript:" +
> finalScriptToInject);
> } else {
>
> inAppWebView.evaluateJavascript(finalScriptToInject, null);
> }
> }
> });
> {code}
>
>
> I haven't tried any other plugins but it might be neccessary to change other
> plugins to use evaluateJavascript instead of loadUrl("javascript:...").
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)