Could not execute returned javascript: could not set properties of null object

Sorry to raise this Web api 1.0 issue again, but I wonder if someone would know the answer to this question…

(for added context, I refer to this previous thread: Xojo Topic - could not execute returned javascript )

I understand that when embedding a dynamically created Container within a WebPage one should not attempt to manipulate any UI properties of the Container in the same Method as the EmbedWithin code. Instead, place any such UI manipulation code into the Container’s .Shown event. (As this avoids the possibility of the user’s browser receiving property manipulation JS before the browser has received the object creation JS)

My question here is: Where would be the correct place to use AddHandler (example - if I wanted to add an event handler to the newly created Container)??

Any advice would be much appreciated!

AddHandler is purely Xojo, so anytime after creation. Doesn’t matter if it’s embedded or not, as long as the WebContainer isn’t Nil.

2 Likes

Many thanks - I suspected that was the case, but nice to have that confirmed. :+1:

Happy to help!

I also have some additional questions…

It is not immediately clear to me which properties (of a webContainer, say) are UI implemented browser-side / server-side.

ie, if I create a new instance of a Container (which has a string Property (ie “Serial Number”, which is never in UI) and a WebLabel (which has a Text Property) and an ImageWell (which has a Picture Property) - which of these properties can I safely set BEFORE EmbedWithin ??

To my way of thinking, up until the point that EmbedWithin is called, the UI is not being sent any info about this object, so I am free to set whatever properties I want, but what I must avoid is changing anything visible (the Label / the ImageWell / or the Container coordinates) AFTER EnbedWithin. Any such changes should only be made AFTER the Container’s Shown Event has fired - right??

Am I understanding this correctly??

The problem I am facing is this, for example, If I leave the ImageWell.Picture property as Nil, BEFORE Embedwithiin, and then add the picture during the Container’s Shown event - it works perfectly on all browsers except iPad Safari - which “occasionally” will show a blank ImageWell. If I add the picture to the ImageWell BEFORE EmbedWithin the ImageWell displays perfectly on all browsers 100% of the time - but Windows Chrome will “occasionally” display the “Could not execute returned javascript” error.

Both of the above errors are rare, and only happen, maybe once in every 50 runs, and only happen when running the app on a remote Linux server. These errors NEVER happen when running in Windows local debug.

It’s all about internet async timing - but my head hurts!!

Really grateful if anyone can explain more about how / when Xojo sends js to the browser and what events get reported back to the server from the browser (and when!).

When you embedwithin(), Xojo creates a local instance, which you can modify, such as assigning a picture, and then creates the instance in the client.

Depending on the latency of the Internet connection of the client, it can take 200ms or more for the DOM to be updated with the new HTML element.

The error reported by Chrome has probably to do with that. Perhaps you can use a server side timer with a delay of 500 ms to assign the picture.

Many thanks for your suggestion Michel. I have previously tried a server side timer and it does work ok, but the UI effect does not look great (The blank container appears first, then the picture appears after a variable delay of a second or two).

Instead, I have added the picture assignment code into the ImageWell’s Shown event. So far this appears to work perfectly across all browsers / platforms. I just wish I knew exactly why it works!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.