trackwhat-small / src /js /lib /debug.js
eggman-poff's picture
Upload folder using huggingface_hub
9435b27 verified
Raw
History Blame Contribute Delete
1.32 kB
// @ts-nocheck
export function summarizeDebugValue(value, depth = 0) {
if (value === null || value === undefined) return value;
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return value;
if (Array.isArray(value)) return value.slice(0, 6).map((item) => summarizeDebugValue(item, depth + 1));
if (value instanceof Error) return { name: value.name, message: value.message };
if (typeof value === 'object') {
if (depth >= 2) return '[object]';
const output = {};
for (const key of Object.keys(value).slice(0, 12)) {
const item = value[key];
output[key] = typeof item === 'function' ? '[function]' : summarizeDebugValue(item, depth + 1);
}
return output;
}
return String(value);
}
export function recordDebugTrace(step, details = {}) {
const targetState = window.__trackwhatDesktopCaptureState;
const entry = { at: new Date().toISOString(), step, details: summarizeDebugValue(details) };
if (!targetState) return entry;
targetState.debugTrace = targetState.debugTrace || [];
targetState.debugTrace.push(entry);
if (targetState.debugTrace.length > 60) {
targetState.debugTrace.splice(0, targetState.debugTrace.length - 60);
}
try { console.debug('[TrackWhat trace]', step, entry.details); } catch {}
return entry;
}