Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1635] Android: Errors with "logging and Unicode" test cases

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:56:43.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.6.0 M04
ComponentsAndroid
Labelsandroid, defect, release-1.6.0
ReporterThomas Huelbert
AssigneeDon Thorp
Created2011-04-15T02:57:54.000+0000
Updated2011-04-17T01:56:43.000+0000

Description

1.BaseUI>Views>WebViews>Loggin and unicode
2.check console output

results:
E/Web Console( 627): Uncaught TypeError: Cannot read property 'API' of undefined at file:///android_asset/Resources/examples/webview_logging.html:5
D/TiAPI ( 627): (kroll$31) [102,344500] webview loaded: file:///android_asset/Resources/examples/webview_logging.html

Comments

  1. Bill Dawson 2011-04-15

    Thomas, just curious, was the failcase from a device or the emulator? I'm getting weird mixed behavior. (You can assign to me after answering)

  2. Thomas Huelbert 2011-04-15

    Sorry for the omitted info Bill - this was device only (worked on the simulator when I tested it) - nexus one running 2.2

  3. Bill Dawson 2011-04-15

    Ok, cool, I have the exact same behavior pattern. Fails on my HTC Desire using 2.2, works in an emulator (I tried it with a 2.1 emulator but will also try 2.2).

  4. Bill Dawson 2011-04-15

    So this has been broken (on devices -- at least 2.2) basically forever. I tried even for Titanium 1.3:

       I/TiAPI   (19880): (kroll$1) [115,154]  *** TITANIUM VERSION 1.3.0 ***
       I/ActivityManager(   97): Displayed activity com.billdawson.simplewebview/.SimplewebviewActivity: 548 ms (total 548 ms)
       I/TabGroupProxy(19880): (main) [82,236] handleOpen
       I/ActivityManager(   97): Starting activity: Intent { cmp=com.billdawson.simplewebview/ti.modules.titanium.ui.TiTabActivity (has extras) }
       W/TiTabActivity(19880): (main) [32,268] Notifying TiTabGroup, activity is created
       W/TiActivity(19880): (main) [114,382] Notifying TiUIWindow, activity is created
       I/ActivityManager(   97): Displayed activity com.billdawson.simplewebview/ti.modules.titanium.ui.TiTabActivity: 312 ms (total 312 ms)
       E/Web Console(19880): Uncaught ReferenceError: TiAPI is not defined at :1
       D/webkit-timers(19880): [JWebCoreJavaBridge::resume] >> do resume
       E/Web Console(19880): Uncaught TypeError: Cannot read property 'API' of undefined at file:///android_asset/Resources/simple.html:23
       

    That D/webkit-timers(19880) line is interesting. It does not occur in the emulator!

    Still researching...

  5. Bill Dawson 2011-04-15

    Here is the core Android code for WebView.addJavascriptInterface(), which we use to put TiAPI and TiApp in the javascript scope:

       public void addJavascriptInterface(Object obj, String interfaceName) {
               WebViewCore.JSInterfaceData arg = new WebViewCore.JSInterfaceData();
               arg.mObject = obj;
               arg.mInterfaceName = interfaceName;
               mWebViewCore.sendMessage(EventHub.ADD_JS_INTERFACE, arg);
           }
       

    Messages in mWebViewCore are handled on a separate thread. Maybe the loading of a page in the webview is actually fast enough to occur before our objects are added to the javascript scope.

    In my tests on an HTC Desire running Android 2.2, this page loaded in a WebView and required the setTimeout to run once (with just 100 milliseconds) before Ti.API was available:

       <!doctype html>
       <html>
           <body>
               <div id="log"></div>
           </body>
           <script>
           var i = 1;
           function log(s) {
               document.getElementById('log').innerHTML += '<br/>' + s;
           }
           var interval = 100;
           function checkTi() {
               if (!window.hasOwnProperty("Ti") ) {
                   log("Still no Ti.  Trying again (" + i + ")");
                   i++;
                   setTimeout(checkTi, interval);
               } else if (typeof window.Ti === 'undefined') {
                   log('Got Ti, but it is undefined.  Trying again (' + i + ')');
                   i++;
                   setTimeout(checkTi, interval);
               } else if (!window.Ti.hasOwnProperty('API')) {
                   log("Ti but no Ti.API.  Trying again (" + i + ")");
                   i++;
                   setTimeout(checkTi, interval);
               } else {
                   log('got it on try ' + i);
                   Ti.API.info('Welcome to my web page');
               }
           }
           window.onload = function() {
               checkTi();
           }
           </script>
       </html>
       
  6. Bill Dawson 2011-04-15

    (from [12d7bf6a90db72fa0aebe538c95128c8a0cdc625]) Inject our Ti JS and JSON near beginning of local (and ONLY local) html file contents or html set directly via the html property. [#2153 state:fixed-in-qa][#2514 state:fixed-in-qa][#1635 state:fixed-in-qa][#1036 state:fixed-in-qa] https://github.com/appcelerator/titanium_mobile/commit/12d7bf6a90db72fa0aebe538c95128c8a0cdc625"> https://github.com/appcelerator/titanium_mobile/commit/12d7bf6a90db...

  7. Thomas Huelbert 2011-04-15

    This works great on 2.2 devices, but on 1.6 the test fails with:

    I/ActivityManager( 76): Starting activity: Intent { cmp=com.appcelerator.pushtest/org.appcelerator.titanium.TiActivity (has extras) }
    I/ActivityManager( 76): Displayed activity com.appcelerator.pushtest/org.appcelerator.titanium.TiActivity: 175 ms (total 175 ms)
    I/global ( 641): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
    D/WebCore ( 641): Console: ReferenceError: Can't find variable: Ti line: 5 source: file:///android_asset/Resources/examples/webview_logging.html

    Maybe a fact of life on 1.6? back to Bill.

  8. Bill Dawson 2011-04-15

    (from [3452f061796695f0ad14d49fe3b22689f2e27dce]) [#1635 state:fixed-in-qa] Android webkit MimeTypeMap does not have a mime type for file extension html until Android version 2.2. So we need to add it to our own mime type map in order for html files to be recognized as text/html and therefore get our javascript code injected. https://github.com/appcelerator/titanium_mobile/commit/3452f061796695f0ad14d49fe3b22689f2e27dce"> https://github.com/appcelerator/titanium_mobile/commit/3452f0617966...

  9. Thomas Huelbert 2011-04-15

    [INFO] Titanium SDK version: 1.6.0 (01/10/11 08:25 3452f06) G1 (1.6) and the 1.6 emulator.

  10. vooood 2011-04-15

    seems like the problem persists with the latest nightly build [INFO] Titanium SDK version: 1.6.0 (01/22/11 23:17 9177466...)

    the Titanium variable is just not available to the android simulator even after a wait of 60 seconds (tested using Bill Dawson's method above) making the API completely unavailable for use on remote web pages. The page was generated with PHP but the output is equal to what Bill Dawson provided.

JSON Source