From 9ac632deee0410be07187dcbb3d40fbf00ede0c3 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 5 Dec 2023 11:30:30 +0100 Subject: [PATCH] Handle immediate connection errors The browser might throw an exception right away if there is something it doesn't like with our connect attempt. E.g. using a non-TLS WebSocket from a TLS web page. --- app/ui.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/ui.js b/app/ui.js index 85695ca2..00628c72 100644 --- a/app/ui.js +++ b/app/ui.js @@ -1041,10 +1041,18 @@ const UI = { } url += '/' + path; - UI.rfb = new RFB(document.getElementById('noVNC_container'), url, - { shared: UI.getSetting('shared'), - repeaterID: UI.getSetting('repeaterID'), - credentials: { password: password } }); + try { + UI.rfb = new RFB(document.getElementById('noVNC_container'), url, + { shared: UI.getSetting('shared'), + repeaterID: UI.getSetting('repeaterID'), + credentials: { password: password } }); + } catch (exc) { + Log.Error("Failed to connect to server: " + exc); + UI.updateVisualState('disconnected'); + UI.showStatus(_("Failed to connect to server: ") + exc, 'error'); + return; + } + UI.rfb.addEventListener("connect", UI.connectFinished); UI.rfb.addEventListener("disconnect", UI.disconnectFinished); UI.rfb.addEventListener("serververification", UI.serverVerify);