cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF subversion and git services (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-5756) InAppBrowser example fails on Android 4.4
Date Mon, 13 Jan 2014 19:35:52 GMT

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

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

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

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)

Mime
View raw message