@buoy-gg/console 7.0.40 → 7.0.42
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 +11 -65
- package/lib/commonjs/components/ConsoleIcon.js +1 -19
- package/lib/commonjs/components/ConsoleLogList.js +1 -152
- package/lib/commonjs/components/ConsoleModal.js +1 -48
- package/lib/commonjs/components/ConsoleRoot.js +1 -37
- package/lib/commonjs/devtools/ConsoleBody.js +1 -234
- package/lib/commonjs/devtools/ConsoleHeader.js +1 -114
- package/lib/commonjs/devtools/ConsoleMessageRow.js +1 -356
- package/lib/commonjs/devtools/ConsoleValue.js +1 -254
- package/lib/commonjs/devtools/ConsoleView.js +1 -54
- package/lib/commonjs/devtools/consoleFilter.js +1 -125
- package/lib/commonjs/devtools/consoleFormat.js +1 -313
- package/lib/commonjs/devtools/origin.js +1 -191
- package/lib/commonjs/devtools/theme.js +1 -152
- package/lib/commonjs/devtools/useConsoleController.js +1 -82
- package/lib/commonjs/devtools/useConsoleMessages.js +1 -241
- package/lib/commonjs/hooks/useConsoleLogs.js +1 -23
- package/lib/commonjs/index.js +1 -181
- package/lib/commonjs/preset.js +1 -63
- package/lib/commonjs/store/consoleLogStore.js +6 -587
- package/lib/commonjs/store/sanitize.js +1 -83
- package/lib/commonjs/sync/consoleSyncAdapter.js +1 -86
- package/lib/module/components/ConsoleIcon.js +1 -12
- package/lib/module/components/ConsoleLogList.js +1 -147
- package/lib/module/components/ConsoleModal.js +1 -44
- package/lib/module/components/ConsoleRoot.js +1 -33
- package/lib/module/devtools/ConsoleBody.js +1 -229
- package/lib/module/devtools/ConsoleHeader.js +1 -109
- package/lib/module/devtools/ConsoleMessageRow.js +1 -352
- package/lib/module/devtools/ConsoleValue.js +1 -249
- package/lib/module/devtools/ConsoleView.js +1 -49
- package/lib/module/devtools/consoleFilter.js +1 -119
- package/lib/module/devtools/consoleFormat.js +1 -309
- package/lib/module/devtools/origin.js +1 -183
- package/lib/module/devtools/theme.js +1 -143
- package/lib/module/devtools/useConsoleController.js +1 -79
- package/lib/module/devtools/useConsoleMessages.js +1 -238
- package/lib/module/hooks/useConsoleLogs.js +1 -19
- package/lib/module/index.js +1 -52
- package/lib/module/preset.js +1 -61
- package/lib/module/store/consoleLogStore.js +6 -573
- package/lib/module/store/sanitize.js +1 -77
- package/lib/module/sync/consoleSyncAdapter.js +1 -82
- package/lib/web/index.mjs +17 -0
- package/package.json +39 -5
- package/lib/commonjs/components/ConsoleIcon.js.map +0 -1
- package/lib/commonjs/components/ConsoleLogList.js.map +0 -1
- package/lib/commonjs/components/ConsoleModal.js.map +0 -1
- package/lib/commonjs/components/ConsoleRoot.js.map +0 -1
- package/lib/commonjs/devtools/ConsoleBody.js.map +0 -1
- package/lib/commonjs/devtools/ConsoleHeader.js.map +0 -1
- package/lib/commonjs/devtools/ConsoleMessageRow.js.map +0 -1
- package/lib/commonjs/devtools/ConsoleValue.js.map +0 -1
- package/lib/commonjs/devtools/ConsoleView.js.map +0 -1
- package/lib/commonjs/devtools/consoleFilter.js.map +0 -1
- package/lib/commonjs/devtools/consoleFormat.js.map +0 -1
- package/lib/commonjs/devtools/origin.js.map +0 -1
- package/lib/commonjs/devtools/theme.js.map +0 -1
- package/lib/commonjs/devtools/useConsoleController.js.map +0 -1
- package/lib/commonjs/devtools/useConsoleMessages.js.map +0 -1
- package/lib/commonjs/hooks/useConsoleLogs.js.map +0 -1
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/preset.js.map +0 -1
- package/lib/commonjs/store/consoleLogStore.js.map +0 -1
- package/lib/commonjs/store/sanitize.js.map +0 -1
- package/lib/commonjs/sync/consoleSyncAdapter.js.map +0 -1
- package/lib/module/components/ConsoleIcon.js.map +0 -1
- package/lib/module/components/ConsoleLogList.js.map +0 -1
- package/lib/module/components/ConsoleModal.js.map +0 -1
- package/lib/module/components/ConsoleRoot.js.map +0 -1
- package/lib/module/devtools/ConsoleBody.js.map +0 -1
- package/lib/module/devtools/ConsoleHeader.js.map +0 -1
- package/lib/module/devtools/ConsoleMessageRow.js.map +0 -1
- package/lib/module/devtools/ConsoleValue.js.map +0 -1
- package/lib/module/devtools/ConsoleView.js.map +0 -1
- package/lib/module/devtools/consoleFilter.js.map +0 -1
- package/lib/module/devtools/consoleFormat.js.map +0 -1
- package/lib/module/devtools/origin.js.map +0 -1
- package/lib/module/devtools/theme.js.map +0 -1
- package/lib/module/devtools/useConsoleController.js.map +0 -1
- package/lib/module/devtools/useConsoleMessages.js.map +0 -1
- package/lib/module/hooks/useConsoleLogs.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/preset.js.map +0 -1
- package/lib/module/store/consoleLogStore.js.map +0 -1
- package/lib/module/store/sanitize.js.map +0 -1
- package/lib/module/sync/consoleSyncAdapter.js.map +0 -1
- package/lib/typescript/components/ConsoleIcon.d.ts.map +0 -1
- package/lib/typescript/components/ConsoleLogList.d.ts.map +0 -1
- package/lib/typescript/components/ConsoleModal.d.ts.map +0 -1
- package/lib/typescript/components/ConsoleRoot.d.ts.map +0 -1
- package/lib/typescript/devtools/ConsoleBody.d.ts.map +0 -1
- package/lib/typescript/devtools/ConsoleHeader.d.ts.map +0 -1
- package/lib/typescript/devtools/ConsoleMessageRow.d.ts.map +0 -1
- package/lib/typescript/devtools/ConsoleValue.d.ts.map +0 -1
- package/lib/typescript/devtools/ConsoleView.d.ts.map +0 -1
- package/lib/typescript/devtools/consoleFilter.d.ts.map +0 -1
- package/lib/typescript/devtools/consoleFormat.d.ts.map +0 -1
- package/lib/typescript/devtools/origin.d.ts.map +0 -1
- package/lib/typescript/devtools/theme.d.ts.map +0 -1
- package/lib/typescript/devtools/useConsoleController.d.ts.map +0 -1
- package/lib/typescript/devtools/useConsoleMessages.d.ts.map +0 -1
- package/lib/typescript/hooks/useConsoleLogs.d.ts.map +0 -1
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/preset.d.ts.map +0 -1
- package/lib/typescript/store/consoleLogStore.d.ts.map +0 -1
- package/lib/typescript/store/sanitize.d.ts.map +0 -1
- package/lib/typescript/sync/consoleSyncAdapter.d.ts.map +0 -1
|
@@ -1,589 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.clearEntries=clearEntries;exports.getEntries=getEntries;exports.getPreserveLog=getPreserveLog;exports.initConsolePersistence=initConsolePersistence;exports.installConsoleCapture=installConsoleCapture;exports.installFatalErrorCapture=installFatalErrorCapture;exports.onClear=onClear;exports.replaceEntries=replaceEntries;exports.setPreserveLog=setPreserveLog;exports.subscribe=subscribe;exports.subscribePreserveLog=subscribePreserveLog;exports.uninstallConsoleCapture=uninstallConsoleCapture;var _sharedUi=require("@buoy-gg/shared-ui");var React=_interopRequireWildcard(require("react"));var _sanitize=require("./sanitize");var _origin=require("../devtools/origin");function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var n=new WeakMap,o=new WeakMap;return(_interopRequireWildcard=function(r,s){if(!s&&r&&r.__esModule)return r;var i,a,l={__proto__:null,default:r};if(null===r||"object"!=typeof r&&"function"!=typeof r)return l;if(i=s?o:n){if(i.has(r))return i.get(r);i.set(r,l)}for(const c in r)"default"!==c&&{}.hasOwnProperty.call(r,c)&&((a=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(r,c))&&(a.get||a.set)?i(l,c,a):l[c]=r[c]);return l})(e,t)}const METHODS=["log","info","warn","error","debug","trace","dir","table","assert","group","groupCollapsed","groupEnd"];const STACK_METHODS=new Set(["error","warn","trace","assert"]);const METHOD_LEVEL={error:"error",assert:"error",warn:"warning",debug:"verbose",log:"info",info:"info",trace:"info",dir:"info",table:"info",group:"info",groupCollapsed:"info",groupEnd:"info"};const MAX_ENTRIES=1e3;const store=(0,_sharedUi.createToolStore)({id:"console",max:MAX_ENTRIES,order:"append",coalesce:"frame"});let installed=false;let fatalInstalled=false;let captureDisabledByUser=false;const originals={};function formatArg(e){if(typeof e==="string")return e;if(e instanceof Error)return e.stack??`${e.name}: ${e.message}`;if(e===void 0)return"undefined";if(e===null)return"null";if(typeof e==="function")return`\u0192 ${e.name||"(anonymous)"}`;try{return JSON.stringify(e)}catch{return String(e)}}function formatArgs(e){return e.map(formatArg).join(" ")}function cleanStack(e){if(!e)return void 0;return e.split("\n").slice(3).join("\n")||void 0}function captureOwnerStack(){try{const e=Reflect.get(React,"captureOwnerStack");return typeof e==="function"?e()??void 0:void 0}catch{return void 0}}const COMPONENT_STACK_FRAMES=8;function compactComponentStack(e){const t=e.split("\n").map(r=>r.trim()).filter(Boolean).map(r=>r.replace(/\s*\((?:https?:|\/).*$/,""));const n=t.slice(0,COMPONENT_STACK_FRAMES);const o=t.length-n.length;return n.map(r=>` ${r}`).join("\n")+(o>0?`
|
|
2
|
+
\u2026+${o} more frames`:"")}function asComponentError(e){if(!(e instanceof Error))return null;const t=e;return t.isComponentError||typeof t.componentStack==="string"?t:null}function record(e,t){const n=new Error().stack;const o=(0,_origin.parseOrigin)(n,captureOwnerStack());const r=e==="error"?asComponentError(t[0]):null;if(r){const i=fatalKey(r.name,r.message);const a=r.componentStack?`
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.clearEntries = clearEntries;
|
|
7
|
-
exports.getEntries = getEntries;
|
|
8
|
-
exports.getPreserveLog = getPreserveLog;
|
|
9
|
-
exports.initConsolePersistence = initConsolePersistence;
|
|
10
|
-
exports.installConsoleCapture = installConsoleCapture;
|
|
11
|
-
exports.installFatalErrorCapture = installFatalErrorCapture;
|
|
12
|
-
exports.onClear = onClear;
|
|
13
|
-
exports.replaceEntries = replaceEntries;
|
|
14
|
-
exports.setPreserveLog = setPreserveLog;
|
|
15
|
-
exports.subscribe = subscribe;
|
|
16
|
-
exports.subscribePreserveLog = subscribePreserveLog;
|
|
17
|
-
exports.uninstallConsoleCapture = uninstallConsoleCapture;
|
|
18
|
-
var _sharedUi = require("@buoy-gg/shared-ui");
|
|
19
|
-
var React = _interopRequireWildcard(require("react"));
|
|
20
|
-
var _sanitize = require("./sanitize");
|
|
21
|
-
var _origin = require("../devtools/origin");
|
|
22
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
23
|
-
/**
|
|
24
|
-
* consoleLogStore
|
|
25
|
-
*
|
|
26
|
-
* Intercepts the global `console` methods and keeps a bounded ring buffer of
|
|
27
|
-
* captured entries, modeled after Chrome DevTools' ConsoleMessage. Direct
|
|
28
|
-
* console patching is the capture path (works identically on Expo, RN CLI, and
|
|
29
|
-
* web). The DevTools-style view layer (filtering, formatting, grouping) is built
|
|
30
|
-
* on top of these raw entries.
|
|
31
|
-
*
|
|
32
|
-
* By default the buffer is in-memory only, so a JS reload starts fresh — just
|
|
33
|
-
* like the Metro/Chrome console. A "Preserve log" toggle persists the buffer to
|
|
34
|
-
* storage and restores it on the next launch (Chrome's "Preserve log").
|
|
35
|
-
*/
|
|
4
|
+
This error is located at:
|
|
5
|
+
${compactComponentStack(r.componentStack)}`:"";pushFatal({id:store.allocId(),method:"error",level:"error",args:["[RENDER ERROR]",r],message:`[RENDER ERROR] ${i}${a}`,timestamp:Date.now(),stack:r.stack,origin:o},isDuplicateFatal(`[RENDER ERROR] ${i}`));return}const s={id:store.allocId(),method:e,level:METHOD_LEVEL[e],args:t,message:formatArgs(t),timestamp:Date.now(),stack:STACK_METHODS.has(e)?cleanStack(n):void 0,origin:o};store.add(s);scheduleSave();if(s.level==="error")store.flushSync()}const FATAL_DEDUPE_MS=2e3;let lastFatalKey="";let lastFatalAt=0;function fatalKey(e,t){const n=t.trim();if(e&&n.startsWith(`${e}: `))return n;return e?`${e}: ${n}`:n}function isDuplicateFatal(e){const t=Date.now();if(e===lastFatalKey&&t-lastFatalAt<FATAL_DEDUPE_MS)return true;lastFatalKey=e;lastFatalAt=t;return false}function pushFatal(e,t=false){store.add(e);scheduleSave();if(!t)store.flushSync(true)}function recordFatalError(e,t){const n=e instanceof Error?e:void 0;const o=t===false?"[UNCAUGHT]":"[FATAL]";const r=n?fatalKey(n.name,n.message):formatArg(e);const s=isDuplicateFatal(`${o} ${r}`);pushFatal({id:store.allocId(),method:"error",level:"error",args:[o,e],message:`${o} ${r}`,timestamp:Date.now(),stack:n?.stack,fatal:true},s)}function formatNativeStack(e){const t=e.extraData?.rawStack;if(typeof t==="string"&&t.length>0)return t;if(!Array.isArray(e.stack)||e.stack.length===0)return void 0;return e.stack.map(n=>{const o=n.lineNumber!=null?`${n.file??"?"}:${n.lineNumber}:${n.column??0}`:n.file??"?";return` at ${n.methodName||"<anonymous>"} (${o})`}).join("\n")}function recordNativeException(e){const t=e.isFatal===false?"[UNCAUGHT]":"[FATAL]";const n=fatalKey(e.name??void 0,e.originalMessage??e.message??"Unknown error");const o=isDuplicateFatal(`${t} ${n}`);const r=typeof e.componentStack==="string"&&e.componentStack.trim()?`
|
|
36
6
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
/** DevTools log levels (Protocol.Log.LogEntryLevel). */
|
|
40
|
-
|
|
41
|
-
/** Methods we intercept, in the order we install them. */
|
|
42
|
-
const METHODS = ["log", "info", "warn", "error", "debug", "trace", "dir", "table", "assert", "group", "groupCollapsed", "groupEnd"];
|
|
43
|
-
|
|
44
|
-
/** Methods whose call site we capture a stack for. */
|
|
45
|
-
const STACK_METHODS = new Set(["error", "warn", "trace", "assert"]);
|
|
46
|
-
|
|
47
|
-
/** method → DevTools level. */
|
|
48
|
-
const METHOD_LEVEL = {
|
|
49
|
-
error: "error",
|
|
50
|
-
assert: "error",
|
|
51
|
-
warn: "warning",
|
|
52
|
-
debug: "verbose",
|
|
53
|
-
log: "info",
|
|
54
|
-
info: "info",
|
|
55
|
-
trace: "info",
|
|
56
|
-
dir: "info",
|
|
57
|
-
table: "info",
|
|
58
|
-
group: "info",
|
|
59
|
-
groupCollapsed: "info",
|
|
60
|
-
groupEnd: "info"
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/** Max entries retained before the oldest are dropped. */
|
|
64
|
-
const MAX_ENTRIES = 1000;
|
|
65
|
-
// Frame-coalesced emit: console traffic is inherently bursty (loops,
|
|
66
|
-
// per-frame logs), and uncoalesced each entry was its own React commit —
|
|
67
|
-
// the console tool measured 41 JS FPS / 84% CPU / 7 jank during a bench
|
|
68
|
-
// dwell (tool-bench 2026-07-06) largely from its own live churn. The buffer,
|
|
69
|
-
// listeners, clear-forwarding and the "push to the dashboard NOW" hook are
|
|
70
|
-
// the shared `createToolStore`; this module adds capture + persistence.
|
|
71
|
-
const store = (0, _sharedUi.createToolStore)({
|
|
72
|
-
id: "console",
|
|
73
|
-
max: MAX_ENTRIES,
|
|
74
|
-
order: "append",
|
|
75
|
-
coalesce: "frame"
|
|
76
|
-
});
|
|
77
|
-
let installed = false;
|
|
78
|
-
let fatalInstalled = false;
|
|
79
|
-
/**
|
|
80
|
-
* Raised by an explicit `uninstallConsoleCapture()`. The fatal-error hook can't
|
|
81
|
-
* be safely unwound once chained (another library may have chained on top of
|
|
82
|
-
* ours since), so an explicit user OFF mutes fatal recording instead.
|
|
83
|
-
*/
|
|
84
|
-
let captureDisabledByUser = false;
|
|
85
|
-
|
|
86
|
-
/** Saved originals so we can restore on uninstall and still print through. */
|
|
87
|
-
const originals = {};
|
|
88
|
-
|
|
89
|
-
/** Best-effort, single-line serialization of a single console argument. */
|
|
90
|
-
function formatArg(arg) {
|
|
91
|
-
if (typeof arg === "string") return arg;
|
|
92
|
-
if (arg instanceof Error) return arg.stack ?? `${arg.name}: ${arg.message}`;
|
|
93
|
-
if (arg === undefined) return "undefined";
|
|
94
|
-
if (arg === null) return "null";
|
|
95
|
-
if (typeof arg === "function") return `ƒ ${arg.name || "(anonymous)"}`;
|
|
96
|
-
try {
|
|
97
|
-
return JSON.stringify(arg);
|
|
98
|
-
} catch {
|
|
99
|
-
return String(arg);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function formatArgs(args) {
|
|
103
|
-
return args.map(formatArg).join(" ");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/** Drop the "Error" header + the interceptor's own frames from a raw stack. */
|
|
107
|
-
function cleanStack(raw) {
|
|
108
|
-
if (!raw) return undefined;
|
|
109
|
-
return raw.split("\n").slice(3).join("\n") || undefined;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Nearest owning React component stack (dev only; empty off-render). */
|
|
113
|
-
function captureOwnerStack() {
|
|
114
|
-
try {
|
|
115
|
-
const fn = React.captureOwnerStack;
|
|
116
|
-
return typeof fn === "function" ? fn() ?? undefined : undefined;
|
|
117
|
-
} catch {
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* An error React Native decorated on its way through ExceptionsManager: a
|
|
124
|
-
* render/lifecycle crash carrying the component stack. `isComponentError` is
|
|
125
|
-
* set by RN's `getExtendedError`, so this identifies a REAL crash rather than
|
|
126
|
-
* an ordinary `console.error("...")` call.
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
|
-
/** Frames to keep from a component stack — the crash site plus its context. */
|
|
130
|
-
const COMPONENT_STACK_FRAMES = 8;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Squeeze a React component stack down to the part a human (or an agent
|
|
134
|
-
* reading this over a wire) actually uses: the component names nearest the
|
|
135
|
-
* crash.
|
|
136
|
-
*
|
|
137
|
-
* Raw component stacks in a Metro dev bundle append the full bundle URL with
|
|
138
|
-
* every query param to EVERY frame — one crash is ~15 KB of near-identical
|
|
139
|
-
* `http://192.168.x.x:8830/…&transform.routerRoot=src/app…` noise wrapped
|
|
140
|
-
* around the handful of names that matter. The complete error, componentStack
|
|
141
|
-
* included, is still on the entry's `args` for anyone who wants it.
|
|
142
|
-
*/
|
|
143
|
-
function compactComponentStack(stack) {
|
|
144
|
-
const frames = stack.split("\n").map(line => line.trim()).filter(Boolean)
|
|
145
|
-
// Drop the "(url)" tail; keep a "Name(./file.tsx)" hint when RN provides one.
|
|
146
|
-
.map(line => line.replace(/\s*\((?:https?:|\/).*$/, ""));
|
|
147
|
-
const shown = frames.slice(0, COMPONENT_STACK_FRAMES);
|
|
148
|
-
const rest = frames.length - shown.length;
|
|
149
|
-
return shown.map(f => ` ${f}`).join("\n") + (rest > 0 ? `\n …+${rest} more frames` : "");
|
|
150
|
-
}
|
|
151
|
-
function asComponentError(arg) {
|
|
152
|
-
if (!(arg instanceof Error)) return null;
|
|
153
|
-
const e = arg;
|
|
154
|
-
return e.isComponentError || typeof e.componentStack === "string" ? e : null;
|
|
155
|
-
}
|
|
156
|
-
function record(method, args) {
|
|
157
|
-
// Capture the call site for every log so we can attribute its origin.
|
|
158
|
-
const rawStack = new Error().stack;
|
|
159
|
-
const origin = (0, _origin.parseOrigin)(rawStack, captureOwnerStack());
|
|
160
|
-
|
|
161
|
-
// React Native funnels an uncaught render error back through console.error
|
|
162
|
-
// (ExceptionsManager.reportException) so console monkey-patches still see it.
|
|
163
|
-
// That arrives as an ordinary error row, which badly under-sells it: the app
|
|
164
|
-
// is dead. Promote it to a tagged [FATAL] entry carrying the component stack.
|
|
165
|
-
const crash = method === "error" ? asComponentError(args[0]) : null;
|
|
166
|
-
if (crash) {
|
|
167
|
-
// Tagged [RENDER ERROR], not [FATAL]: React reports an error an
|
|
168
|
-
// ErrorBoundary CAUGHT and recovered from through this same path, with the
|
|
169
|
-
// same componentStack, and nothing here distinguishes the two. Claiming a
|
|
170
|
-
// healthy app "most likely CRASHED" is worse than under-claiming — the
|
|
171
|
-
// component stack, which is the useful part, is reported either way.
|
|
172
|
-
const headline = fatalKey(crash.name, crash.message);
|
|
173
|
-
const located = crash.componentStack ? `\n\nThis error is located at:\n${compactComponentStack(crash.componentStack)}` : "";
|
|
174
|
-
pushFatal({
|
|
175
|
-
id: store.allocId(),
|
|
176
|
-
method: "error",
|
|
177
|
-
level: "error",
|
|
178
|
-
args: ["[RENDER ERROR]", crash],
|
|
179
|
-
message: `[RENDER ERROR] ${headline}${located}`,
|
|
180
|
-
timestamp: Date.now(),
|
|
181
|
-
stack: crash.stack,
|
|
182
|
-
origin
|
|
183
|
-
}, isDuplicateFatal(`[RENDER ERROR] ${headline}`));
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const entry = {
|
|
187
|
-
id: store.allocId(),
|
|
188
|
-
method,
|
|
189
|
-
level: METHOD_LEVEL[method],
|
|
190
|
-
args,
|
|
191
|
-
message: formatArgs(args),
|
|
192
|
-
timestamp: Date.now(),
|
|
193
|
-
stack: STACK_METHODS.has(method) ? cleanStack(rawStack) : undefined,
|
|
194
|
-
origin
|
|
195
|
-
};
|
|
196
|
-
store.add(entry);
|
|
197
|
-
scheduleSave();
|
|
198
|
-
// Errors are the entries most likely to be the last thing an app ever logs,
|
|
199
|
-
// so they get pushed to any dashboard immediately instead of waiting on the
|
|
200
|
-
// throttle that a dying tree will never run. Rate-limited; ordinary logs
|
|
201
|
-
// still ride the normal throttled path.
|
|
202
|
-
if (entry.level === "error") store.flushSync();
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/** Minimal shape of React Native's global `ErrorUtils`. */
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Two independent seams report the same crash on some setups (the C++ handler
|
|
209
|
-
* can also feed `console.error`). Suppress a repeat of the same headline within
|
|
210
|
-
* this window so a crash reads as ONE entry.
|
|
211
|
-
*/
|
|
212
|
-
const FATAL_DEDUPE_MS = 2000;
|
|
213
|
-
let lastFatalKey = "";
|
|
214
|
-
let lastFatalAt = 0;
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Normalize a crash headline so the same error reported through two different
|
|
218
|
-
* seams produces the same key. React Native often sets `error.message` to the
|
|
219
|
-
* ALREADY-prefixed string ("TypeError: x is not a function"), so one path
|
|
220
|
-
* builds "TypeError: TypeError: x…" and the other "TypeError: x…" — which
|
|
221
|
-
* defeats the de-duplication entirely.
|
|
222
|
-
*/
|
|
223
|
-
function fatalKey(name, message) {
|
|
224
|
-
const body = message.trim();
|
|
225
|
-
if (name && body.startsWith(`${name}: `)) return body;
|
|
226
|
-
return name ? `${name}: ${body}` : body;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Has this crash already been recorded moments ago?
|
|
231
|
-
*
|
|
232
|
-
* Only ever used to suppress a duplicate PUSH to the dashboard — never to drop
|
|
233
|
-
* an entry. Two different components crashing with the same message inside the
|
|
234
|
-
* window are two crashes, and a tool whose pitch is "the app's last words"
|
|
235
|
-
* must not silently throw one away.
|
|
236
|
-
*/
|
|
237
|
-
function isDuplicateFatal(key) {
|
|
238
|
-
const now = Date.now();
|
|
239
|
-
if (key === lastFatalKey && now - lastFatalAt < FATAL_DEDUPE_MS) return true;
|
|
240
|
-
lastFatalKey = key;
|
|
241
|
-
lastFatalAt = now;
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* The device sync bridge's "push this tool NOW" escape hatch
|
|
247
|
-
* (@buoy-gg/external-sync `crashFlush`). Reached through the global rather than
|
|
248
|
-
* an import because console deliberately has no dependency on external-sync.
|
|
249
|
-
*/
|
|
250
|
-
// The flush itself lives on the shared store (`store.flushSync`): rate-limited
|
|
251
|
-
// unless forced — a fatal is the app's last word and always goes out.
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Append a pre-built fatal entry to the ring buffer, then push it to any
|
|
255
|
-
* connected dashboard IMMEDIATELY.
|
|
256
|
-
*
|
|
257
|
-
* A fatal render error unmounts the React tree microseconds later, taking the
|
|
258
|
-
* sync bridge — and the normal 200 ms throttled snapshot — with it. Flushing
|
|
259
|
-
* synchronously here is what makes a crashed app's last words readable from
|
|
260
|
-
* the desktop app and the MCP server instead of the app just going silent.
|
|
261
|
-
*/
|
|
262
|
-
function pushFatal(entry, duplicate = false) {
|
|
263
|
-
store.add(entry);
|
|
264
|
-
scheduleSave();
|
|
265
|
-
// A repeat within the dedupe window is still RECORDED (two crashes are two
|
|
266
|
-
// crashes); it just doesn't earn another forced push to the dashboard.
|
|
267
|
-
if (!duplicate) store.flushSync(true);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/** Record an uncaught JS error from the global handler as an error entry. */
|
|
271
|
-
function recordFatalError(error, isFatal) {
|
|
272
|
-
const err = error instanceof Error ? error : undefined;
|
|
273
|
-
// RN passes isFatal:false for non-fatal uncaught errors (e.g. errors thrown
|
|
274
|
-
// in event handlers on some setups); anything else is treated as fatal.
|
|
275
|
-
const label = isFatal === false ? "[UNCAUGHT]" : "[FATAL]";
|
|
276
|
-
const headline = err ? fatalKey(err.name, err.message) : formatArg(error);
|
|
277
|
-
const duplicate = isDuplicateFatal(`${label} ${headline}`);
|
|
278
|
-
// The label leads the args (not just the pre-rendered message): the
|
|
279
|
-
// DevTools-style row renders from args, so this is what makes the tag
|
|
280
|
-
// visible in the UI — exactly like `console.error("[FATAL]", err)`.
|
|
281
|
-
pushFatal({
|
|
282
|
-
id: store.allocId(),
|
|
283
|
-
method: "error",
|
|
284
|
-
level: "error",
|
|
285
|
-
args: [label, error],
|
|
286
|
-
message: `${label} ${headline}`,
|
|
287
|
-
timestamp: Date.now(),
|
|
288
|
-
// The error's OWN stack — the crash site, not this handler's call site.
|
|
289
|
-
stack: err?.stack,
|
|
290
|
-
fatal: true
|
|
291
|
-
}, duplicate);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* The exception payload React Native's C++ error handler hands to listeners
|
|
296
|
-
* registered via `global.RN$registerExceptionListener` (JsErrorHandler.cpp).
|
|
297
|
-
*/
|
|
298
|
-
|
|
299
|
-
/** Render the C++ handler's parsed frames back into a normal stack string. */
|
|
300
|
-
function formatNativeStack(data) {
|
|
301
|
-
const raw = data.extraData?.rawStack;
|
|
302
|
-
if (typeof raw === "string" && raw.length > 0) return raw;
|
|
303
|
-
if (!Array.isArray(data.stack) || data.stack.length === 0) return undefined;
|
|
304
|
-
return data.stack.map(f => {
|
|
305
|
-
const where = f.lineNumber != null ? `${f.file ?? "?"}:${f.lineNumber}:${f.column ?? 0}` : f.file ?? "?";
|
|
306
|
-
return ` at ${f.methodName || "<anonymous>"} (${where})`;
|
|
307
|
-
}).join("\n");
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/** Record a crash reported by React Native's native (C++) error handler. */
|
|
311
|
-
function recordNativeException(data) {
|
|
312
|
-
const label = data.isFatal === false ? "[UNCAUGHT]" : "[FATAL]";
|
|
313
|
-
const headline = fatalKey(data.name ?? undefined, data.originalMessage ?? data.message ?? "Unknown error");
|
|
314
|
-
const duplicate = isDuplicateFatal(`${label} ${headline}`);
|
|
315
|
-
// The component stack is the single most useful line for "which component
|
|
316
|
-
// crashed" — RN puts it in the redbox, so put it in the console entry too.
|
|
317
|
-
const componentStack = typeof data.componentStack === "string" && data.componentStack.trim() ? `\n\nThis error is located at:\n${compactComponentStack(data.componentStack)}` : "";
|
|
318
|
-
const message = `${label} ${headline}${componentStack}`;
|
|
319
|
-
pushFatal({
|
|
320
|
-
id: store.allocId(),
|
|
321
|
-
method: "error",
|
|
322
|
-
level: "error",
|
|
323
|
-
args: [label, headline, ...(componentStack ? [componentStack.trim()] : [])],
|
|
324
|
-
message,
|
|
325
|
-
timestamp: Date.now(),
|
|
326
|
-
stack: formatNativeStack(data),
|
|
327
|
-
fatal: true
|
|
328
|
-
}, duplicate);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Register with React Native's native (C++) exception handler — the seam a
|
|
333
|
-
* RENDER crash actually travels through on the New Architecture.
|
|
334
|
-
*
|
|
335
|
-
* React 19 routes an uncaught render error to `onUncaughtError` →
|
|
336
|
-
* `ExceptionsManager.handleException`, which NEVER reaches
|
|
337
|
-
* `ErrorUtils.setGlobalHandler`. Where it goes from there depends on the build:
|
|
338
|
-
*
|
|
339
|
-
* - `useAlwaysAvailableJSErrorHandling` on: the C++ handler
|
|
340
|
-
* (`global.RN$handleException`) reports it and JS sees nothing — this
|
|
341
|
-
* listener is the only seam.
|
|
342
|
-
* - otherwise: JS `reportException` re-feeds `console.error(e)` "so any methods
|
|
343
|
-
* monkey patched on top of console.error are called", which the console patch
|
|
344
|
-
* catches and promotes to `[FATAL]` (see `record`).
|
|
345
|
-
*
|
|
346
|
-
* Both are covered, and a crash reported through both de-duplicates to one
|
|
347
|
-
* entry. `RN$registerExceptionListener` keeps a LIST of listeners (LogBox
|
|
348
|
-
* registers one too), so this is purely additive. We never call the payload's
|
|
349
|
-
* `preventDefault()`: suppressing RN's own redbox is not our call to make.
|
|
350
|
-
*/
|
|
351
|
-
function installNativeExceptionCapture() {
|
|
352
|
-
const register = globalThis.RN$registerExceptionListener;
|
|
353
|
-
if (typeof register !== "function") return false;
|
|
354
|
-
register(data => {
|
|
355
|
-
try {
|
|
356
|
-
if (!captureDisabledByUser) recordNativeException(data);
|
|
357
|
-
} catch {
|
|
358
|
-
// Capture must never interfere with error reporting.
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
return true;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Hook React Native's error paths so FATAL/uncaught JS errors land in the
|
|
366
|
-
* console store: the classic `ErrorUtils.setGlobalHandler` (old architecture,
|
|
367
|
-
* native-module callbacks, promise rejections) AND the native C++ exception
|
|
368
|
-
* listener (New Architecture render crashes — see
|
|
369
|
-
* {@link installNativeExceptionCapture}). Both feed the same de-duplicated
|
|
370
|
-
* `[FATAL]` entry, so a crash reported through both seams shows up once.
|
|
371
|
-
*
|
|
372
|
-
* - Chains the previous handler (LogBox/redbox still fire; nothing swallowed).
|
|
373
|
-
* - Idempotent, and a silent no-op off React Native (neither global present) —
|
|
374
|
-
* which also keeps it inert on the desktop dashboard / web mirrors.
|
|
375
|
-
* - Recording respects an explicit `uninstallConsoleCapture()` (user OFF), but
|
|
376
|
-
* the hooks themselves stay chained — they can't be safely removed.
|
|
377
|
-
*/
|
|
378
|
-
function installFatalErrorCapture() {
|
|
379
|
-
if (fatalInstalled) return;
|
|
380
|
-
// Latch only once a seam is actually attached. Setting the flag up front
|
|
381
|
-
// means an install that runs before `InitializeCore` has published
|
|
382
|
-
// `ErrorUtils` would latch anyway and never retry — silently losing promise
|
|
383
|
-
// rejections and native-callback errors, which travel ONLY that seam.
|
|
384
|
-
const nativeInstalled = installNativeExceptionCapture();
|
|
385
|
-
const errorUtils = globalThis.ErrorUtils;
|
|
386
|
-
if (typeof errorUtils?.setGlobalHandler !== "function") {
|
|
387
|
-
fatalInstalled = nativeInstalled;
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
fatalInstalled = true;
|
|
391
|
-
const previous = typeof errorUtils.getGlobalHandler === "function" ? errorUtils.getGlobalHandler() : undefined;
|
|
392
|
-
errorUtils.setGlobalHandler((error, isFatal) => {
|
|
393
|
-
try {
|
|
394
|
-
if (!captureDisabledByUser) recordFatalError(error, isFatal);
|
|
395
|
-
} catch {
|
|
396
|
-
// Capture must never interfere with error reporting.
|
|
397
|
-
}
|
|
398
|
-
if (typeof previous === "function") previous(error, isFatal);
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* Patch the global console methods. Idempotent — safe to call more than once.
|
|
404
|
-
* Each patched method still forwards to the original so normal logging keeps
|
|
405
|
-
* working (Metro terminal, Chrome, native logcat/Xcode).
|
|
406
|
-
*
|
|
407
|
-
* Also installs the fatal-error hook (see `installFatalErrorCapture`) so every
|
|
408
|
-
* install path captures crashes, not just `console.*` calls.
|
|
409
|
-
*/
|
|
410
|
-
function installConsoleCapture() {
|
|
411
|
-
if ((0, _sharedUi.getAccountAccess)().status === "locked") return;
|
|
412
|
-
captureDisabledByUser = false;
|
|
413
|
-
installFatalErrorCapture();
|
|
414
|
-
if (installed) return;
|
|
415
|
-
installed = true;
|
|
416
|
-
for (const method of METHODS) {
|
|
417
|
-
const original = console[method];
|
|
418
|
-
if (typeof original !== "function") continue;
|
|
419
|
-
originals[method] = original;
|
|
420
|
-
// Named so origin parsing can identify (and skip) this frame by function
|
|
421
|
-
// name — in a Metro bundle every frame shares one bundle URL, so filename
|
|
422
|
-
// filtering can't distinguish our wrapper from the real caller.
|
|
423
|
-
console[method] = function buoyConsoleProxy(...args) {
|
|
424
|
-
record(method, args);
|
|
425
|
-
original.apply(console, args);
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/** Restore the original console methods. Also mutes fatal-error recording
|
|
431
|
-
* (the hook itself stays chained — see `installFatalErrorCapture`). */
|
|
432
|
-
function uninstallConsoleCapture() {
|
|
433
|
-
captureDisabledByUser = true;
|
|
434
|
-
if (!installed) return;
|
|
435
|
-
installed = false;
|
|
436
|
-
for (const method of METHODS) {
|
|
437
|
-
const original = originals[method];
|
|
438
|
-
if (original) console[method] = original;
|
|
439
|
-
delete originals[method];
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/** Subscribe to changes. Returns an unsubscribe function. */
|
|
444
|
-
function subscribe(listener) {
|
|
445
|
-
return store.subscribe(listener);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/** Current snapshot (stable reference between mutations for useSyncExternalStore). */
|
|
449
|
-
function getEntries() {
|
|
450
|
-
return store.getSnapshot();
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/** Clear all captured entries. Fires onClear listeners (e.g. to forward the
|
|
454
|
-
* clear to a remote device when running in mirror mode). */
|
|
455
|
-
function clearEntries() {
|
|
456
|
-
void clearSavedBuffer();
|
|
457
|
-
store.clear();
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
// ─── Remote-mirror mode (desktop dashboard) ──────────────────────────────────
|
|
461
|
-
// The desktop imports this same store but, instead of patching its own console,
|
|
462
|
-
// drives it from device snapshots via replaceEntries(). Capture is never
|
|
463
|
-
// installed there, so local and remote modes never mix.
|
|
464
|
-
|
|
465
|
-
/** Replace the whole entry list from a remote snapshot. */
|
|
466
|
-
function replaceEntries(next) {
|
|
467
|
-
store.set(next);
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
/** Register a listener fired when clearEntries() is called. Returns an
|
|
471
|
-
* unsubscribe function. Used by the dashboard to forward clears to the device. */
|
|
472
|
-
function onClear(listener) {
|
|
473
|
-
return store.onClear(listener);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
// ─── Preserve log (persist across reload) ────────────────────────────────────
|
|
477
|
-
// Default OFF: the buffer is in-memory only, so a reload starts fresh. When ON,
|
|
478
|
-
// the buffer is saved to storage (debounced) and restored on the next launch.
|
|
479
|
-
|
|
480
|
-
const PRESERVE_KEY = "@react_buoy_console_preserve";
|
|
481
|
-
const BUFFER_KEY = "@react_buoy_console_buffer";
|
|
482
|
-
const SAVE_DEBOUNCE_MS = 600;
|
|
483
|
-
let preserveLog = false;
|
|
484
|
-
let persistenceReady = false;
|
|
485
|
-
let persistenceGeneration = 0;
|
|
486
|
-
let bufferWrites = Promise.resolve();
|
|
487
|
-
const preserveListeners = new Set();
|
|
488
|
-
let saveTimer = null;
|
|
489
|
-
function emitPreserve() {
|
|
490
|
-
for (const listener of preserveListeners) listener();
|
|
491
|
-
}
|
|
492
|
-
function scheduleSave() {
|
|
493
|
-
if (!preserveLog || !(0, _sharedUi.hasAccountAccess)()) return;
|
|
494
|
-
if (saveTimer) clearTimeout(saveTimer);
|
|
495
|
-
saveTimer = setTimeout(saveBuffer, SAVE_DEBOUNCE_MS);
|
|
496
|
-
}
|
|
497
|
-
async function saveBuffer() {
|
|
498
|
-
saveTimer = null;
|
|
499
|
-
if (!preserveLog || !(0, _sharedUi.hasAccountAccess)()) return;
|
|
500
|
-
try {
|
|
501
|
-
const serializable = store.getSnapshot().map(entry => ({
|
|
502
|
-
...entry,
|
|
503
|
-
args: (0, _sanitize.sanitizeArgs)(entry.args)
|
|
504
|
-
}));
|
|
505
|
-
const generation = persistenceGeneration;
|
|
506
|
-
bufferWrites = bufferWrites.then(async () => {
|
|
507
|
-
if (generation !== persistenceGeneration || !preserveLog || !(0, _sharedUi.hasAccountAccess)()) return;
|
|
508
|
-
await _sharedUi.persistentStorage.setItem(BUFFER_KEY, JSON.stringify(serializable));
|
|
509
|
-
}).catch(() => {});
|
|
510
|
-
await bufferWrites;
|
|
511
|
-
} catch {
|
|
512
|
-
// Storage unavailable — preserve is best-effort.
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
async function clearSavedBuffer() {
|
|
516
|
-
persistenceGeneration++;
|
|
517
|
-
persistenceReady = false;
|
|
518
|
-
try {
|
|
519
|
-
bufferWrites = bufferWrites.then(() => _sharedUi.persistentStorage.removeItem(BUFFER_KEY)).catch(() => {});
|
|
520
|
-
await bufferWrites;
|
|
521
|
-
} catch {
|
|
522
|
-
// ignore
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Load the persisted preserve-log flag and, if enabled, restore the saved
|
|
528
|
-
* buffer. If disabled, drop any saved buffer so the session starts fresh.
|
|
529
|
-
* Idempotent — safe to call from ConsoleRoot on every mount.
|
|
530
|
-
*/
|
|
531
|
-
async function initConsolePersistence() {
|
|
532
|
-
if (persistenceReady || !(0, _sharedUi.hasAccountAccess)()) return;
|
|
533
|
-
persistenceReady = true;
|
|
534
|
-
const generation = persistenceGeneration;
|
|
535
|
-
try {
|
|
536
|
-
preserveLog = (await _sharedUi.persistentStorage.getItem(PRESERVE_KEY)) === "true";
|
|
537
|
-
} catch {
|
|
538
|
-
preserveLog = false;
|
|
539
|
-
}
|
|
540
|
-
if (generation !== persistenceGeneration || !(0, _sharedUi.hasAccountAccess)()) {
|
|
541
|
-
persistenceReady = false;
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
emitPreserve();
|
|
545
|
-
if (!preserveLog) {
|
|
546
|
-
await clearSavedBuffer();
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
try {
|
|
550
|
-
const raw = await _sharedUi.persistentStorage.getItem(BUFFER_KEY);
|
|
551
|
-
if (generation !== persistenceGeneration || !(0, _sharedUi.hasAccountAccess)()) {
|
|
552
|
-
persistenceReady = false;
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
555
|
-
if (raw) {
|
|
556
|
-
const saved = JSON.parse(raw);
|
|
557
|
-
if (Array.isArray(saved) && saved.length) {
|
|
558
|
-
// Prepend restored entries before anything captured this session.
|
|
559
|
-
store.update(current => [...saved, ...current]);
|
|
560
|
-
store.bumpIdAbove(Math.max(...saved.map(e => e.id)));
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
} catch {
|
|
564
|
-
// Corrupt/absent buffer — ignore.
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
/** Whether logs persist across reload. */
|
|
569
|
-
function getPreserveLog() {
|
|
570
|
-
return preserveLog;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
/** Toggle preserve-log. Persists the flag; saves or drops the buffer. */
|
|
574
|
-
function setPreserveLog(next) {
|
|
575
|
-
if (preserveLog === next) return;
|
|
576
|
-
preserveLog = next;
|
|
577
|
-
emitPreserve();
|
|
578
|
-
_sharedUi.persistentStorage.setItem(PRESERVE_KEY, String(next)).catch(() => {});
|
|
579
|
-
if (next) saveBuffer();else clearSavedBuffer();
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
/** Subscribe to preserve-log changes. Returns an unsubscribe function. */
|
|
583
|
-
function subscribePreserveLog(listener) {
|
|
584
|
-
preserveListeners.add(listener);
|
|
585
|
-
return () => {
|
|
586
|
-
preserveListeners.delete(listener);
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
//# sourceMappingURL=consoleLogStore.js.map
|
|
7
|
+
This error is located at:
|
|
8
|
+
${compactComponentStack(e.componentStack)}`:"";const s=`${t} ${n}${r}`;pushFatal({id:store.allocId(),method:"error",level:"error",args:[t,n,...r?[r.trim()]:[]],message:s,timestamp:Date.now(),stack:formatNativeStack(e),fatal:true},o)}function installNativeExceptionCapture(){const e=globalThis.RN$registerExceptionListener;if(typeof e!=="function")return false;e(t=>{try{if(!captureDisabledByUser)recordNativeException(t)}catch{}});return true}function installFatalErrorCapture(){if(fatalInstalled)return;const e=installNativeExceptionCapture();const t=globalThis.ErrorUtils;if(typeof t?.setGlobalHandler!=="function"){fatalInstalled=e;return}fatalInstalled=true;const n=typeof t.getGlobalHandler==="function"?t.getGlobalHandler():void 0;t.setGlobalHandler((o,r)=>{try{if(!captureDisabledByUser)recordFatalError(o,r)}catch{}if(typeof n==="function")n(o,r)})}function installConsoleCapture(){if((0,_sharedUi.getAccountAccess)().status==="locked")return;captureDisabledByUser=false;installFatalErrorCapture();if(installed)return;installed=true;for(const e of METHODS){const t=console[e];if(typeof t!=="function")continue;originals[e]=t;console[e]=function n(...o){record(e,o);t.apply(console,o)}}}function uninstallConsoleCapture(){captureDisabledByUser=true;if(!installed)return;installed=false;for(const e of METHODS){const t=originals[e];if(t)console[e]=t;delete originals[e]}}function subscribe(e){return store.subscribe(e)}function getEntries(){return store.getSnapshot()}function clearEntries(){void clearSavedBuffer();store.clear()}function replaceEntries(e){store.set(e)}function onClear(e){return store.onClear(e)}const PRESERVE_KEY="@react_buoy_console_preserve";const BUFFER_KEY="@react_buoy_console_buffer";const SAVE_DEBOUNCE_MS=600;let preserveLog=false;let persistenceReady=false;let persistenceGeneration=0;let bufferWrites=Promise.resolve();const preserveListeners=new Set;let saveTimer=null;function emitPreserve(){for(const e of preserveListeners)e()}function scheduleSave(){if(!preserveLog||!(0,_sharedUi.hasAccountAccess)())return;if(saveTimer)clearTimeout(saveTimer);saveTimer=setTimeout(saveBuffer,SAVE_DEBOUNCE_MS)}async function saveBuffer(){saveTimer=null;if(!preserveLog||!(0,_sharedUi.hasAccountAccess)())return;try{const e=store.getSnapshot().map(n=>({...n,args:(0,_sanitize.sanitizeArgs)(n.args)}));const t=persistenceGeneration;bufferWrites=bufferWrites.then(async()=>{if(t!==persistenceGeneration||!preserveLog||!(0,_sharedUi.hasAccountAccess)())return;await _sharedUi.persistentStorage.setItem(BUFFER_KEY,JSON.stringify(e))}).catch(()=>{});await bufferWrites}catch{}}async function clearSavedBuffer(){persistenceGeneration++;persistenceReady=false;try{bufferWrites=bufferWrites.then(()=>_sharedUi.persistentStorage.removeItem(BUFFER_KEY)).catch(()=>{});await bufferWrites}catch{}}async function initConsolePersistence(){if(persistenceReady||!(0,_sharedUi.hasAccountAccess)())return;persistenceReady=true;const e=persistenceGeneration;try{preserveLog=await _sharedUi.persistentStorage.getItem(PRESERVE_KEY)==="true"}catch{preserveLog=false}if(e!==persistenceGeneration||!(0,_sharedUi.hasAccountAccess)()){persistenceReady=false;return}emitPreserve();if(!preserveLog){await clearSavedBuffer();return}try{const t=await _sharedUi.persistentStorage.getItem(BUFFER_KEY);if(e!==persistenceGeneration||!(0,_sharedUi.hasAccountAccess)()){persistenceReady=false;return}if(t){const n=JSON.parse(t);if(Array.isArray(n)&&n.length){store.update(o=>[...n,...o]);store.bumpIdAbove(Math.max(...n.map(o=>o.id)))}}}catch{}}function getPreserveLog(){return preserveLog}function setPreserveLog(e){if(preserveLog===e)return;preserveLog=e;emitPreserve();_sharedUi.persistentStorage.setItem(PRESERVE_KEY,String(e)).catch(()=>{});if(e)saveBuffer();else clearSavedBuffer()}function subscribePreserveLog(e){preserveListeners.add(e);return()=>{preserveListeners.delete(e)}}
|