2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2019 The noVNC Authors
4 * Licensed under MPL 2.0 (see LICENSE.txt)
6 * See README.md for usage and integration instructions.
9// Fallback for all uncought errors
10function handleError(event, err) {
12 const msg = document.getElementById('noVNC_fallback_errormsg');
14 // Work around Firefox bug:
15 // https://bugzilla.mozilla.org/show_bug.cgi?id=1685038
16 if (event.message === "ResizeObserver loop completed with undelivered notifications.") {
20 // Only show the initial error
21 if (msg.hasChildNodes()) {
25 let div = document.createElement("div");
26 div.classList.add('noVNC_message');
27 div.appendChild(document.createTextNode(event.message));
31 div = document.createElement("div");
32 div.className = 'noVNC_location';
33 let text = event.filename;
34 if (event.lineno !== undefined) {
35 text += ":" + event.lineno;
36 if (event.colno !== undefined) {
37 text += ":" + event.colno;
40 div.appendChild(document.createTextNode(text));
44 if (err && err.stack) {
45 div = document.createElement("div");
46 div.className = 'noVNC_stack';
47 div.appendChild(document.createTextNode(err.stack));
51 document.getElementById('noVNC_fallback_error')
52 .classList.add("noVNC_open");
55 document.write("noVNC encountered an error.");
58 // Try to disable keyboard interaction, best effort
60 // Remove focus from the currently focused element in order to
61 // prevent keyboard interaction from continuing
62 if (document.activeElement) { document.activeElement.blur(); }
64 // Don't let any element be focusable when showing the error
65 let keyboardFocusable = 'a[href], button, input, textarea, select, details, [tabindex]';
66 document.querySelectorAll(keyboardFocusable).forEach((elem) => {
67 elem.setAttribute("tabindex", "-1");
73 // Don't return true since this would prevent the error
74 // from being printed to the browser console.
78window.addEventListener('error', evt => handleError(evt, evt.error));
79window.addEventListener('unhandledrejection', evt => handleError(evt.reason, evt.reason));