Search code examples
tizentizen-wearable-sdktizen-web-app

Method exported by library cannot not be invoked from code, but from DevTools


The task is to create a Tizen Wearable App, targeting Tizen 2.3.2, using the TAU framework.

The application itself consists of two parts by design:

  • A service is running in the background, receiving notifications from a server. Messages received by the service are being passed to the UI-application.

  • The UI itself is being either started or brought to the foreground by service, whenever a message is being received. Multiple 'popups' exist within the application, which handle the each (possible) notification accordingly. The popups are being opened using tau.openPopup('popId').

However, calling tau.openPopup from code results in an error:

TypeError: 'undefined' is not a function (evaluating 'tau.openPopup('process-popup')')

Calling the same expression from the development console (Chrome DevTools) does work as intented, implying that the library was indeed loaded properly and its methods are being exported properly.

Recreating the GUI application (using the template provided by Tizen Studio) did NOT solve the problem. At this point I ran out of ideas; probably due to my lack of experience in working with JavaScript.

What could be the cause of such peculiar behavior?


Solution

  • The peculiar behavior leads back to the fact, that scripts are allowed to be executed before all resources finished loading.

    In this particular problem, the TAU library was loaded AFTER my script, meaning the method tau.openPopup was at time of invocation not yet loaded by the browser, thus undefined. When opening and invoking from console, the browser happened to finished loading, thus the method was defined.

    This problem can be solved, by waiting for the browser to finish loading resources. The simplest, native solution would be to register a callback (or event listener) on the window.onLoad event; e.g.:

    window.onload = function () { // Now we can do awesome stuff here! }