fix(client): truncate outputs larger than 500_000 (#55485)

pull/55526/head
Lasse Jørgensen 2024-07-16 06:45:21 +02:00 committed by GitHub
parent 58b1997520
commit e49b8b0214
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 1 deletions

View File

@ -8,14 +8,19 @@ const ctx: Worker & typeof globalThis = self as unknown as Worker &
const __utils = (() => {
const MAX_LOGS_SIZE = 64 * 1024;
const TRUNCATE_AT = 500_000;
let logs: string[] = [];
function flushLogs() {
if (logs.length) {
let data = logs.join('\n');
if (data.length > TRUNCATE_AT) {
data = `${data.substring(0, TRUNCATE_AT)} Logs truncated. See browser console for more`;
}
ctx.postMessage({
type: 'LOG',
data: logs.join('\n')
data: data
});
logs = [];
}