Blazor Server reconnect on mobile / iPhone Safari

774 Views Asked by At

Created a Blazor Server App using VS2022 Net 6. Hosting in IIS / win 2022.

On my computer the reconnect on sleeping computer / tab in browser works fine. On my iPhone in safari, I can never reconnect when the tab has been in power save mode.

I tried some JS code to do an automatic document.reload() - but that doesn't seem to work? In this app, there are no state to save, so it should be simple :-)

What am I missing? I want the user to be able to open the app and put it on a sleeping tab, open the sleeping tab like 4 hours later to use the App again. I don't want to increase the connection timeout to 999999 - I just want it to reconnect nicely.

Maybe Blazor isn't the best technology for this?

// Lazze

1

There are 1 best solutions below

0
Lars Siden On

One way to get it to work better is to add this code to _layout.shtml - last section inside the body tag

<script autostart="false" src="_framework/blazor.server.js"></script>
 <script>
  Blazor.start({
    reconnectionHandler: {
      onConnectionDown: (options, error) => document.location.reload(),
      onConnectionUp: () => console.log("Up, up, and away!")
    }
  });
</script>

This seems to auto-reload without error messages.

// Lazze