diff options
Diffstat (limited to 'webclients/novnc/app/error-handler.js')
-rw-r--r-- | webclients/novnc/app/error-handler.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/webclients/novnc/app/error-handler.js b/webclients/novnc/app/error-handler.js new file mode 100644 index 0000000..e5a6adb --- /dev/null +++ b/webclients/novnc/app/error-handler.js @@ -0,0 +1,56 @@ +// NB: this should *not* be included as a module until we have +// native support in the browsers, so that our error handler +// can catch script-loading errors. + + +(function(){ + "use strict"; + + // Fallback for all uncought errors + function handleError (event, err) { + try { + var msg = document.getElementById('noVNC_fallback_errormsg'); + + // Only show the initial error + if (msg.hasChildNodes()) { + return false; + } + + var 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'; + var 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 !== undefined)) { + 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"); + } 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', function (evt) { handleError(evt, evt.error); }); + window.addEventListener('unhandledrejection', function (evt) { handleError(evt.reason, evt.reason); }); +})(); |