Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16082] Android: WebView.evalJS always returns null on Android 4.2.2 device

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionInvalid
Resolution Date2017-08-18T15:51:21.000+0000
Affected Version/sRelease 3.2.0
Fix Version/sRelease 6.2.0
ComponentsAndroid
LabelsAndroid, WebView, evalJs, exalture, kitkat
ReporterSHOCKOE TEAM
AssigneeJoshua Quick
Created2013-12-17T22:24:01.000+0000
Updated2017-08-18T15:51:21.000+0000

Description

WebView.evalJS appears to always return null on devices running Android Kit-Kat, regardless of the provided script. Example app:

var win = Titanium.UI.createWindow({  
    title:'EvalJS kit-kat test',
    backgroundColor:'#fff'
});
var webView = Ti.UI.createWebView({
    url : 'http://www.google.com'
});
webView.addEventListener('load', function(evt){
    //Expected behavior is for an alert saying 'google' to be shown
    //On Android Kit-Kat, an empty alert is shown instead.
    alert(evt.source.evalJS('document.title'));
});

win.add(webView);
win.open();
Reproduces on 3.1.3.GA and 3.2.0.v20131210191510

Comments

  1. Ritu Agrawal 2013-12-19

    I have not been able to reproduce this problem on Nexus 7 phone running Android 4.4 with 3.1.3 SDK. I am wondering if you encounter this issue only on Android 4.4 device or can you reproduce this issue on other devices as well? Can you reproduce this issue on the simulator too? I would appreciate if you can also try an alternate website in the above example.
  2. Quang Pham 2013-12-24

    same here, evalJS always return null for 3.2 SDK, Android 4.0
  3. Ritu Agrawal 2013-12-26

    Moving this ticket to engineering as I can reproduce it on Samsung Galaxy Nexus (4.2.2) device.
  4. Ingo Muschenetz 2013-12-27

    Hi All--Since this was reproduced on 4.2.2, should we rewrite the ticket to not be KitKat specific?
  5. Adam Paxton 2014-01-15

    Same issue on Galaxy Nexus running 4.3. Build with Ti SDK 3.2.0.GA
  6. Muhammad Mahmoud 2014-03-10

    Reproduced on Samsung Galaxy S4 running 4.3 and Nexus 4 running 4.4 with Ti SDK 3.1.2.GA
  7. Michiel Dondorp 2014-06-13

    I think the problem originates in this: http://developer.android.com/guide/webapps/migrating.html ??Android 4.4 (API level 19) introduces a new version of WebView that is based on Chromium. This change upgrades WebView performance and standards support for HTML5, CSS3, and JavaScript to match the latest web browsers. Any apps using WebView will inherit these upgrades when running on Android 4.4 and higher.??
  8. Gianluca Arcidiacono 2014-08-04

    Same problem with Nexus 5 (Android 4.4.4, SDK 3.3.0). Any workaround?
  9. Michiel Dondorp 2014-08-04

    I no longer have this when I just do:
       var command;
       if(android){
           command =  "return " + command;
       }
       evalJs(command);
       
    Just found the code again which handles this: [ti.ui.widget.webview.TiWebViewBinding.java](https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiWebViewBinding.java) Line 147: getJsValue
  10. carlo 2015-03-26

    confirmed return is needed on Android (tested on Nexus 5, Android 5.0.1) but cause return null on iOS wtf
  11. SHOCKOE TEAM 2015-05-27

    Any updates on this ticket?
  12. Frankie Merzadyan 2017-01-30

    Could not reproduce. Tried with 4.2.X-4.4.X, 6 and 7.X emulators. Alert dialogue returned expected non-null values.
  13. Gary Mathews 2017-08-18

    Since this issue is not reproducible I'm going to close this as invalid.

JSON Source