[TIMOB-4885] Android: evalJS for javascript functions in webview results in a crash
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-09-27T09:55:53.000+0000 |
Affected Version/s | Release 1.7.2 |
Fix Version/s | Sprint 2011-37, Release 1.8.0 |
Components | Android |
Labels | module_webview, qe-testadded |
Reporter | Anirudh Nagesh |
Assignee | Bill Dawson |
Created | 2011-08-03T14:51:11.000+0000 |
Updated | 2014-06-19T12:46:21.000+0000 |
Description
Evaluating a javascript function inside an html results in a crash. works fine on iOS
Step1: copy the below code to app.js
var win = Ti.UI.createWindow({ backgroundColor: '#cccccc' });
var webView = Ti.UI.createWebView({ width: 300, height: 200, top: 0, left: 0,backgroundColor: 'white',
url:'test.html'
});
win.add(webView);
webView.addEventListener('load', function(){
Ti.API.debug('webivew loaded');
// var title = webView.evalJS("document.title"); // this works fine!
// Ti.API.debug(title);
var foo_return = webView.evalJS("foo('Hi')");
Ti.API.debug(foo_return);
});
win.open();
Step2: Copy the below code to 'test.html' under the resources.
<!doctype html>
<html>
<head>
<title>Test Webview Page</title>
</head>
<body><h1>My hovercraft is full of eels.</h1>
<script type="text/javascript">
function foo(msg) { alert(msg); };
</script>
</body>
</html>
Step3: Crash log from ddms is attached.
Attachments
File | Date | Size |
---|---|---|
crash_log.txt | 2011-08-03T14:51:11.000+0000 | 12769 |
timob4885.zip | 2011-09-13T15:58:09.000+0000 | 7563598 |
Still working on it, but a quick note: I can only re-create this if the function being called has an
alert()
,prompt()
orconfirm()
call in it. If anybody can re-create with a JS function (in the html file) that does not use one of these functions that pops up a dialog, please post another example failcase.See attached test app timob4885.zip for easy testing of evalJS that causes a UI to appear from within webview (alert()) and evalJS that does not cause a UI to appear from within webview. The original problem was with using evalJS to show an alert. That should be fixed now. This test app incorporates the original fail case.
Merge.
Fix verified in SDK 1.8.0.1.v20111122105459 with a Nexus One running 2.2.2.
Anvil test case added. PR link: https://github.com/appcelerator/titanium_mobile/pull/5020