Details
-
Type:
Bug
-
Status: Closed
-
Priority:
High
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: Release 3.4.0
-
Component/s: Android
-
Labels:
-
Environment:
OSX 10.9.2
Titanium SDK 3.3.0.GA
Genymotion, Android 4.1.1 on Custom Tablet 10inch
-
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
- is duplicated by
-
TIMOB-15896 WebView's evalJS method times out on Android API >= 17
-
- Closed
-
- relates to
-
TIMOB-10837 Android: webView throws on evalJS when string starts with `var`
-
- Reopened
-
-
AC-1157 WebView.evalJS times out / throws 'Unexpected token' error
- Closed