Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4885] Android: evalJS for javascript functions in webview results in a crash

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2011-09-27T09:55:53.000+0000
Affected Version/sRelease 1.7.2
Fix Version/sSprint 2011-37, Release 1.8.0
ComponentsAndroid
Labelsmodule_webview, qe-testadded
ReporterAnirudh Nagesh
AssigneeBill Dawson
Created2011-08-03T14:51:11.000+0000
Updated2014-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

FileDateSize
crash_log.txt2011-08-03T14:51:11.000+000012769
timob4885.zip2011-09-13T15:58:09.000+00007563598

Comments

  1. Bill Dawson 2011-08-22

    Still working on it, but a quick note: I can only re-create this if the function being called has an alert(), prompt() or confirm() 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.
  2. Bill Dawson 2011-09-13

    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.
  3. Don Thorp 2011-09-27

    Merge.
  4. Alan Vaghti 2011-11-22

    Fix verified in SDK 1.8.0.1.v20111122105459 with a Nexus One running 2.2.2.
  5. jithinpv 2013-11-25

    Anvil test case added. PR link: https://github.com/appcelerator/titanium_mobile/pull/5020

JSON Source