You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2014/02/11 00:23:47 UTC

[jira] [Commented] (CB-5756) InAppBrowser example fails on Android 4.4

    [ https://issues.apache.org/jira/browse/CB-5756?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13897248#comment-13897248 ] 

ASF subversion and git services commented on CB-5756:
-----------------------------------------------------

Commit e807bc3dc0f684212e43610a18f61e837a685c38 in branch refs/heads/master from [~iclelland]
[ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-inappbrowser.git;h=e807bc3 ]

CB-5756: Android: Use WebView.evaluateJavascript for script injection on Android 4.4+


> 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)