Make error handler's focus changes best-effort

When the error handler itself causes an exception, it falls back to a
simple document.write(). This means the proper error dialog isn't shown
when this happens.

The focus changes that were added to the error handler in e1f8232b are
not crucial for its function. If these focus changes causes an exception
we can just ignore that.
This commit is contained in:
Samuel Mannehed 2022-10-12 12:50:08 +02:00
parent 4ecb44111d
commit 145d235094
1 changed files with 8 additions and 1 deletions

View File

@ -51,6 +51,12 @@ function handleError(event, err) {
document.getElementById('noVNC_fallback_error') document.getElementById('noVNC_fallback_error')
.classList.add("noVNC_open"); .classList.add("noVNC_open");
} catch (exc) {
document.write("noVNC encountered an error.");
}
// Try to disable keyboard interaction, best effort
try {
// Remove focus from the currently focused element in order to // Remove focus from the currently focused element in order to
// prevent keyboard interaction from continuing // prevent keyboard interaction from continuing
if (document.activeElement) { document.activeElement.blur(); } if (document.activeElement) { document.activeElement.blur(); }
@ -61,8 +67,9 @@ function handleError(event, err) {
elem.setAttribute("tabindex", "-1"); elem.setAttribute("tabindex", "-1");
}); });
} catch (exc) { } catch (exc) {
document.write("noVNC encountered an error."); // Do nothing
} }
// Don't return true since this would prevent the error // Don't return true since this would prevent the error
// from being printed to the browser console. // from being printed to the browser console.
return false; return false;