{ "id": "62267", "key": "TIMOB-1635", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "11237", "name": "Release 1.6.0 M04", "archived": true, "released": true, "releaseDate": "2011-01-10" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2011-04-17T01:56:43.000+0000", "created": "2011-04-15T02:57:54.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "android", "defect", "release-1.6.0" ], "versions": [], "issuelinks": [], "assignee": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2011-04-17T01:56:43.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "{html}
1.BaseUI>Views>WebViews>Loggin and unicode
\n2.check console output
results:
\nE/Web Console( 627): Uncaught TypeError: Cannot read property 'API'\nof undefined at\nfile:///android_asset/Resources/examples/webview_logging.html:5
\nD/TiAPI ( 627): (kroll$31) [102,344500] webview loaded:\nfile:///android_asset/Resources/examples/webview_logging.html
Thomas, just curious, was the failcase from a device or the\nemulator? I'm getting weird mixed behavior. (You can assign to me\nafter answering)
Sorry for the omitted info Bill - this was device only (worked\non the simulator when I tested it) - nexus one running 2.2
Ok, cool, I have the exact same behavior pattern. Fails on my\nHTC Desire using 2.2, works in an emulator (I tried it with a 2.1\nemulator but will also try 2.2).
So this has been broken (on devices -- at least 2.2) basically\nforever. I tried even for Titanium 1.3:
\n\nI/TiAPI (19880): (kroll$1) [115,154] *** TITANIUM VERSION 1.3.0 ***\nI/ActivityManager( 97): Displayed activity com.billdawson.simplewebview/.SimplewebviewActivity: 548 ms (total 548 ms)\nI/TabGroupProxy(19880): (main) [82,236] handleOpen\nI/ActivityManager( 97): Starting activity: Intent { cmp=com.billdawson.simplewebview/ti.modules.titanium.ui.TiTabActivity (has extras) }\nW/TiTabActivity(19880): (main) [32,268] Notifying TiTabGroup, activity is created\nW/TiActivity(19880): (main) [114,382] Notifying TiUIWindow, activity is created\nI/ActivityManager( 97): Displayed activity com.billdawson.simplewebview/ti.modules.titanium.ui.TiTabActivity: 312 ms (total 312 ms)\nE/Web Console(19880): Uncaught ReferenceError: TiAPI is not defined at :1\nD/webkit-timers(19880): [JWebCoreJavaBridge::resume] >> do resume\nE/Web Console(19880): Uncaught TypeError: Cannot read property 'API' of undefined at file:///android_asset/Resources/simple.html:23
\n
\nThat D/webkit-timers(19880)
line is interesting. It\ndoes not occur in the emulator!
Still researching...
Here is the core Android code for\nWebView.addJavascriptInterface()
, which we use to put\nTiAPI
and TiApp
in the javascript\nscope:
\npublic void addJavascriptInterface(Object obj, String interfaceName) {\n WebViewCore.JSInterfaceData arg = new WebViewCore.JSInterfaceData();\n arg.mObject = obj;\n arg.mInterfaceName = interfaceName;\n mWebViewCore.sendMessage(EventHub.ADD_JS_INTERFACE, arg);\n }
\n
\nMessages in mWebViewCore
are handled on a separate\nthread. Maybe the loading of a page in the webview is actually fast\nenough to occur before our objects are added to the javascript\nscope.
In my tests on an HTC Desire running Android 2.2, this page\nloaded in a WebView and required the setTimeout
to run\nonce (with just 100 milliseconds) before Ti.API
was\navailable:
\n<!doctype html>\n<html>\n <body>\n <div id=\"log\"></div>\n </body>\n <script>\n var i = 1;\n function log(s) {\n document.getElementById('log').innerHTML += '<br/>' + s;\n }\n var interval = 100;\n function checkTi() {\n if (!window.hasOwnProperty(\"Ti\") ) {\n log(\"Still no Ti. Trying again (\" + i + \")\");\n i++;\n setTimeout(checkTi, interval);\n } else if (typeof window.Ti === 'undefined') {\n log('Got Ti, but it is undefined. Trying again (' + i + ')');\n i++;\n setTimeout(checkTi, interval);\n } else if (!window.Ti.hasOwnProperty('API')) {\n log(\"Ti but no Ti.API. Trying again (\" + i + \")\");\n i++;\n setTimeout(checkTi, interval);\n } else {\n log('got it on try ' + i);\n Ti.API.info('Welcome to my web page');\n }\n }\n window.onload = function() {\n checkTi();\n }\n </script>\n</html>
\n
(from [12d7bf6a90db72fa0aebe538c95128c8a0cdc625])\nInject our Ti JS and JSON near beginning of local (and ONLY local)\nhtml file contents or html set directly via the html property.\n[#2153 state:fixed-in-qa][#2514\nstate:fixed-in-qa][#1635 state:fixed-in-qa][#1036\nstate:fixed-in-qa] \nhttps://github.com/appcelerator/titanium_mobile/commit/12d7bf6a90db...
This works great on 2.2 devices, but on 1.6 the test fails\nwith:
\nI/ActivityManager( 76): Starting activity: Intent {\ncmp=com.appcelerator.pushtest/org.appcelerator.titanium.TiActivity\n(has extras) }
\nI/ActivityManager( 76): Displayed activity\ncom.appcelerator.pushtest/org.appcelerator.titanium.TiActivity: 175\nms (total 175 ms)
\nI/global ( 641): Default buffer size used in BufferedReader\nconstructor. It would be better to be explicit if an 8k-char buffer\nis required.
\nD/WebCore ( 641): Console: ReferenceError: Can't find variable: Ti\nline: 5 source:\nfile:///android_asset/Resources/examples/webview_logging.html
Maybe a fact of life on 1.6? back to Bill.
(from [3452f061796695f0ad14d49fe3b22689f2e27dce])\n[#1635 state:fixed-in-qa] Android webkit\nMimeTypeMap does not have a mime type for file extension html until\nAndroid version 2.2. So we need to add it to our own mime type map\nin order for html files to be recognized as text/html and therefore\nget our javascript code injected. \nhttps://github.com/appcelerator/titanium_mobile/commit/3452f0617966...
[INFO] Titanium SDK version: 1.6.0 (01/10/11\n08:25 3452f06) G1 (1.6) and the 1.6 emulator.
seems like the problem persists with the latest nightly build\n[INFO] Titanium SDK version: 1.6.0 (01/22/11\n23:17 9177466...)
\nthe Titanium variable is just not available to the android\nsimulator even after a wait of 60 seconds (tested using Bill\nDawson's method above) making the API completely unavailable for\nuse on remote web pages. The page was generated with PHP but the\noutput is equal to what Bill Dawson provided.