on browser createNamespace can happen AFTER your setupJavascriptFramework event

I have a couple of great webSDK controls working now. The one in question here has a problem with timing, sometimes the loadLibraries command doesn’t get the library served up fast enough and when I go to send a message to one of the controls I just get an error because the library isn’t there yet. The second attempt to load the page on any session always worked fine.

Attempting to fix that I decided that I would return the library from the setupJavascriptFramework event. This is shown in the YUI text editor example and I used it with a mobile safari webSDK control without a problem so I very simply changed from calling the loadLibrary command with a webFile reference to just returning the text. That should work, and it does work 100% of the time on iOS. On the browser however I get the error:

Could not execute returned javascript: undefined is not an object (evaluating 'XojoCustom.XTension.motion24’)
and then the rest of my source code and a whole lot of xojo javascript.

This same code when loaded through the loadLibrary command works fine, just not on the first hit of the page. There are a LOT more xojo javascript in that error message after my source and sure enough 415 lines down the script that caused the error I found:


So the thing that was undefined was my javascript namespace. It hadn’t been created yet. On iOS this never happens, on the browser in this app it always happens. But it never happens when I work with the YUI text editor example, perhaps it has to do with how many controls are in the window as I have lots of them in this example.

It seems that my namespace should be guaranteed to have been created before you ask me for code to add to it? Is this a bug or do I not understand completely how this is supposed to be used, which is entirely possible, but I’m not doing anything that the YUI text editor example doesn’t do.

by way of testing I loaded up the mobile site containing that other control that returns code from the setupJavascriptFramework event and sure enough it fails on desktop safari while working perfectly on iOS.

just for fun I added that line:


to the top of my library code and now it loads up perfectly every time, but that feels very dirty and wrong :wink: It will get me through testing this for the time being while we figure out if I’m crazy or if there is a bug.

If you can provide an example of the namespace not being set up, please file a bug report (and soon, because I’d like to fix this in r3 if we can). I can’t think of any way that the order of these two calls could possibly get out of sync, and certainly not on different browsers.

FWIW, if you are using LoadLibraries, you should be using the callback method to send an event back to your control indicating that everything is ready to accept commands because the speed at which the external code is loaded is largely up to the end users browser and network.

I always despair of getting such an error to happen in a simple project outside the large context of the rest of the program, but I managed to do it this time. Example app and bug report :slight_smile: