From 3226a1f58828a83f3f715f12b1e3ac99ef9cf3b2 Mon Sep 17 00:00:00 2001
From: ed
Date: Thu, 2 Sep 2021 18:45:42 +0200
Subject: [PATCH] crashpage: show recent console messages
---
copyparty/web/util.js | 41 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 39 insertions(+), 2 deletions(-)
diff --git a/copyparty/web/util.js b/copyparty/web/util.js
index 908fe469..873fbf5a 100644
--- a/copyparty/web/util.js
+++ b/copyparty/web/util.js
@@ -29,6 +29,35 @@ function esc(txt) {
}[c];
});
}
+window.onunhandledrejection = function (e) {
+ console.log("REJ: " + e.reason);
+};
+try {
+ console.hist = [];
+ var hook = function (t) {
+ var orig = console[t].bind(console),
+ cfun = function () {
+ console.hist.push(Date.now() + ' ' + t + ' ' + Array.from(arguments).join(', '));
+ if (console.hist.length > 100)
+ console.hist = console.hist.slice(50);
+
+ orig.apply(console, arguments);
+ };
+
+ console['std' + t] = orig;
+ console[t] = cfun;
+ };
+ hook('log');
+ console.log('log-capture ok');
+ hook('debug');
+ hook('warn');
+ hook('error');
+}
+catch (ex) {
+ if (console.stdlog)
+ console.log = console.stdlog;
+ console.log(ex);
+}
var crashed = false, ignexd = {};
function vis_exh(msg, url, lineNo, columnNo, error) {
if ((msg + '').indexOf('ResizeObserver') !== -1)
@@ -55,7 +84,7 @@ function vis_exh(msg, url, lineNo, columnNo, error) {
adb = ad.brands;
for (var a = 0; a < adb.length; a++)
- if (adb[a].brand.indexOf('Not;A') < 0)
+ if (!/Not.*A.*Brand/.exec(adb[a].brand))
ua += adb[a].brand + '/' + adb[a].version + ', ';
ua += ad.platform;
@@ -87,6 +116,13 @@ function vis_exh(msg, url, lineNo, columnNo, error) {
}
catch (e) { }
+ if (console.hist.length) {
+ html.push('
console: