[TIMOB-3554] webview.evalJS() causes exception
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Trivial |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2011-07-07T11:12:08.000+0000 |
Affected Version/s | Release 1.6.2 |
Fix Version/s | Sprint 2011-25 |
Components | Android |
Labels | n/a |
Reporter | Paul Dowsett |
Assignee | Don Thorp |
Created | 2011-04-15T03:46:35.000+0000 |
Updated | 2012-02-15T10:14:17.000+0000 |
Description
A number of users in the Q&A have reported that evalJS applied to a webview causes an exception. The following usecase demonstrates the problem, which results in [this trace](http://pastebin.com/raw.php?i=HNGHQn6C)
var win = Ti.UI.createWindow({
backgroundColor : "blue",
exitOnClose:true
});
var myWeb = Ti.UI.createWebView({
url:'myweb.htm',
// url:'http://www.mydomain.net/myweb.htm',
url:'myweb.htm',
backgroundColor:'green'
});
myWeb.addEventListener('load',function(e){
var title = myWeb.evalJS("return document.title;");
Ti.API.info("The title of the webview is " + title);
});
win.add(myWeb);
win.open();
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>This is Titanium</title>
</head>
<body>
<div id="page-content">
<h1>Testing Titanium</h1>
<div id="inner-content">
<p>
This is a Titanium test.
</p>
</div>
</div>
</body>
</html>
Moving contents of ticket #3510, by user KT, here:
Here's a test that will crash on Android 2.2 / Ti 1.7.X with SIGSEGV:
This code gives a crash dump similar to http://pastie.org/1754641">http://pastie.org/1754641
Just as some further background, and to help try to pinpoint it regression-wise, users seem to be having similar issues for at least a year:
This is, strangely, in direct contravention to the https://github.com/appcelerator/titanium_mobile/commit/597a4878af606e255811964cc5cbc9b93df5dfb2"> drillbit test
If that works, then what is drillbit doing differently so that it works whereas the app.js above crashes immediately?
This crash doesn't seem to happen on 3.0. But the necessary Ti Javascript seems to never get injected, as is the case with 1.6 (i.e., no crash, but no Ti injection). The injection problem is described separately in #3539
The problem was with the code that the user was passing to evalJS(), ie:
The test code above works as expected, and returns the following output:
This is the code that proves that this issue is either invalid or fixed, as it works as expected:
Note this ticket is duplicated in TIMOB-3539
Closing as invalid due to comments from Paul.
When I try to run the example provided above by Paul, it crashes and the output is as follows: {noformat} D/TiWebViewBinding( 319): (main) [2408,2971] getJSValue:javascript:_TiReturn.setValue((function(){try{return document.title+"";}catch(ti_eval_err){return '';}})()); W/dalvikvm( 319): JNI WARNING: jarray 0x40610110 points to non-array object (Ljava/lang/String;) I/dalvikvm( 319): "WebViewCoreThread" prio=5 tid=14 NATIVE I/dalvikvm( 319): | group="main" sCount=0 dsCount=0 obj=0x405ac350 self=0x219b10 I/dalvikvm( 319): | sysTid=377 nice=0 sched=0/0 cgrp=default handle=2202696 I/dalvikvm( 319): | schedstat=( 507256989 1098467084 111 ) I/dalvikvm( 319): at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method) I/dalvikvm( 319): at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method) I/dalvikvm( 319): at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:246) I/dalvikvm( 319): at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1570) I/dalvikvm( 319): at android.webkit.WebViewCore.access$1400(WebViewCore.java:53) I/dalvikvm( 319): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:956) I/dalvikvm( 319): at android.os.Handler.dispatchMessage(Handler.java:99) I/dalvikvm( 319): at android.os.Looper.loop(Looper.java:123) I/dalvikvm( 319): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629) I/dalvikvm( 319): at java.lang.Thread.run(Thread.java:1019) I/dalvikvm( 319): E/dalvikvm( 319): VM aborting I/DEBUG ( 31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** I/DEBUG ( 31): Build fingerprint: 'generic/google_sdk/generic:2.3.1/GSI11/93351:eng/test-keys' I/DEBUG ( 31): pid: 319, tid: 377 >>> com.nokiasiemens.reporting <<< I/DEBUG ( 31): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadd00d I/DEBUG ( 31): r0 fffffebc r1 deadd00d r2 00000026 r3 00000000 I/DEBUG ( 31): r4 81da45c8 r5 40610110 r6 81d859ec r7 0021a540 I/DEBUG ( 31): r8 44026b50 r9 43efbe20 10 43efbe08 fp 4168d82c I/DEBUG ( 31): ip 81da4728 sp 44026678 lr afd19375 pc 81d45a02 cpsr 20000030 {noformat} Please check this issue. Thank you.
I just tested Paul's sample against master and it worked as expected on iOS, Android, and Mobile Web. Note that there is a typo in the sample. The app.js file says "myweb.htm", but the filename is listed as "myapp.htm"--if you use this sample verbatim, you'll get nothing back from the evalJS methods. However, with the filename corrected, it works fine.