mirror of
https://git.proxmox.com/git/mirror_novnc
synced 2025-05-28 07:10:00 +00:00

When this error is shown, something has gone very wrong. It shows when a bug in the JavaScript causes an uncaught error. In these scenarios we dont want the user to be able to interact with the GUI or the remote session, since we can't guarantee that things work.
73 lines
2.5 KiB
JavaScript
73 lines
2.5 KiB
JavaScript
/*
|
|
* noVNC: HTML5 VNC client
|
|
* Copyright (C) 2019 The noVNC Authors
|
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
*
|
|
* See README.md for usage and integration instructions.
|
|
*/
|
|
|
|
// Fallback for all uncought errors
|
|
function handleError(event, err) {
|
|
try {
|
|
const msg = document.getElementById('noVNC_fallback_errormsg');
|
|
|
|
// Work around Firefox bug:
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1685038
|
|
if (event.message === "ResizeObserver loop completed with undelivered notifications.") {
|
|
return false;
|
|
}
|
|
|
|
// Only show the initial error
|
|
if (msg.hasChildNodes()) {
|
|
return false;
|
|
}
|
|
|
|
let div = document.createElement("div");
|
|
div.classList.add('noVNC_message');
|
|
div.appendChild(document.createTextNode(event.message));
|
|
msg.appendChild(div);
|
|
|
|
if (event.filename) {
|
|
div = document.createElement("div");
|
|
div.className = 'noVNC_location';
|
|
let text = event.filename;
|
|
if (event.lineno !== undefined) {
|
|
text += ":" + event.lineno;
|
|
if (event.colno !== undefined) {
|
|
text += ":" + event.colno;
|
|
}
|
|
}
|
|
div.appendChild(document.createTextNode(text));
|
|
msg.appendChild(div);
|
|
}
|
|
|
|
if (err && err.stack) {
|
|
div = document.createElement("div");
|
|
div.className = 'noVNC_stack';
|
|
div.appendChild(document.createTextNode(err.stack));
|
|
msg.appendChild(div);
|
|
}
|
|
|
|
document.getElementById('noVNC_fallback_error')
|
|
.classList.add("noVNC_open");
|
|
|
|
// Remove focus from the currently focused element in order to
|
|
// prevent keyboard interaction from continuing
|
|
document.activeElement.blur();
|
|
|
|
// Don't let any element be focusable when showing the error
|
|
let keyboardFocusable = 'a[href], button, input, textarea, select, details, [tabindex]';
|
|
document.querySelectorAll(keyboardFocusable).forEach((elem) => {
|
|
elem.setAttribute("tabindex", "-1");
|
|
});
|
|
} catch (exc) {
|
|
document.write("noVNC encountered an error.");
|
|
}
|
|
// Don't return true since this would prevent the error
|
|
// from being printed to the browser console.
|
|
return false;
|
|
}
|
|
|
|
window.addEventListener('error', evt => handleError(evt, evt.error));
|
|
window.addEventListener('unhandledrejection', evt => handleError(evt.reason, evt.reason));
|