Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2025-09

page reload when server restarted not 100% reliable

9 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luca Olivetti

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).

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Pantalla</title>

<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="fa/css/all.min.css"> <link rel="stylesheet" type="text/css" href="choices/choices.min.css">

<link rel="stylesheet" type="text/css" href="css/pantalla.css"> <script src="js/bootstrap.bundle.min.js"></script> <script src="choices/choices.min.js"></script>
<script src="js/qrcode.js"></script>
<!--- below my pas2js application -------------------> <script src="sesewebclient.js"></script>

</head>

<body>

....

     <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>

</body>
</html>

but today, even with the check on rtl and QRCode, I got a blank page when I restarted the server, maybe something else wasn't loaded. This is strange because the rtl.run() shouldn't fire if all the other parts haven't been completely loaded, right? An edge quirk? In any case, if this happens, is there a way to make the try..catch work, so I don't have to check all of the libraries?

Bye

Luca

Reply by email

Mattias Gaertner
to Luca Olivetti
Luca Olivetti wrote 11 lines
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);

Mattias

Reply by email

Luca Olivetti
to Mattias Gaertner

El 22/9/25 a les 17:11, Mattias Gaertner via Pas2js ha escrit:

Show quoted text 18 lines
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.

Bye

Luca

Reply by email

Luca Olivetti
to Luca Olivetti

El 22/9/25 a les 17:48, Luca Olivetti via Pas2js ha escrit:

Show quoted text 25 lines
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.

(*) to quickly test I just removed one of the files from the server, but in real life, if I'm unlucky enough, the server could be restarting right after loading the html, before loading the extra js and be ready again to load the pas2js application.

(**) and with edge in kiosk mode not even that

Bye

Luca

Reply by email

Michael Van Canneyt
to Luca Olivetti
Luca Olivetti wrote 49 lines
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.

Reply by email

Luca Olivetti
to Michael Van Canneyt

El 22/9/25 a les 18:33, Michael Van Canneyt ha escrit:

Show quoted text 18 lines
> 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); ??? } ? } });

Again, I'm not 100% sure but I think I tried everything at the time. In any case in the scenario I described It shouldn't make a difference: something is showing the exception instead of being propagated to my try..catch block.

Bye

Luca

Reply by email

Luca Olivetti
to Luca Olivetti

El 22/9/25 a les 18:44, Luca Olivetti via Pas2js ha escrit:

Show quoted text 26 lines
El 22/9/25 a les 18:33, Michael Van Canneyt ha escrit: >> 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); > ???? } > ?? } > }); Again, I'm not 100% sure but I think I tried everything at the time. In any case in the scenario I described It shouldn't make a difference: something is showing the exception instead of being propagated to my try..catch block.

The "trick" is to catch the exception inside the pas2js application, since TBrowserApplication.OnException doesn't handle the exception, I had to override the ShowException method.

procedure TMyApplication.ShowException(E: Exception);
Var
   S : String;
   T : TTimer;
begin
   if (Enil) then
     S:=E.ClassName+': '+E.Message
   else if ExceptObjectJS then
     S:=TJSObject(ExceptObjectJS).toString;
   S:='Unhandled exception caught: '+S;
   Console.Log(s);
   //ha llegado a inicializar
   if Assigned(errorScreen) then
     showErrorScreen(S);
   T:=TTimer.Create(nil);
   T.Interval:=5000;
   ;
   T.Enabled:=true;
end;

Now I'll have to decide if I still have to check for rtl === 'undefined'

Bye

Luca

Reply by email

Michael Van Canneyt
to Luca Olivetti
Luca Olivetti wrote 55 lines
El 22/9/25 a les 18:44, Luca Olivetti via Pas2js ha escrit: > El 22/9/25 a les 18:33, Michael Van Canneyt ha escrit: > >>> 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); >> ???? } >> ?? } >> }); > > Again, I'm not 100% sure but I think I tried everything at the time. > In any case in the scenario I described It shouldn't make a difference: > something is showing the exception instead of being propagated to my > try..catch block. > The "trick" is to catch the exception inside the pas2js application, since TBrowserApplication.OnException doesn't handle the exception, I had to override the ShowException method. procedure TMyApplication.ShowException(E: Exception); Var S : String; T : TTimer; begin if (Enil) then S:=E.ClassName+': '+E.Message else if ExceptObjectJS then S:=TJSObject(ExceptObjectJS).toString; S:='Unhandled exception caught: '+S; Console.Log(s); //ha llegado a inicializar if Assigned(errorScreen) then showErrorScreen(S); T:=TTimer.Create(nil); T.Interval:=5000; ; T.Enabled:=true; end; Now I'll have to decide if I still have to check for rtl === 'undefined'

If rtl is undefined, then there will be no TMyApplication ?

Michael.

Reply by email

Luca Olivetti
to Michael Van Canneyt

El 23/9/25 a les 9:46, Michael Van Canneyt ha escrit:

> Now I'll have to decide if I still have to check for rtl === 'undefined' If rtl is undefined, then there will be no TMyApplication ?

Yes, in fact I left the check for rtl === 'undefined' in the html. I hope I covered all the based.
I'm not sure that OnException doing nothing in a TBrowserApplication is correct though.

Bye

Luca

Reply by email