@buoy-gg/console 7.0.20 → 7.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/commonjs/index.js +6 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/preset.js +25 -0
- package/lib/commonjs/preset.js.map +1 -1
- package/lib/commonjs/store/consoleLogStore.js +294 -1
- package/lib/commonjs/store/consoleLogStore.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/preset.js +27 -0
- package/lib/module/preset.js.map +1 -1
- package/lib/module/store/consoleLogStore.js +293 -1
- package/lib/module/store/consoleLogStore.js.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/preset.d.ts.map +1 -1
- package/lib/typescript/store/consoleLogStore.d.ts +26 -1
- package/lib/typescript/store/consoleLogStore.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +1 -0
- package/src/preset.tsx +32 -0
- package/src/store/consoleLogStore.ts +366 -1
|
@@ -52,6 +52,12 @@ export interface ConsoleLogEntry {
|
|
|
52
52
|
stack?: string;
|
|
53
53
|
/** Where the log came from (component / function / call site). */
|
|
54
54
|
origin?: LogOrigin;
|
|
55
|
+
/**
|
|
56
|
+
* True when this entry came from React Native's global error handler (an
|
|
57
|
+
* uncaught — usually fatal — JS error), not from a `console.*` call. The
|
|
58
|
+
* message carries a matching `[FATAL]` / `[UNCAUGHT]` prefix.
|
|
59
|
+
*/
|
|
60
|
+
fatal?: boolean;
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
/** Methods we intercept, in the order we install them. */
|
|
@@ -97,6 +103,13 @@ type Listener = () => void;
|
|
|
97
103
|
let entries: ConsoleLogEntry[] = [];
|
|
98
104
|
let nextId = 1;
|
|
99
105
|
let installed = false;
|
|
106
|
+
let fatalInstalled = false;
|
|
107
|
+
/**
|
|
108
|
+
* Raised by an explicit `uninstallConsoleCapture()`. The fatal-error hook can't
|
|
109
|
+
* be safely unwound once chained (another library may have chained on top of
|
|
110
|
+
* ours since), so an explicit user OFF mutes fatal recording instead.
|
|
111
|
+
*/
|
|
112
|
+
let captureDisabledByUser = false;
|
|
100
113
|
|
|
101
114
|
const listeners = new Set<Listener>();
|
|
102
115
|
const clearListeners = new Set<Listener>();
|
|
@@ -153,10 +166,87 @@ function captureOwnerStack(): string | undefined {
|
|
|
153
166
|
}
|
|
154
167
|
}
|
|
155
168
|
|
|
169
|
+
/**
|
|
170
|
+
* An error React Native decorated on its way through ExceptionsManager: a
|
|
171
|
+
* render/lifecycle crash carrying the component stack. `isComponentError` is
|
|
172
|
+
* set by RN's `getExtendedError`, so this identifies a REAL crash rather than
|
|
173
|
+
* an ordinary `console.error("...")` call.
|
|
174
|
+
*/
|
|
175
|
+
type ComponentError = Error & {
|
|
176
|
+
componentStack?: string;
|
|
177
|
+
isComponentError?: boolean;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/** Frames to keep from a component stack — the crash site plus its context. */
|
|
181
|
+
const COMPONENT_STACK_FRAMES = 8;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Squeeze a React component stack down to the part a human (or an agent
|
|
185
|
+
* reading this over a wire) actually uses: the component names nearest the
|
|
186
|
+
* crash.
|
|
187
|
+
*
|
|
188
|
+
* Raw component stacks in a Metro dev bundle append the full bundle URL with
|
|
189
|
+
* every query param to EVERY frame — one crash is ~15 KB of near-identical
|
|
190
|
+
* `http://192.168.x.x:8830/…&transform.routerRoot=src/app…` noise wrapped
|
|
191
|
+
* around the handful of names that matter. The complete error, componentStack
|
|
192
|
+
* included, is still on the entry's `args` for anyone who wants it.
|
|
193
|
+
*/
|
|
194
|
+
function compactComponentStack(stack: string): string {
|
|
195
|
+
const frames = stack
|
|
196
|
+
.split("\n")
|
|
197
|
+
.map((line) => line.trim())
|
|
198
|
+
.filter(Boolean)
|
|
199
|
+
// Drop the "(url)" tail; keep a "Name(./file.tsx)" hint when RN provides one.
|
|
200
|
+
.map((line) => line.replace(/\s*\((?:https?:|\/).*$/, ""));
|
|
201
|
+
const shown = frames.slice(0, COMPONENT_STACK_FRAMES);
|
|
202
|
+
const rest = frames.length - shown.length;
|
|
203
|
+
return (
|
|
204
|
+
shown.map((f) => ` ${f}`).join("\n") +
|
|
205
|
+
(rest > 0 ? `\n …+${rest} more frames` : "")
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
function asComponentError(arg: unknown): ComponentError | null {
|
|
209
|
+
if (!(arg instanceof Error)) return null;
|
|
210
|
+
const e = arg as ComponentError;
|
|
211
|
+
return e.isComponentError || typeof e.componentStack === "string" ? e : null;
|
|
212
|
+
}
|
|
213
|
+
|
|
156
214
|
function record(method: ConsoleMethod, args: unknown[]): void {
|
|
157
215
|
// Capture the call site for every log so we can attribute its origin.
|
|
158
216
|
const rawStack = new Error().stack;
|
|
159
217
|
const origin = parseOrigin(rawStack, captureOwnerStack());
|
|
218
|
+
|
|
219
|
+
// React Native funnels an uncaught render error back through console.error
|
|
220
|
+
// (ExceptionsManager.reportException) so console monkey-patches still see it.
|
|
221
|
+
// That arrives as an ordinary error row, which badly under-sells it: the app
|
|
222
|
+
// is dead. Promote it to a tagged [FATAL] entry carrying the component stack.
|
|
223
|
+
const crash = method === "error" ? asComponentError(args[0]) : null;
|
|
224
|
+
if (crash) {
|
|
225
|
+
// Tagged [RENDER ERROR], not [FATAL]: React reports an error an
|
|
226
|
+
// ErrorBoundary CAUGHT and recovered from through this same path, with the
|
|
227
|
+
// same componentStack, and nothing here distinguishes the two. Claiming a
|
|
228
|
+
// healthy app "most likely CRASHED" is worse than under-claiming — the
|
|
229
|
+
// component stack, which is the useful part, is reported either way.
|
|
230
|
+
const headline = fatalKey(crash.name, crash.message);
|
|
231
|
+
const located = crash.componentStack
|
|
232
|
+
? `\n\nThis error is located at:\n${compactComponentStack(crash.componentStack)}`
|
|
233
|
+
: "";
|
|
234
|
+
pushFatal(
|
|
235
|
+
{
|
|
236
|
+
id: nextId++,
|
|
237
|
+
method: "error",
|
|
238
|
+
level: "error",
|
|
239
|
+
args: ["[RENDER ERROR]", crash],
|
|
240
|
+
message: `[RENDER ERROR] ${headline}${located}`,
|
|
241
|
+
timestamp: Date.now(),
|
|
242
|
+
stack: crash.stack,
|
|
243
|
+
origin,
|
|
244
|
+
},
|
|
245
|
+
isDuplicateFatal(`[RENDER ERROR] ${headline}`)
|
|
246
|
+
);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
160
250
|
const entry: ConsoleLogEntry = {
|
|
161
251
|
id: nextId++,
|
|
162
252
|
method,
|
|
@@ -173,14 +263,287 @@ function record(method: ConsoleMethod, args: unknown[]): void {
|
|
|
173
263
|
: [...entries, entry];
|
|
174
264
|
emit();
|
|
175
265
|
scheduleSave();
|
|
266
|
+
// Errors are the entries most likely to be the last thing an app ever logs,
|
|
267
|
+
// so they get pushed to any dashboard immediately instead of waiting on the
|
|
268
|
+
// throttle that a dying tree will never run. Rate-limited; ordinary logs
|
|
269
|
+
// still ride the normal throttled path.
|
|
270
|
+
if (entry.level === "error") flushConsoleSyncNow();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Minimal shape of React Native's global `ErrorUtils`. */
|
|
274
|
+
interface RNErrorUtils {
|
|
275
|
+
getGlobalHandler?: () =>
|
|
276
|
+
| ((error: unknown, isFatal?: boolean) => void)
|
|
277
|
+
| undefined;
|
|
278
|
+
setGlobalHandler?: (
|
|
279
|
+
handler: (error: unknown, isFatal?: boolean) => void
|
|
280
|
+
) => void;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Two independent seams report the same crash on some setups (the C++ handler
|
|
285
|
+
* can also feed `console.error`). Suppress a repeat of the same headline within
|
|
286
|
+
* this window so a crash reads as ONE entry.
|
|
287
|
+
*/
|
|
288
|
+
const FATAL_DEDUPE_MS = 2000;
|
|
289
|
+
let lastFatalKey = "";
|
|
290
|
+
let lastFatalAt = 0;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Normalize a crash headline so the same error reported through two different
|
|
294
|
+
* seams produces the same key. React Native often sets `error.message` to the
|
|
295
|
+
* ALREADY-prefixed string ("TypeError: x is not a function"), so one path
|
|
296
|
+
* builds "TypeError: TypeError: x…" and the other "TypeError: x…" — which
|
|
297
|
+
* defeats the de-duplication entirely.
|
|
298
|
+
*/
|
|
299
|
+
function fatalKey(name: string | undefined, message: string): string {
|
|
300
|
+
const body = message.trim();
|
|
301
|
+
if (name && body.startsWith(`${name}: `)) return body;
|
|
302
|
+
return name ? `${name}: ${body}` : body;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Has this crash already been recorded moments ago?
|
|
307
|
+
*
|
|
308
|
+
* Only ever used to suppress a duplicate PUSH to the dashboard — never to drop
|
|
309
|
+
* an entry. Two different components crashing with the same message inside the
|
|
310
|
+
* window are two crashes, and a tool whose pitch is "the app's last words"
|
|
311
|
+
* must not silently throw one away.
|
|
312
|
+
*/
|
|
313
|
+
function isDuplicateFatal(key: string): boolean {
|
|
314
|
+
const now = Date.now();
|
|
315
|
+
if (key === lastFatalKey && now - lastFatalAt < FATAL_DEDUPE_MS) return true;
|
|
316
|
+
lastFatalKey = key;
|
|
317
|
+
lastFatalAt = now;
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* The device sync bridge's "push this tool NOW" escape hatch
|
|
323
|
+
* (@buoy-gg/external-sync `crashFlush`). Reached through the global rather than
|
|
324
|
+
* an import because console deliberately has no dependency on external-sync.
|
|
325
|
+
*/
|
|
326
|
+
let lastFlushAt = 0;
|
|
327
|
+
/** Floor between opportunistic flushes, so an error storm can't flood the socket. */
|
|
328
|
+
const FLUSH_MIN_INTERVAL_MS = 150;
|
|
329
|
+
const flushConsoleSyncNow = (force = false): void => {
|
|
330
|
+
const now = Date.now();
|
|
331
|
+
// A fatal is the app's last word — it always goes out, rate limit or not.
|
|
332
|
+
if (!force && now - lastFlushAt < FLUSH_MIN_INTERVAL_MS) return;
|
|
333
|
+
lastFlushAt = now;
|
|
334
|
+
try {
|
|
335
|
+
const set = (globalThis as { __buoyFlushToolSync?: Set<(toolId: string) => void> })
|
|
336
|
+
.__buoyFlushToolSync;
|
|
337
|
+
if (!set) return;
|
|
338
|
+
for (const flush of set) flush("console");
|
|
339
|
+
} catch {
|
|
340
|
+
// Best-effort: a crash path must never crash.
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Append a pre-built fatal entry to the ring buffer, then push it to any
|
|
346
|
+
* connected dashboard IMMEDIATELY.
|
|
347
|
+
*
|
|
348
|
+
* A fatal render error unmounts the React tree microseconds later, taking the
|
|
349
|
+
* sync bridge — and the normal 200 ms throttled snapshot — with it. Flushing
|
|
350
|
+
* synchronously here is what makes a crashed app's last words readable from
|
|
351
|
+
* the desktop app and the MCP server instead of the app just going silent.
|
|
352
|
+
*/
|
|
353
|
+
function pushFatal(entry: ConsoleLogEntry, duplicate = false): void {
|
|
354
|
+
entries =
|
|
355
|
+
entries.length >= MAX_ENTRIES
|
|
356
|
+
? [...entries.slice(entries.length - MAX_ENTRIES + 1), entry]
|
|
357
|
+
: [...entries, entry];
|
|
358
|
+
emit();
|
|
359
|
+
scheduleSave();
|
|
360
|
+
// A repeat within the dedupe window is still RECORDED (two crashes are two
|
|
361
|
+
// crashes); it just doesn't earn another forced push to the dashboard.
|
|
362
|
+
if (!duplicate) flushConsoleSyncNow(true);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** Record an uncaught JS error from the global handler as an error entry. */
|
|
366
|
+
function recordFatalError(error: unknown, isFatal?: boolean): void {
|
|
367
|
+
const err = error instanceof Error ? error : undefined;
|
|
368
|
+
// RN passes isFatal:false for non-fatal uncaught errors (e.g. errors thrown
|
|
369
|
+
// in event handlers on some setups); anything else is treated as fatal.
|
|
370
|
+
const label = isFatal === false ? "[UNCAUGHT]" : "[FATAL]";
|
|
371
|
+
const headline = err ? fatalKey(err.name, err.message) : formatArg(error);
|
|
372
|
+
const duplicate = isDuplicateFatal(`${label} ${headline}`);
|
|
373
|
+
// The label leads the args (not just the pre-rendered message): the
|
|
374
|
+
// DevTools-style row renders from args, so this is what makes the tag
|
|
375
|
+
// visible in the UI — exactly like `console.error("[FATAL]", err)`.
|
|
376
|
+
pushFatal(
|
|
377
|
+
{
|
|
378
|
+
id: nextId++,
|
|
379
|
+
method: "error",
|
|
380
|
+
level: "error",
|
|
381
|
+
args: [label, error],
|
|
382
|
+
message: `${label} ${headline}`,
|
|
383
|
+
timestamp: Date.now(),
|
|
384
|
+
// The error's OWN stack — the crash site, not this handler's call site.
|
|
385
|
+
stack: err?.stack,
|
|
386
|
+
fatal: true,
|
|
387
|
+
},
|
|
388
|
+
duplicate
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* The exception payload React Native's C++ error handler hands to listeners
|
|
394
|
+
* registered via `global.RN$registerExceptionListener` (JsErrorHandler.cpp).
|
|
395
|
+
*/
|
|
396
|
+
interface NativeExceptionData {
|
|
397
|
+
message?: string;
|
|
398
|
+
originalMessage?: string | null;
|
|
399
|
+
name?: string | null;
|
|
400
|
+
componentStack?: string | null;
|
|
401
|
+
stack?: Array<{
|
|
402
|
+
file?: string;
|
|
403
|
+
methodName?: string;
|
|
404
|
+
lineNumber?: number;
|
|
405
|
+
column?: number;
|
|
406
|
+
}>;
|
|
407
|
+
id?: number;
|
|
408
|
+
isFatal?: boolean;
|
|
409
|
+
isComponentError?: boolean;
|
|
410
|
+
extraData?: { rawStack?: string } & Record<string, unknown>;
|
|
411
|
+
/** Suppresses RN's own redbox. We never call it — we only observe. */
|
|
412
|
+
preventDefault?: () => unknown;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/** Render the C++ handler's parsed frames back into a normal stack string. */
|
|
416
|
+
function formatNativeStack(data: NativeExceptionData): string | undefined {
|
|
417
|
+
const raw = data.extraData?.rawStack;
|
|
418
|
+
if (typeof raw === "string" && raw.length > 0) return raw;
|
|
419
|
+
if (!Array.isArray(data.stack) || data.stack.length === 0) return undefined;
|
|
420
|
+
return data.stack
|
|
421
|
+
.map((f) => {
|
|
422
|
+
const where =
|
|
423
|
+
f.lineNumber != null ? `${f.file ?? "?"}:${f.lineNumber}:${f.column ?? 0}` : f.file ?? "?";
|
|
424
|
+
return ` at ${f.methodName || "<anonymous>"} (${where})`;
|
|
425
|
+
})
|
|
426
|
+
.join("\n");
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** Record a crash reported by React Native's native (C++) error handler. */
|
|
430
|
+
function recordNativeException(data: NativeExceptionData): void {
|
|
431
|
+
const label = data.isFatal === false ? "[UNCAUGHT]" : "[FATAL]";
|
|
432
|
+
const headline = fatalKey(data.name ?? undefined, data.originalMessage ?? data.message ?? "Unknown error");
|
|
433
|
+
const duplicate = isDuplicateFatal(`${label} ${headline}`);
|
|
434
|
+
// The component stack is the single most useful line for "which component
|
|
435
|
+
// crashed" — RN puts it in the redbox, so put it in the console entry too.
|
|
436
|
+
const componentStack =
|
|
437
|
+
typeof data.componentStack === "string" && data.componentStack.trim()
|
|
438
|
+
? `\n\nThis error is located at:\n${compactComponentStack(data.componentStack)}`
|
|
439
|
+
: "";
|
|
440
|
+
const message = `${label} ${headline}${componentStack}`;
|
|
441
|
+
pushFatal(
|
|
442
|
+
{
|
|
443
|
+
id: nextId++,
|
|
444
|
+
method: "error",
|
|
445
|
+
level: "error",
|
|
446
|
+
args: [label, headline, ...(componentStack ? [componentStack.trim()] : [])],
|
|
447
|
+
message,
|
|
448
|
+
timestamp: Date.now(),
|
|
449
|
+
stack: formatNativeStack(data),
|
|
450
|
+
fatal: true,
|
|
451
|
+
},
|
|
452
|
+
duplicate
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Register with React Native's native (C++) exception handler — the seam a
|
|
458
|
+
* RENDER crash actually travels through on the New Architecture.
|
|
459
|
+
*
|
|
460
|
+
* React 19 routes an uncaught render error to `onUncaughtError` →
|
|
461
|
+
* `ExceptionsManager.handleException`, which NEVER reaches
|
|
462
|
+
* `ErrorUtils.setGlobalHandler`. Where it goes from there depends on the build:
|
|
463
|
+
*
|
|
464
|
+
* - `useAlwaysAvailableJSErrorHandling` on: the C++ handler
|
|
465
|
+
* (`global.RN$handleException`) reports it and JS sees nothing — this
|
|
466
|
+
* listener is the only seam.
|
|
467
|
+
* - otherwise: JS `reportException` re-feeds `console.error(e)` "so any methods
|
|
468
|
+
* monkey patched on top of console.error are called", which the console patch
|
|
469
|
+
* catches and promotes to `[FATAL]` (see `record`).
|
|
470
|
+
*
|
|
471
|
+
* Both are covered, and a crash reported through both de-duplicates to one
|
|
472
|
+
* entry. `RN$registerExceptionListener` keeps a LIST of listeners (LogBox
|
|
473
|
+
* registers one too), so this is purely additive. We never call the payload's
|
|
474
|
+
* `preventDefault()`: suppressing RN's own redbox is not our call to make.
|
|
475
|
+
*/
|
|
476
|
+
function installNativeExceptionCapture(): boolean {
|
|
477
|
+
const register = (
|
|
478
|
+
globalThis as {
|
|
479
|
+
RN$registerExceptionListener?: (
|
|
480
|
+
listener: (data: NativeExceptionData) => void
|
|
481
|
+
) => void;
|
|
482
|
+
}
|
|
483
|
+
).RN$registerExceptionListener;
|
|
484
|
+
if (typeof register !== "function") return false;
|
|
485
|
+
register((data) => {
|
|
486
|
+
try {
|
|
487
|
+
if (!captureDisabledByUser) recordNativeException(data);
|
|
488
|
+
} catch {
|
|
489
|
+
// Capture must never interfere with error reporting.
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
return true;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Hook React Native's error paths so FATAL/uncaught JS errors land in the
|
|
497
|
+
* console store: the classic `ErrorUtils.setGlobalHandler` (old architecture,
|
|
498
|
+
* native-module callbacks, promise rejections) AND the native C++ exception
|
|
499
|
+
* listener (New Architecture render crashes — see
|
|
500
|
+
* {@link installNativeExceptionCapture}). Both feed the same de-duplicated
|
|
501
|
+
* `[FATAL]` entry, so a crash reported through both seams shows up once.
|
|
502
|
+
*
|
|
503
|
+
* - Chains the previous handler (LogBox/redbox still fire; nothing swallowed).
|
|
504
|
+
* - Idempotent, and a silent no-op off React Native (neither global present) —
|
|
505
|
+
* which also keeps it inert on the desktop dashboard / web mirrors.
|
|
506
|
+
* - Recording respects an explicit `uninstallConsoleCapture()` (user OFF), but
|
|
507
|
+
* the hooks themselves stay chained — they can't be safely removed.
|
|
508
|
+
*/
|
|
509
|
+
export function installFatalErrorCapture(): void {
|
|
510
|
+
if (fatalInstalled) return;
|
|
511
|
+
// Latch only once a seam is actually attached. Setting the flag up front
|
|
512
|
+
// means an install that runs before `InitializeCore` has published
|
|
513
|
+
// `ErrorUtils` would latch anyway and never retry — silently losing promise
|
|
514
|
+
// rejections and native-callback errors, which travel ONLY that seam.
|
|
515
|
+
const nativeInstalled = installNativeExceptionCapture();
|
|
516
|
+
const errorUtils = (globalThis as { ErrorUtils?: RNErrorUtils }).ErrorUtils;
|
|
517
|
+
if (typeof errorUtils?.setGlobalHandler !== "function") {
|
|
518
|
+
fatalInstalled = nativeInstalled;
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
fatalInstalled = true;
|
|
522
|
+
const previous =
|
|
523
|
+
typeof errorUtils.getGlobalHandler === "function"
|
|
524
|
+
? errorUtils.getGlobalHandler()
|
|
525
|
+
: undefined;
|
|
526
|
+
errorUtils.setGlobalHandler((error: unknown, isFatal?: boolean) => {
|
|
527
|
+
try {
|
|
528
|
+
if (!captureDisabledByUser) recordFatalError(error, isFatal);
|
|
529
|
+
} catch {
|
|
530
|
+
// Capture must never interfere with error reporting.
|
|
531
|
+
}
|
|
532
|
+
if (typeof previous === "function") previous(error, isFatal);
|
|
533
|
+
});
|
|
176
534
|
}
|
|
177
535
|
|
|
178
536
|
/**
|
|
179
537
|
* Patch the global console methods. Idempotent — safe to call more than once.
|
|
180
538
|
* Each patched method still forwards to the original so normal logging keeps
|
|
181
539
|
* working (Metro terminal, Chrome, native logcat/Xcode).
|
|
540
|
+
*
|
|
541
|
+
* Also installs the fatal-error hook (see `installFatalErrorCapture`) so every
|
|
542
|
+
* install path captures crashes, not just `console.*` calls.
|
|
182
543
|
*/
|
|
183
544
|
export function installConsoleCapture(): void {
|
|
545
|
+
captureDisabledByUser = false;
|
|
546
|
+
installFatalErrorCapture();
|
|
184
547
|
if (installed) return;
|
|
185
548
|
installed = true;
|
|
186
549
|
|
|
@@ -198,8 +561,10 @@ export function installConsoleCapture(): void {
|
|
|
198
561
|
}
|
|
199
562
|
}
|
|
200
563
|
|
|
201
|
-
/** Restore the original console methods.
|
|
564
|
+
/** Restore the original console methods. Also mutes fatal-error recording
|
|
565
|
+
* (the hook itself stays chained — see `installFatalErrorCapture`). */
|
|
202
566
|
export function uninstallConsoleCapture(): void {
|
|
567
|
+
captureDisabledByUser = true;
|
|
203
568
|
if (!installed) return;
|
|
204
569
|
installed = false;
|
|
205
570
|
for (const method of METHODS) {
|