Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8732] Android: Custom JavaScript objects sent in events to a WebView throw errors

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDuplicate
Resolution Date2012-05-15T11:50:35.000+0000
Affected Version/sRelease 2.0.0, Release 1.8.2
Fix Version/sn/a
ComponentsAndroid
Labelsapi
ReporterDevang Gandhi
AssigneeJosh Roesslein
Created2012-04-13T17:47:43.000+0000
Updated2017-03-10T19:14:07.000+0000

Description

When JavaScript objects are accessed from webview, ljava.lang.object error is thrown. Javascript objects are defined in a js file, which is then passed to html page using fireevent. The values are retrieved correctly in iOS. snippet of JS file:
var win = Ti.UI.currentWindow;

var activity_obj = {
	screen_name: [],
	idea_title : []
};

activity_obj.screen_name[0] = 'bhushan';
activity_obj.screen_name[1] = 'bhaskar';
activity_obj.screen_name[2] = 'deore';

activity_obj.idea_title[0] = 'android';
activity_obj.idea_title[1] = 'iphone';
activity_obj.idea_title[2] = 'app';

var webView = Ti.UI.createWebView({
	url:'webview_logging.html',
	height:400

});
win.add(webView);

webView.addEventListener('load', function(e) {
		Ti.App.fireEvent('data', activity_obj);	
});

Snippet of html file:
<html>
	<head>
		<title>Webview Logging</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

		<script>
			function show_content(e) {
				//alert('in event');
				for (var prop in e) {
					if (e.hasOwnProperty(prop)) {
						var obj_01 = e[prop];
						Ti.API.info("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
						Ti.API.info(JSON.stringify(obj_01));
						
					}
				}
			}
			Ti.App.addEventListener('data', show_content);
		</script>
	</head>
	<body>
		<div id = 'add_content'>
			ド標準第5版の刊行を大いに
		</div>
		
	</body>
</html>
Also attached crash log, and other js files, as a complete project. Steps to reproduce: Below are attached app.js and other files. Create a new project in titanium.create source folder under resources, and place all files excluding app.js. replace app.js with attached app.js. Run the project, and see the console.

Attachments

FileDateSize
app.js2012-04-13T17:47:44.000+0000421
log.txt2012-04-13T17:47:43.000+000047676
webview_logging.html2012-04-13T17:47:43.000+0000602
webview_repaint.js2012-04-13T17:47:43.000+0000526
webview.js2012-04-13T17:47:43.000+00001005
xml2json.js2012-04-13T17:47:44.000+0000889

Comments

  1. Josh Roesslein 2012-05-15

    This looks to be a duplicate of TIMOB-8308. Ran test case on latest master (2.1) CI and works fine.
  2. Lee Morris 2017-03-10

    Closing ticket as duplicate.

JSON Source