From 7a936ea01e72d2cd884a8b18c81da761bb9da92a Mon Sep 17 00:00:00 2001
From: ed
Date: Sat, 13 Jan 2024 01:22:20 +0000
Subject: [PATCH] js: be careful with allocations in crash handler
---
copyparty/web/util.js | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/copyparty/web/util.js b/copyparty/web/util.js
index 593443b5..4f94b653 100644
--- a/copyparty/web/util.js
+++ b/copyparty/web/util.js
@@ -202,19 +202,24 @@ function vis_exh(msg, url, lineNo, columnNo, error) {
}
ignexd[ekey] = true;
- var ls = jcp(localStorage);
- if (ls.fman_clip)
- ls.fman_clip = ls.fman_clip.length + ' items';
+ var ls = {},
+ lsk = Object.keys(localStorage),
+ nka = lsk.length,
+ nk = Math.min(200, nka);
- var lsk = Object.keys(ls);
- lsk.sort();
- html.push('
');
- for (var a = 0; a < lsk.length; a++) {
- if (ls[lsk[a]].length > 9000)
- continue;
+ for (var a = 0; a < nk; a++) {
+ var k = lsk[a],
+ v = localStorage.getItem(k);
- html.push(' ' + esc(lsk[a]) + ' ' + esc(ls[lsk[a]]) + '
');
+ ls[k] = v.length > 256 ? v.slice(0, 32) + '[...' + v.length + 'b]' : v;
}
+
+ lsk = Object.keys(ls);
+ lsk.sort();
+ html.push('
' + nka + ': ');
+ for (var a = 0; a < nk; a++)
+ html.push(' ' + esc(lsk[a]) + ' ' + esc(ls[lsk[a]]) + '
');
+
html.push('