Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-17613

Unable to execute javascript code using evalJS on Android with SDK 3.3.0.GA

    Details

    • Story Points:
      3
    • Sprint:
      2014 Sprint 18 SDK

      Description

      After upgrading to the latest Titanium SDK (3.3.0.GA), we are not able to invoke Javascript functions using evalJS on Android. We are developing the application for about 2-3 years now, and we can confirm that the code worked prior upgrading to 3.3.0. Moreover, the iOS version of our app does not have this problem even after upgrading the SDK.
      Our application is quite complex, and one of the core features is the integration with web applications provided by our platform. In order this integration to work, we heavily rely on invoking Javascript functions in the webView context in order to retrieve some data, or identify what steps should be taken.

      Since we are not allowed to share any productive code, I have prepared a code snippet that presents the issue:

      app.js

      (function() {
      	
      	var win = Ti.UI.createWindow();
      	var webView = Ti.UI.createWebView({
      		url : 'test.html'
      	});
      	
      	var evalJSFunc = "" + 
      	"(function() {" + 
      		"var result = '{';" +
      		"var d = document.getElementById('myDiv');" +
      		"if (d && d.children) {" +
      			"var childrenLength = d.children.length;" +
      			"var delimiter = '';" +
      			"for (var i = 0; i < childrenLength; i++) {" +
      				"var child = d.children[i];" +
      				"result = result + delimiter + child.name + ':' + child.value;" +
      				"delimiter = ',';" +
      			"}" +
      		"}" +
      		"result = result + '}';" +
      		"return result + '}';" +
      	"})();";
      	
      	webView.addEventListener('load', function() {
      		var result = webView.evalJS(evalJSFunc);
      		alert(result);
      	});
      	
      	win.add(webView);
      	win.open();
      	
      })();
      

      And this is the sample HTML file (note that the Javascript function is the same as the one we try to invoke using evalJS in app.js; it is left just for reference without invoking it):

      test.html

      <html>
      <head>
      <script type="text/javascript">
       
      	function a() {
      		var result = '{';
      		var d = document.getElementById('myDiv');
      		if (d && d.children) {
      			var childrenLength = d.children.length;
      			var delimiter = '';
      			for (var i = 0; i < childrenLength; i++) {
      				var child = d.children[i];
      				result = result + delimiter + child.name + ':' + child.value;
      				delimiter = ',';
      			}
      		}
      		result = result + '}';
      		return result + '}';
      	}
      </script>
      </head>
      <body>
      	<div id="myDiv">
      		<input type="hidden" name="f1" value="1" />
      		<input type="hidden" name="f2" value="2" />
      	</div>
      </body>
      </html>
      

      When executing the above we get the following error:

      [INFO] :   I/TiWebChromeClient.console: (main) [12259,12259] Uncaught SyntaxError: Unexpected token var (1:file:///android_asset/Resources/test.html)
      

      After some time (if we wait enough) we get the attached screenshot in Genymotion simulator (no clue where this comes from).

      Until now, the workaround for us was to rollback to the previous Titanium SDK (3.2.3.GA). Now, given the fact that Apple will also release the new iOS8 soon, we expect that new Titanium SDK would be rolled out as well, one that we must upgrade to, since iOS8 is a must for us. However, this Android issue is also a blocker, putting us in deadlock situation.
      I have noticed that there are few other JIRA issues similar to ours.

      https://jira.appcelerator.org/browse/TIMOB-15896
      https://jira.appcelerator.org/browse/TC-4427

      However, I'm not sure if the cause is really the same (one of the issues says that this happens on 3.2.0 with API17 but we are experiencing it on 3.3.0 with API16). In either case, we would highly appreciate if this issue is treated with higher priority and resolved as quick as possible.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                hpham Hieu Pham
                Reporter:
                ivo.tasevski Ivo
                Tester:
                Lokesh Choudhary
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-19149
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Source Code