]>
Commit | Line | Data |
---|---|---|
412d9306 SM |
1 | /* |
2 | * noVNC: HTML5 VNC client | |
3 | * Copyright (C) 2019 The noVNC Authors | |
4 | * Licensed under MPL 2.0 (see LICENSE.txt) | |
5 | * | |
6 | * See README.md for usage and integration instructions. | |
7 | */ | |
8 | ||
adfc9d3f SR |
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. | |
12 | ||
651c23ec JD |
13 | // No ES6 can be used in this file since it's used for the translation |
14 | /* eslint-disable prefer-arrow-callback */ | |
15 | ||
e7777653 | 16 | (function _scope() { |
adfc9d3f SR |
17 | "use strict"; |
18 | ||
adfc9d3f | 19 | // Fallback for all uncought errors |
2c5491e1 | 20 | function handleError(event, err) { |
adfc9d3f | 21 | try { |
2b5f94fa | 22 | const msg = document.getElementById('noVNC_fallback_errormsg'); |
adfc9d3f SR |
23 | |
24 | // Only show the initial error | |
25 | if (msg.hasChildNodes()) { | |
26 | return false; | |
27 | } | |
28 | ||
2b5f94fa | 29 | let div = document.createElement("div"); |
adfc9d3f | 30 | div.classList.add('noVNC_message'); |
c361080b | 31 | div.appendChild(document.createTextNode(event.message)); |
adfc9d3f SR |
32 | msg.appendChild(div); |
33 | ||
732233ed | 34 | if (event.filename) { |
adfc9d3f SR |
35 | div = document.createElement("div"); |
36 | div.className = 'noVNC_location'; | |
2b5f94fa | 37 | let text = event.filename; |
732233ed PO |
38 | if (event.lineno !== undefined) { |
39 | text += ":" + event.lineno; | |
40 | if (event.colno !== undefined) { | |
41 | text += ":" + event.colno; | |
42 | } | |
43 | } | |
44 | div.appendChild(document.createTextNode(text)); | |
adfc9d3f SR |
45 | msg.appendChild(div); |
46 | } | |
47 | ||
7d60e97c | 48 | if (err && err.stack) { |
adfc9d3f SR |
49 | div = document.createElement("div"); |
50 | div.className = 'noVNC_stack'; | |
51 | div.appendChild(document.createTextNode(err.stack)); | |
52 | msg.appendChild(div); | |
53 | } | |
54 | ||
55 | document.getElementById('noVNC_fallback_error') | |
56 | .classList.add("noVNC_open"); | |
57 | } catch (exc) { | |
58 | document.write("noVNC encountered an error."); | |
59 | } | |
60 | // Don't return true since this would prevent the error | |
61 | // from being printed to the browser console. | |
62 | return false; | |
63 | } | |
e7777653 PO |
64 | window.addEventListener('error', function onerror(evt) { handleError(evt, evt.error); }); |
65 | window.addEventListener('unhandledrejection', function onreject(evt) { handleError(evt.reason, evt.reason); }); | |
adfc9d3f | 66 | })(); |