debugging javascript in html5
Bernard Devlin
bdrunrev at gmail.com
Fri Mar 18 07:19:28 EDT 2022
Here's a peculiarity I haven't seen mentioned before. I am trying to test
the viability of the idea of a function to call back to LC and provide
debugging info.
Assume you create a LC function lclog(pmsg,pval) and you put a breakpoint
in the IDE inside that function body. Set the htmltext of a browser widget
to the code below, set the javascriptHandlers of the browser to contain the
word: lclog . Your browser widget will have a button 'clickme'.
1) On clicking that button the JS alerts ALL trigger first.
2) After they have fired the first call to lclog() runs, and the second
call to lclog() never runs.
<html><head><script>
function lcxhr(method, url) {
alert('lcxhr called');
var json = JSON.stringify({ name: "John", surname: "Smith"});
liveCode.lclog('json created', json);
alert('you see this alert before the above call to lclog()');
liveCode.lclog('exit js function','');
}</script>
</head><body><input id="clickMe" type="button" value="clickme"
onclick="lcxhr('','http://192.168.0.34:8080/tabs/echo');" /></body></html>
In case that html gets mangled by the uselist software, here's the above
html base64encoded:
PGh0bWw+PGhlYWQ+PHNjcmlwdD5mdW5jdGlvbiBsY3hocihtZXRob2QsIHVybCkgewphbGVy
dCgnbGN4aHIgY2FsbGVkJyk7IAp2YXIganNvbiA9IEpTT04uc3RyaW5naWZ5KHsgIG5hbWU6
ICJKb2huIiwgIHN1cm5hbWU6ICJTbWl0aCJ9KTsKbGl2ZUNvZGUubGNsb2coJ2pzb24gY3Jl
YXRlZCcsIGpzb24pOwphbGVydCgneW91IHNlZSB0aGlzIGFsZXJ0IGJlZm9yZSB0aGUgYWJv
dmUgY2FsbCB0byBsY2xvZygpJyk7CmxpdmVDb2RlLmxjbG9nKCdleGl0IGpzIGZ1bmN0aW9u
JywnJyk7Cn08L3NjcmlwdD48L2hlYWQ+PGJvZHk+PGlucHV0IGlkPSJjbGlja01lIiB0eXBl
PSJidXR0b24iIHZhbHVlPSJjbGlja21lIiBvbmNsaWNrPSJsY3hocignJywnaHR0cDovLzE5
Mi4xNjguMC4zNDo4MDgwL3RhYnMvZWNoby50Y2wnKTsiIC8+PC9ib2R5PjwvaHRtbD4=
So we can't rely on the timing of anything returned to a javascripHandler.
Moreover, once a javascriptHandler has fired there can't be anything else
that runs. Quite a limitation IMO.
Regards
Bernard
>
More information about the use-livecode
mailing list