File size: 1,323 Bytes
9435b27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// @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;
}