]>
Commit | Line | Data |
---|---|---|
adfc9d3f SR |
1 | // NB: this should *not* be included as a module until we have |
2 | // native support in the browsers, so that our error handler | |
3 | // can catch script-loading errors. | |
4 | ||
651c23ec JD |
5 | // No ES6 can be used in this file since it's used for the translation |
6 | /* eslint-disable prefer-arrow-callback */ | |
7 | ||
8 | (function() { | |
adfc9d3f SR |
9 | "use strict"; |
10 | ||
adfc9d3f SR |
11 | // Fallback for all uncought errors |
12 | function handleError (event, err) { | |
13 | try { | |
2b5f94fa | 14 | const msg = document.getElementById('noVNC_fallback_errormsg'); |
adfc9d3f SR |
15 | |
16 | // Only show the initial error | |
17 | if (msg.hasChildNodes()) { | |
18 | return false; | |
19 | } | |
20 | ||
2b5f94fa | 21 | let div = document.createElement("div"); |
adfc9d3f | 22 | div.classList.add('noVNC_message'); |
c361080b | 23 | div.appendChild(document.createTextNode(event.message)); |
adfc9d3f SR |
24 | msg.appendChild(div); |
25 | ||
732233ed | 26 | if (event.filename) { |
adfc9d3f SR |
27 | div = document.createElement("div"); |
28 | div.className = 'noVNC_location'; | |
2b5f94fa | 29 | let text = event.filename; |
732233ed PO |
30 | if (event.lineno !== undefined) { |
31 | text += ":" + event.lineno; | |
32 | if (event.colno !== undefined) { | |
33 | text += ":" + event.colno; | |
34 | } | |
35 | } | |
36 | div.appendChild(document.createTextNode(text)); | |
adfc9d3f SR |
37 | msg.appendChild(div); |
38 | } | |
39 | ||
7d60e97c | 40 | if (err && err.stack) { |
adfc9d3f SR |
41 | div = document.createElement("div"); |
42 | div.className = 'noVNC_stack'; | |
43 | div.appendChild(document.createTextNode(err.stack)); | |
44 | msg.appendChild(div); | |
45 | } | |
46 | ||
47 | document.getElementById('noVNC_fallback_error') | |
48 | .classList.add("noVNC_open"); | |
49 | } catch (exc) { | |
50 | document.write("noVNC encountered an error."); | |
51 | } | |
52 | // Don't return true since this would prevent the error | |
53 | // from being printed to the browser console. | |
54 | return false; | |
55 | } | |
56 | window.addEventListener('error', function (evt) { handleError(evt, evt.error); }); | |
57 | window.addEventListener('unhandledrejection', function (evt) { handleError(evt.reason, evt.reason); }); | |
58 | })(); |