Pad: Improve page load error handler

* Install the error handler early.
  * Include stack trace.
  * Remove unnecessary escaping.
  * Improve formatting.
  * Move to a separate script file.
This commit is contained in:
Richard Hansen 2021-08-02 18:45:36 -04:00
parent d4e74fd038
commit b6fba9d66d
2 changed files with 49 additions and 21 deletions

View file

@ -33,6 +33,7 @@
for the JavaScript code in this page.|
*/
</script>
<script src="../static/js/basic_error_handler.js?v=<%=settings.randomVersionString%>"></script>
<meta charset="utf-8">
<meta name="robots" content="noindex, nofollow">
@ -441,27 +442,6 @@
<% e.begin_block("scripts"); %>
<script type="text/javascript" src="../static/js/require-kernel.js?v=<%=settings.randomVersionString%>"></script>
<script type="text/javascript">
// @license magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt
(function() {
// Display errors on page load to the user
// (Gets overridden by padutils.setupGlobalExceptionHandler)
const originalHandler = window.onerror;
window.onerror = function(msg, url, line) {
const box = document.getElementById('editorloadingbox');
const cleanMessage = msg.replace(/[^0-9a-zA-Z=\.?&:\/]+/,'');
const cleanSource = url.replace(/[^0-9a-zA-Z=\.?&:\/]+/,'');
const cleanLine = parseInt(line);
box.innerText = `An error occurred while loading the pad\n${cleanMessage} in
${cleanSource} at line ${cleanLine}`
// call original error handler
if(typeof(originalHandler) == 'function') originalHandler.call(null, arguments);
};
})();
// @license-end
</script>
<script type="text/javascript" src="../socket.io/socket.io.js?v=<%=settings.randomVersionString%>"></script>
<!-- Include base packages manually (this help with debugging) -->