]>
git.proxmox.com Git - mirror_novnc.git/blob - app/error-handler.js
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 // NB: this should *not* be included as a module until we have
10 // native support in the browsers, so that our error handler
11 // can catch script-loading errors.
13 // No ES6 can be used in this file since it's used for the translation
14 /* eslint-disable prefer-arrow-callback */
19 // Fallback for all uncought errors
20 function handleError(event
, err
) {
22 const msg
= document
.getElementById('noVNC_fallback_errormsg');
24 // Only show the initial error
25 if (msg
.hasChildNodes()) {
29 let div
= document
.createElement("div");
30 div
.classList
.add('noVNC_message');
31 div
.appendChild(document
.createTextNode(event
.message
));
35 div
= document
.createElement("div");
36 div
.className
= 'noVNC_location';
37 let text
= event
.filename
;
38 if (event
.lineno
!== undefined) {
39 text
+= ":" + event
.lineno
;
40 if (event
.colno
!== undefined) {
41 text
+= ":" + event
.colno
;
44 div
.appendChild(document
.createTextNode(text
));
48 if (err
&& err
.stack
) {
49 div
= document
.createElement("div");
50 div
.className
= 'noVNC_stack';
51 div
.appendChild(document
.createTextNode(err
.stack
));
55 document
.getElementById('noVNC_fallback_error')
56 .classList
.add("noVNC_open");
58 document
.write("noVNC encountered an error.");
60 // Don't return true since this would prevent the error
61 // from being printed to the browser console.
64 window
.addEventListener('error', function onerror(evt
) { handleError(evt
, evt
.error
); });
65 window
.addEventListener('unhandledrejection', function onreject(evt
) { handleError(evt
.reason
, evt
.reason
); });