There is a rather simple way to solve this for the user without fixing upstream libraries or even the doing very much on the server side.
The GUI and the connection to the server should not live in the same window, because you only really need to reload the connection window to reestablish the connection and the GUI can carry on as normal, without the user having to step away.
Basically, the GUI should load in the top frame, and the page that holds the socket to the server should be in an iframe
inside it. When connection is lost, only the iframe should reload.
Meanwhile, the GUI page should store its state on the client (probably IndexedDB), so that it can be synced with the backend when it gets reconnected, even if the user has closed the tab in the meantime.