[Pas2js] page reload when server restarted not 100% reliable

Michael Van Canneyt michael at freepascal.org
Mon Sep 22 18:33:42 CEST 2025



On Mon, 22 Sep 2025, Luca Olivetti via Pas2js wrote:

> El 22/9/25 a les 17:48, Luca Olivetti via Pas2js ha escrit:
>> El 22/9/25 a les 17:11, Mattias Gaertner via Pas2js ha escrit:
>>> 
>>> 
>>> On 9/22/25 16:19, Luca Olivetti via Pas2js wrote:
>>>> I have ~20 clients (windows 11 in kiosk mode with edge as the kiosk 
>>>> application). They're touch screen only, no keyboard or mouse.
>>>> The pas2j application tries to reload the page when the connection is 
>>>> severed (it's using a TJSEventSource and the server sends a message every 
>>>> 5 seconds).q
>>>> The problem is that, from time to time, the page is blank (I cannot 
>>>> simply hit F12 to see what's happening since it's in kiosk mode).
>>>> On a non-kiosk instance I found that the pas2js application or another js 
>>>> library wasn't completely loaded while starting the application hence 
>>>> causing an exception, so I came up with this workaround (and, yes, first 
>>>> I tried just with the try..catch but it didn't work).
>>> 
>>> Wasnt completely loaded. Have you tried in the html:
>>> 
>>> window.addEventListener("load", rtl.run);
>> 
>> That's what the checkbox "Run RTL when all page resources are fully loaded" 
>> does.
>> 
>> I'm not 100% sure but I think I tried. I'll try again though.
>
> Now that I tried again, I remember what the problem was: if one of the 
> javascript files fails to load (*) I get a messagebox with the exception (**) 
> instead of entering the catch part of my try statement, that's why I added 
> the check both for rtl and QRCode (here commented out just to test the 
> problem).
>
>    <script>
>       //if (typeof rtl === 'undefined' || typeof QRCode === 'undefined') {
>       //  console.log('rtl o QRCode no definidos, recargo pagina');
>       //  setTimeout(function() { location.reload(); }, 5000);
>       //} else {
>          try {
>            rtl.run();
>          } catch(err) {
>            console.log('error '+err.message+', recargo pagina');
>            setTimeout(function() { location.reload(); }, 5000);
>          }
>       //}
>    </script>
>
>
> I'd like the exception to be propagated to the outer code so my try..catch 
> would work.

Did you try putting the above in the load ?

window.addEventListener("load", function () {
   if (typeof rtl === 'undefined' || typeof QRCode === 'undefined') {
     console.log('rtl o QRCode no definidos, recargo pagina');
     setTimeout(function() { location.reload(); }, 5000);
   } else {
     try {
       rtl.run();
     } catch(err) {
       console.log('error '+err.message+', recargo pagina');
       setTimeout(function() { location.reload(); }, 5000);
     }
   }
});

Michael.


More information about the Pas2js mailing list