@oxog/devinspector 1.2.0 → 1.3.0
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/CHANGELOG.md +36 -0
- package/LICENSE +0 -0
- package/README.md +85 -28
- package/dist/chunk-LNBLBFDA.js +92 -0
- package/dist/chunk-LNBLBFDA.js.map +1 -0
- package/dist/chunk-PPIEWSZ7.js +32 -0
- package/dist/chunk-PPIEWSZ7.js.map +1 -0
- package/dist/console-monitor-LBNXAQQ4.js +571 -0
- package/dist/console-monitor-LBNXAQQ4.js.map +1 -0
- package/dist/devinspector.umd.js +1782 -1074
- package/dist/devinspector.umd.js.map +1 -1
- package/dist/devinspector.umd.min.js +6 -1
- package/dist/devinspector.umd.min.js.map +1 -1
- package/dist/dom-monitor-IGQZTXMH.js +19 -0
- package/dist/dom-monitor-IGQZTXMH.js.map +1 -0
- package/dist/error-monitor-XDNRO4KS.js +423 -0
- package/dist/error-monitor-XDNRO4KS.js.map +1 -0
- package/dist/index.cjs +5918 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +582 -0
- package/dist/index.d.ts +582 -0
- package/dist/index.js +1983 -0
- package/dist/index.js.map +1 -0
- package/dist/inspector-ui-AFTUEVWA.js +1240 -0
- package/dist/inspector-ui-AFTUEVWA.js.map +1 -0
- package/dist/network-monitor-HUSRKEXE.js +841 -0
- package/dist/network-monitor-HUSRKEXE.js.map +1 -0
- package/dist/performance-monitor-66DQJGOJ.js +544 -0
- package/dist/performance-monitor-66DQJGOJ.js.map +1 -0
- package/dist/state-monitor-PS5Q7NWY.js +19 -0
- package/dist/state-monitor-PS5Q7NWY.js.map +1 -0
- package/dist/storage-monitor-QW634CEJ.js +19 -0
- package/dist/storage-monitor-QW634CEJ.js.map +1 -0
- package/package.json +51 -38
- package/dist/devinspector.cjs.js +0 -5494
- package/dist/devinspector.cjs.js.map +0 -1
- package/dist/devinspector.esm.js +0 -5482
- package/dist/devinspector.esm.js.map +0 -1
- package/dist/types/clean-inspector.d.ts +0 -52
- package/dist/types/core/event-emitter.d.ts +0 -21
- package/dist/types/core/inspector.d.ts +0 -121
- package/dist/types/core/plugin-system.d.ts +0 -60
- package/dist/types/core/storage.d.ts +0 -52
- package/dist/types/core/utils.d.ts +0 -34
- package/dist/types/enhanced-inspector.d.ts +0 -56
- package/dist/types/enhanced-simple.d.ts +0 -46
- package/dist/types/index-simple.d.ts +0 -11
- package/dist/types/index.d.ts +0 -19
- package/dist/types/monitors/console/console-interceptor.d.ts +0 -36
- package/dist/types/monitors/console/console-monitor.d.ts +0 -26
- package/dist/types/monitors/console/log-formatter.d.ts +0 -8
- package/dist/types/monitors/dom/dom-monitor.d.ts +0 -8
- package/dist/types/monitors/error/error-monitor.d.ts +0 -28
- package/dist/types/monitors/error/error-tracker.d.ts +0 -55
- package/dist/types/monitors/error/source-map-support.d.ts +0 -15
- package/dist/types/monitors/network/fetch-interceptor.d.ts +0 -45
- package/dist/types/monitors/network/network-monitor.d.ts +0 -47
- package/dist/types/monitors/network/websocket-monitor.d.ts +0 -44
- package/dist/types/monitors/network/xhr-interceptor.d.ts +0 -25
- package/dist/types/monitors/performance/fps-monitor.d.ts +0 -24
- package/dist/types/monitors/performance/long-task-detector.d.ts +0 -25
- package/dist/types/monitors/performance/memory-monitor.d.ts +0 -30
- package/dist/types/monitors/performance/metrics-collector.d.ts +0 -45
- package/dist/types/monitors/performance/performance-monitor.d.ts +0 -34
- package/dist/types/monitors/state/state-monitor.d.ts +0 -8
- package/dist/types/monitors/storage/storage-monitor.d.ts +0 -8
- package/dist/types/simple-index.d.ts +0 -3
- package/dist/types/simple-inspector.d.ts +0 -24
- package/dist/types/ui/components/floating-widget.d.ts +0 -21
- package/dist/types/ui/components/main-panel.d.ts +0 -38
- package/dist/types/ui/inspector-ui.d.ts +0 -29
- package/dist/types/ui/styles.d.ts +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,1983 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultEnabled,
|
|
3
|
+
escapeHtml,
|
|
4
|
+
hasDom
|
|
5
|
+
} from "./chunk-PPIEWSZ7.js";
|
|
6
|
+
|
|
7
|
+
// src/core/event-emitter.ts
|
|
8
|
+
var EventEmitter = class {
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.events = /* @__PURE__ */ new Map();
|
|
11
|
+
var _a, _b;
|
|
12
|
+
this.maxListeners = (_a = options.maxListeners) != null ? _a : 10;
|
|
13
|
+
this.captureRejections = (_b = options.captureRejections) != null ? _b : false;
|
|
14
|
+
}
|
|
15
|
+
on(event, listener) {
|
|
16
|
+
if (!this.events.has(event)) {
|
|
17
|
+
this.events.set(event, /* @__PURE__ */ new Set());
|
|
18
|
+
}
|
|
19
|
+
const listeners = this.events.get(event);
|
|
20
|
+
if (listeners.size > this.maxListeners) {
|
|
21
|
+
console.warn(
|
|
22
|
+
`MaxListenersExceededWarning: Possible EventEmitter memory leak detected. ${listeners.size} ${String(event)} listeners added.`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
listeners.add(listener);
|
|
26
|
+
return () => {
|
|
27
|
+
listeners.delete(listener);
|
|
28
|
+
if (listeners.size === 0) {
|
|
29
|
+
this.events.delete(event);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
once(event, listener) {
|
|
34
|
+
const wrappedListener = (data) => {
|
|
35
|
+
unsubscribe();
|
|
36
|
+
listener(data);
|
|
37
|
+
};
|
|
38
|
+
const unsubscribe = this.on(event, wrappedListener);
|
|
39
|
+
return unsubscribe;
|
|
40
|
+
}
|
|
41
|
+
emit(event, ...args) {
|
|
42
|
+
const listeners = this.events.get(event);
|
|
43
|
+
if (!listeners || listeners.size === 0) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const data = args[0];
|
|
47
|
+
listeners.forEach((listener) => {
|
|
48
|
+
try {
|
|
49
|
+
listener(data);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (this.captureRejections) {
|
|
52
|
+
this.emit("error", error);
|
|
53
|
+
} else {
|
|
54
|
+
console.error(`Error in event listener for "${String(event)}":`, error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
off(event, listener) {
|
|
61
|
+
if (!listener) {
|
|
62
|
+
this.events.delete(event);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const listeners = this.events.get(event);
|
|
66
|
+
if (listeners) {
|
|
67
|
+
listeners.delete(listener);
|
|
68
|
+
if (listeners.size === 0) {
|
|
69
|
+
this.events.delete(event);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
removeAllListeners(event) {
|
|
74
|
+
if (event) {
|
|
75
|
+
this.events.delete(event);
|
|
76
|
+
} else {
|
|
77
|
+
this.events.clear();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
listenerCount(event) {
|
|
81
|
+
const listeners = this.events.get(event);
|
|
82
|
+
return listeners ? listeners.size : 0;
|
|
83
|
+
}
|
|
84
|
+
eventNames() {
|
|
85
|
+
return Array.from(this.events.keys());
|
|
86
|
+
}
|
|
87
|
+
setMaxListeners(n) {
|
|
88
|
+
this.maxListeners = n;
|
|
89
|
+
}
|
|
90
|
+
getMaxListeners() {
|
|
91
|
+
return this.maxListeners;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/core/plugin-system.ts
|
|
96
|
+
var PluginSystem = class {
|
|
97
|
+
constructor(context) {
|
|
98
|
+
this.plugins = /* @__PURE__ */ new Map();
|
|
99
|
+
this.activePlugins = /* @__PURE__ */ new Set();
|
|
100
|
+
this.installingPlugins = /* @__PURE__ */ new Set();
|
|
101
|
+
this.context = context;
|
|
102
|
+
}
|
|
103
|
+
async register(plugin) {
|
|
104
|
+
if (this.plugins.has(plugin.name)) {
|
|
105
|
+
throw new Error(`Plugin "${plugin.name}" is already registered`);
|
|
106
|
+
}
|
|
107
|
+
if (this.installingPlugins.has(plugin.name)) {
|
|
108
|
+
throw new Error(`Plugin "${plugin.name}" is currently being installed`);
|
|
109
|
+
}
|
|
110
|
+
this.installingPlugins.add(plugin.name);
|
|
111
|
+
try {
|
|
112
|
+
await plugin.install(this.context);
|
|
113
|
+
this.plugins.set(plugin.name, plugin);
|
|
114
|
+
this.activePlugins.add(plugin.name);
|
|
115
|
+
if (plugin.enable) {
|
|
116
|
+
plugin.enable();
|
|
117
|
+
}
|
|
118
|
+
this.context.events.emit("plugin:registered", {
|
|
119
|
+
name: plugin.name,
|
|
120
|
+
version: plugin.version
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
this.installingPlugins.delete(plugin.name);
|
|
124
|
+
throw new Error(`Failed to install plugin "${plugin.name}": ${error}`);
|
|
125
|
+
}
|
|
126
|
+
this.installingPlugins.delete(plugin.name);
|
|
127
|
+
}
|
|
128
|
+
async unregister(pluginName) {
|
|
129
|
+
const plugin = this.plugins.get(pluginName);
|
|
130
|
+
if (!plugin) {
|
|
131
|
+
throw new Error(`Plugin "${pluginName}" is not registered`);
|
|
132
|
+
}
|
|
133
|
+
if (plugin.disable) {
|
|
134
|
+
plugin.disable();
|
|
135
|
+
}
|
|
136
|
+
if (plugin.uninstall) {
|
|
137
|
+
await plugin.uninstall();
|
|
138
|
+
}
|
|
139
|
+
this.plugins.delete(pluginName);
|
|
140
|
+
this.activePlugins.delete(pluginName);
|
|
141
|
+
this.context.events.emit("plugin:unregistered", {
|
|
142
|
+
name: pluginName
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
enable(pluginName) {
|
|
146
|
+
const plugin = this.plugins.get(pluginName);
|
|
147
|
+
if (!plugin) {
|
|
148
|
+
throw new Error(`Plugin "${pluginName}" is not registered`);
|
|
149
|
+
}
|
|
150
|
+
if (this.activePlugins.has(pluginName)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (plugin.enable) {
|
|
154
|
+
plugin.enable();
|
|
155
|
+
}
|
|
156
|
+
this.activePlugins.add(pluginName);
|
|
157
|
+
this.context.events.emit("plugin:enabled", {
|
|
158
|
+
name: pluginName
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
disable(pluginName) {
|
|
162
|
+
const plugin = this.plugins.get(pluginName);
|
|
163
|
+
if (!plugin) {
|
|
164
|
+
throw new Error(`Plugin "${pluginName}" is not registered`);
|
|
165
|
+
}
|
|
166
|
+
if (!this.activePlugins.has(pluginName)) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (plugin.disable) {
|
|
170
|
+
plugin.disable();
|
|
171
|
+
}
|
|
172
|
+
this.activePlugins.delete(pluginName);
|
|
173
|
+
this.context.events.emit("plugin:disabled", {
|
|
174
|
+
name: pluginName
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
get(pluginName) {
|
|
178
|
+
return this.plugins.get(pluginName);
|
|
179
|
+
}
|
|
180
|
+
has(pluginName) {
|
|
181
|
+
return this.plugins.has(pluginName);
|
|
182
|
+
}
|
|
183
|
+
isActive(pluginName) {
|
|
184
|
+
return this.activePlugins.has(pluginName);
|
|
185
|
+
}
|
|
186
|
+
getAll() {
|
|
187
|
+
return Array.from(this.plugins.values());
|
|
188
|
+
}
|
|
189
|
+
getActive() {
|
|
190
|
+
return Array.from(this.activePlugins).map((name) => this.plugins.get(name));
|
|
191
|
+
}
|
|
192
|
+
getMetadata(pluginName) {
|
|
193
|
+
const plugin = this.plugins.get(pluginName);
|
|
194
|
+
if (!plugin) {
|
|
195
|
+
return void 0;
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
name: plugin.name,
|
|
199
|
+
version: plugin.version,
|
|
200
|
+
description: plugin.description
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
getAllMetadata() {
|
|
204
|
+
return this.getAll().map((plugin) => ({
|
|
205
|
+
name: plugin.name,
|
|
206
|
+
version: plugin.version,
|
|
207
|
+
description: plugin.description
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var BasePlugin = class {
|
|
212
|
+
async install(context) {
|
|
213
|
+
this.context = context;
|
|
214
|
+
await this.onInstall();
|
|
215
|
+
}
|
|
216
|
+
async uninstall() {
|
|
217
|
+
await this.onUninstall();
|
|
218
|
+
this.context = void 0;
|
|
219
|
+
}
|
|
220
|
+
enable() {
|
|
221
|
+
this.onEnable();
|
|
222
|
+
}
|
|
223
|
+
disable() {
|
|
224
|
+
this.onDisable();
|
|
225
|
+
}
|
|
226
|
+
onUninstall() {
|
|
227
|
+
}
|
|
228
|
+
onEnable() {
|
|
229
|
+
}
|
|
230
|
+
onDisable() {
|
|
231
|
+
}
|
|
232
|
+
get inspector() {
|
|
233
|
+
var _a;
|
|
234
|
+
return (_a = this.context) == null ? void 0 : _a.inspector;
|
|
235
|
+
}
|
|
236
|
+
get events() {
|
|
237
|
+
var _a;
|
|
238
|
+
if (!((_a = this.context) == null ? void 0 : _a.events)) {
|
|
239
|
+
throw new Error("Events not available - plugin not installed");
|
|
240
|
+
}
|
|
241
|
+
return this.context.events;
|
|
242
|
+
}
|
|
243
|
+
get storage() {
|
|
244
|
+
var _a;
|
|
245
|
+
return (_a = this.context) == null ? void 0 : _a.storage;
|
|
246
|
+
}
|
|
247
|
+
get config() {
|
|
248
|
+
var _a;
|
|
249
|
+
return (_a = this.context) == null ? void 0 : _a.config;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// src/version.ts
|
|
254
|
+
var VERSION = "1.3.0";
|
|
255
|
+
|
|
256
|
+
// src/enhanced-simple.ts
|
|
257
|
+
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug"];
|
|
258
|
+
var MAX_MESSAGE_LENGTH = 1e4;
|
|
259
|
+
var MAX_METRIC_ENTRIES = 500;
|
|
260
|
+
var ASSET_PATTERN = /\.(?:css|js|mjs|map|png|jpe?g|gif|svg|webp|avif|ico|woff2?|ttf|otf|eot)(?:[?#]|$)/i;
|
|
261
|
+
var POSITIONS = ["top-left", "top-right", "bottom-left", "bottom-right"];
|
|
262
|
+
var PALETTES = {
|
|
263
|
+
dark: { bg: "#1a1a1a", header: "#262626", toolbar: "#1e1e1e", border: "#333", row: "#2a2a2a", text: "#e4e4e7", muted: "#9ca3af", code: "#0f0f0f" },
|
|
264
|
+
light: { bg: "#ffffff", header: "#f3f4f6", toolbar: "#f9fafb", border: "#d1d5db", row: "#e5e7eb", text: "#111827", muted: "#4b5563", code: "#f3f4f6" }
|
|
265
|
+
};
|
|
266
|
+
var idCounter = 0;
|
|
267
|
+
function nextId() {
|
|
268
|
+
idCounter = (idCounter + 1) % Number.MAX_SAFE_INTEGER;
|
|
269
|
+
return `${Date.now().toString(36)}-${idCounter.toString(36)}`;
|
|
270
|
+
}
|
|
271
|
+
function limit(value, fallback) {
|
|
272
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.floor(value) : fallback;
|
|
273
|
+
}
|
|
274
|
+
function normalizeCombo(combo) {
|
|
275
|
+
if (typeof combo !== "string") return "";
|
|
276
|
+
const parts = combo.toLowerCase().split("+").map((part) => part.trim()).filter(Boolean);
|
|
277
|
+
const key = parts.filter((part) => !["ctrl", "control", "alt", "shift", "meta", "cmd"].includes(part));
|
|
278
|
+
if (key.length !== 1) return "";
|
|
279
|
+
const has = (...names) => names.some((name) => parts.includes(name));
|
|
280
|
+
return [has("ctrl", "control") && "ctrl", has("alt") && "alt", has("shift") && "shift", has("meta", "cmd") && "meta", key[0]].filter(Boolean).join("+");
|
|
281
|
+
}
|
|
282
|
+
function eventCombo(event) {
|
|
283
|
+
if (typeof event.key !== "string") return "";
|
|
284
|
+
return [event.ctrlKey && "ctrl", event.altKey && "alt", event.shiftKey && "shift", event.metaKey && "meta", event.key.toLowerCase()].filter(Boolean).join("+");
|
|
285
|
+
}
|
|
286
|
+
function truncate(text) {
|
|
287
|
+
return text.length > MAX_MESSAGE_LENGTH ? `${text.slice(0, MAX_MESSAGE_LENGTH)}\u2026 (${text.length - MAX_MESSAGE_LENGTH} more characters)` : text;
|
|
288
|
+
}
|
|
289
|
+
function stringifyArg(arg) {
|
|
290
|
+
if (typeof arg === "string") return arg;
|
|
291
|
+
if (arg instanceof Error) return arg.stack || `${arg.name}: ${arg.message}`;
|
|
292
|
+
if (arg !== null && typeof arg === "object") {
|
|
293
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
294
|
+
try {
|
|
295
|
+
const json = JSON.stringify(
|
|
296
|
+
arg,
|
|
297
|
+
(_key, value) => {
|
|
298
|
+
if (typeof value === "bigint") return `${value}n`;
|
|
299
|
+
if (value !== null && typeof value === "object") {
|
|
300
|
+
if (seen.has(value)) return "[Circular]";
|
|
301
|
+
seen.add(value);
|
|
302
|
+
}
|
|
303
|
+
return value;
|
|
304
|
+
},
|
|
305
|
+
2
|
|
306
|
+
);
|
|
307
|
+
return json === void 0 ? String(arg) : json;
|
|
308
|
+
} catch (e) {
|
|
309
|
+
try {
|
|
310
|
+
return String(arg);
|
|
311
|
+
} catch (e2) {
|
|
312
|
+
return "[object]";
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
try {
|
|
317
|
+
return String(arg);
|
|
318
|
+
} catch (e) {
|
|
319
|
+
return "[unprintable]";
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function requestUrl(input) {
|
|
323
|
+
if (typeof input === "string") return input;
|
|
324
|
+
if (input && typeof input === "object") {
|
|
325
|
+
const candidate = input;
|
|
326
|
+
if (typeof candidate.url === "string") return candidate.url;
|
|
327
|
+
if (typeof candidate.href === "string") return candidate.href;
|
|
328
|
+
}
|
|
329
|
+
return String(input);
|
|
330
|
+
}
|
|
331
|
+
function requestMethod(input, init) {
|
|
332
|
+
const fromInit = init && typeof init === "object" ? init.method : void 0;
|
|
333
|
+
if (typeof fromInit === "string" && fromInit) return fromInit.toUpperCase();
|
|
334
|
+
const fromRequest = input && typeof input === "object" ? input.method : void 0;
|
|
335
|
+
if (typeof fromRequest === "string" && fromRequest) return fromRequest.toUpperCase();
|
|
336
|
+
return "GET";
|
|
337
|
+
}
|
|
338
|
+
var _EnhancedDevInspector = class _EnhancedDevInspector {
|
|
339
|
+
constructor(config = {}) {
|
|
340
|
+
this.events = new EventEmitter({ maxListeners: 100 });
|
|
341
|
+
this.network = [];
|
|
342
|
+
this.consoleEntries = [];
|
|
343
|
+
this.errors = [];
|
|
344
|
+
this.metrics = [];
|
|
345
|
+
this.performanceStats = { fps: 0, memory: null };
|
|
346
|
+
this.isRecording = true;
|
|
347
|
+
this.isVisible = false;
|
|
348
|
+
this.isMinimized = false;
|
|
349
|
+
this.destroyed = false;
|
|
350
|
+
this.capturing = false;
|
|
351
|
+
this.renderQueued = false;
|
|
352
|
+
this.activeTab = "network";
|
|
353
|
+
this.selectedRequestId = null;
|
|
354
|
+
this.widget = null;
|
|
355
|
+
this.panel = null;
|
|
356
|
+
this.patches = [];
|
|
357
|
+
this.cleanups = [];
|
|
358
|
+
this.rafId = null;
|
|
359
|
+
this.marks = /* @__PURE__ */ new Map();
|
|
360
|
+
this.xhrState = /* @__PURE__ */ new WeakMap();
|
|
361
|
+
var _a;
|
|
362
|
+
this.config = _EnhancedDevInspector.resolveConfig(config != null ? config : {});
|
|
363
|
+
this.active = this.config.enabled && hasDom();
|
|
364
|
+
const self = this;
|
|
365
|
+
this.pluginSystem = new PluginSystem({
|
|
366
|
+
inspector: this,
|
|
367
|
+
storage: {
|
|
368
|
+
get network() {
|
|
369
|
+
return self.getEntries("network");
|
|
370
|
+
},
|
|
371
|
+
get console() {
|
|
372
|
+
return self.getEntries("console");
|
|
373
|
+
},
|
|
374
|
+
get errors() {
|
|
375
|
+
return self.getEntries("errors");
|
|
376
|
+
},
|
|
377
|
+
get metrics() {
|
|
378
|
+
return self.getEntries("metrics");
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
events: this.events,
|
|
382
|
+
config: this.config
|
|
383
|
+
});
|
|
384
|
+
if (!this.active) return;
|
|
385
|
+
_EnhancedDevInspector.instances.push(this);
|
|
386
|
+
if (this.config.features.network) {
|
|
387
|
+
this.interceptFetch();
|
|
388
|
+
this.interceptXHR();
|
|
389
|
+
}
|
|
390
|
+
if (this.config.features.console) this.interceptConsole();
|
|
391
|
+
if (this.config.features.errors) this.interceptErrors();
|
|
392
|
+
this.setupHotkeys();
|
|
393
|
+
this.mountWhenReady();
|
|
394
|
+
for (const plugin of (_a = config.plugins) != null ? _a : []) {
|
|
395
|
+
this.use(plugin).catch((error) => this.reportInternal("Failed to register plugin", error));
|
|
396
|
+
}
|
|
397
|
+
this.events.emit("inspector:ready");
|
|
398
|
+
}
|
|
399
|
+
/** The most recently created inspector that is still alive, if any. */
|
|
400
|
+
static getInstance() {
|
|
401
|
+
const { instances } = _EnhancedDevInspector;
|
|
402
|
+
return instances.length > 0 ? instances[instances.length - 1] : null;
|
|
403
|
+
}
|
|
404
|
+
static resolveConfig(config) {
|
|
405
|
+
var _a, _b, _c, _d, _e;
|
|
406
|
+
const features = (_a = config.features) != null ? _a : {};
|
|
407
|
+
const theme = config.theme === "light" || config.theme === "dark" ? config.theme : "auto";
|
|
408
|
+
const prefersDark = (() => {
|
|
409
|
+
try {
|
|
410
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia("(prefers-color-scheme: dark)").matches : true;
|
|
411
|
+
} catch (e) {
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
})();
|
|
415
|
+
const hotkeys = (_b = config.hotkeys) != null ? _b : {};
|
|
416
|
+
return {
|
|
417
|
+
enabled: typeof config.enabled === "boolean" ? config.enabled : defaultEnabled(),
|
|
418
|
+
position: POSITIONS.includes(config.position) ? config.position : "bottom-right",
|
|
419
|
+
theme: theme === "auto" ? prefersDark ? "dark" : "light" : theme,
|
|
420
|
+
hotkeys: {
|
|
421
|
+
toggle: normalizeCombo((_c = hotkeys.toggle) != null ? _c : "ctrl+shift+d"),
|
|
422
|
+
minimize: normalizeCombo((_d = hotkeys.minimize) != null ? _d : "ctrl+shift+m")
|
|
423
|
+
},
|
|
424
|
+
features: {
|
|
425
|
+
network: features.network !== false,
|
|
426
|
+
console: features.console !== false,
|
|
427
|
+
performance: features.performance !== false,
|
|
428
|
+
errors: features.errors !== false
|
|
429
|
+
},
|
|
430
|
+
maxNetworkEntries: limit(config.maxNetworkEntries, 1e3),
|
|
431
|
+
maxConsoleEntries: limit(config.maxConsoleEntries, 500),
|
|
432
|
+
maxErrorEntries: limit(config.maxErrorEntries, 100),
|
|
433
|
+
captureStackTraces: config.captureStackTraces !== false,
|
|
434
|
+
hideAssets: ((_e = config.networkFilters) == null ? void 0 : _e.hideAssets) === true,
|
|
435
|
+
slowRequestThreshold: limit(config.slowRequestThreshold, 3e3),
|
|
436
|
+
onError: typeof config.onError === "function" ? config.onError : void 0,
|
|
437
|
+
onPerformanceIssue: typeof config.onPerformanceIssue === "function" ? config.onPerformanceIssue : void 0
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
// ---------------------------------------------------------------------------
|
|
441
|
+
// Public API
|
|
442
|
+
// ---------------------------------------------------------------------------
|
|
443
|
+
/** True when the inspector is running (enabled, in a browser, not destroyed). */
|
|
444
|
+
get isEnabled() {
|
|
445
|
+
return this.active && !this.destroyed;
|
|
446
|
+
}
|
|
447
|
+
show() {
|
|
448
|
+
if (!this.isEnabled) return;
|
|
449
|
+
this.isVisible = true;
|
|
450
|
+
if (this.panel) this.panel.style.display = "flex";
|
|
451
|
+
if (this.widget) this.widget.style.display = "none";
|
|
452
|
+
this.render();
|
|
453
|
+
this.startPerformanceLoop();
|
|
454
|
+
this.events.emit("inspector:show");
|
|
455
|
+
}
|
|
456
|
+
hide() {
|
|
457
|
+
if (!this.isEnabled) return;
|
|
458
|
+
this.isVisible = false;
|
|
459
|
+
if (this.panel) this.panel.style.display = "none";
|
|
460
|
+
if (this.widget) this.widget.style.display = "flex";
|
|
461
|
+
this.stopPerformanceLoop();
|
|
462
|
+
this.events.emit("inspector:hide");
|
|
463
|
+
}
|
|
464
|
+
toggle() {
|
|
465
|
+
if (this.isVisible) this.hide();
|
|
466
|
+
else this.show();
|
|
467
|
+
}
|
|
468
|
+
/** Collapses the panel to its header (or expands it again). */
|
|
469
|
+
minimize() {
|
|
470
|
+
if (!this.isEnabled) return;
|
|
471
|
+
this.isMinimized = !this.isMinimized;
|
|
472
|
+
if (this.panel) this.panel.style.height = this.isMinimized ? "48px" : "650px";
|
|
473
|
+
this.render();
|
|
474
|
+
this.events.emit("inspector:minimize", this.isMinimized);
|
|
475
|
+
}
|
|
476
|
+
clear(type = "all") {
|
|
477
|
+
if (type === "network" || type === "all") {
|
|
478
|
+
this.network = [];
|
|
479
|
+
this.selectedRequestId = null;
|
|
480
|
+
}
|
|
481
|
+
if (type === "console" || type === "all") this.consoleEntries = [];
|
|
482
|
+
if (type === "errors" || type === "all") this.errors = [];
|
|
483
|
+
if (type === "metrics" || type === "all") this.metrics = [];
|
|
484
|
+
this.scheduleRender();
|
|
485
|
+
}
|
|
486
|
+
/** Pauses or resumes capturing. Patched APIs keep working either way. */
|
|
487
|
+
toggleRecording() {
|
|
488
|
+
this.isRecording = !this.isRecording;
|
|
489
|
+
this.scheduleRender();
|
|
490
|
+
return this.isRecording;
|
|
491
|
+
}
|
|
492
|
+
get recording() {
|
|
493
|
+
return this.isRecording;
|
|
494
|
+
}
|
|
495
|
+
getEntries(type) {
|
|
496
|
+
switch (type) {
|
|
497
|
+
case "network":
|
|
498
|
+
return this.network.map((entry) => ({ ...entry }));
|
|
499
|
+
case "console":
|
|
500
|
+
return this.consoleEntries.map((entry) => ({ ...entry }));
|
|
501
|
+
case "errors":
|
|
502
|
+
return this.errors.map((entry) => ({ ...entry }));
|
|
503
|
+
default:
|
|
504
|
+
return this.metrics.map((entry) => ({ ...entry }));
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
/** Records a custom metric and emits `performance:metric`. */
|
|
508
|
+
track(name, data) {
|
|
509
|
+
if (!this.isEnabled) return;
|
|
510
|
+
const entry = { id: nextId(), name: String(name), data, timestamp: Date.now() };
|
|
511
|
+
this.pushBounded(this.metrics, entry, MAX_METRIC_ENTRIES);
|
|
512
|
+
this.emitSafely("performance:metric", entry);
|
|
513
|
+
this.scheduleRender();
|
|
514
|
+
}
|
|
515
|
+
markStart(name) {
|
|
516
|
+
var _a;
|
|
517
|
+
if (!this.isEnabled) return;
|
|
518
|
+
this.marks.set(String(name), performance.now());
|
|
519
|
+
try {
|
|
520
|
+
(_a = performance.mark) == null ? void 0 : _a.call(performance, `devinspector-${name}-start`);
|
|
521
|
+
} catch (e) {
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
/** Ends a measurement started with markStart() and returns its duration in ms. */
|
|
525
|
+
markEnd(name) {
|
|
526
|
+
var _a, _b;
|
|
527
|
+
if (!this.isEnabled) return void 0;
|
|
528
|
+
const key = String(name);
|
|
529
|
+
const start = this.marks.get(key);
|
|
530
|
+
if (start === void 0) return void 0;
|
|
531
|
+
this.marks.delete(key);
|
|
532
|
+
const duration = performance.now() - start;
|
|
533
|
+
try {
|
|
534
|
+
(_a = performance.mark) == null ? void 0 : _a.call(performance, `devinspector-${key}-end`);
|
|
535
|
+
(_b = performance.measure) == null ? void 0 : _b.call(performance, `devinspector-${key}`, `devinspector-${key}-start`, `devinspector-${key}-end`);
|
|
536
|
+
} catch (e) {
|
|
537
|
+
}
|
|
538
|
+
const entry = { id: nextId(), name: key, duration, timestamp: Date.now() };
|
|
539
|
+
this.pushBounded(this.metrics, entry, MAX_METRIC_ENTRIES);
|
|
540
|
+
this.emitSafely("performance:mark", entry);
|
|
541
|
+
this.scheduleRender();
|
|
542
|
+
return duration;
|
|
543
|
+
}
|
|
544
|
+
/** Installs a plugin. Resolves once the plugin's install() has finished. */
|
|
545
|
+
use(plugin) {
|
|
546
|
+
if (this.destroyed) return Promise.reject(new Error("DevInspector has been destroyed"));
|
|
547
|
+
return this.pluginSystem.register(plugin);
|
|
548
|
+
}
|
|
549
|
+
on(event, listener) {
|
|
550
|
+
return this.events.on(event, listener);
|
|
551
|
+
}
|
|
552
|
+
once(event, listener) {
|
|
553
|
+
return this.events.once(event, listener);
|
|
554
|
+
}
|
|
555
|
+
off(event, listener) {
|
|
556
|
+
this.events.off(event, listener);
|
|
557
|
+
}
|
|
558
|
+
/** Serialisable snapshot of everything captured so far. */
|
|
559
|
+
export() {
|
|
560
|
+
return {
|
|
561
|
+
version: VERSION,
|
|
562
|
+
timestamp: Date.now(),
|
|
563
|
+
data: {
|
|
564
|
+
network: this.getEntries("network"),
|
|
565
|
+
console: this.getEntries("console"),
|
|
566
|
+
errors: this.getEntries("errors"),
|
|
567
|
+
metrics: this.getEntries("metrics")
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Loads a snapshot produced by export(), replacing the current data. Entries
|
|
573
|
+
* are validated field by field and trimmed to the configured limits.
|
|
574
|
+
*/
|
|
575
|
+
import(snapshot) {
|
|
576
|
+
const data = snapshot && typeof snapshot === "object" ? snapshot.data : void 0;
|
|
577
|
+
if (!data || typeof data !== "object") throw new TypeError("DevInspector.import() expects an object produced by export()");
|
|
578
|
+
const source = data;
|
|
579
|
+
const list = (value) => Array.isArray(value) ? value.filter((item) => !!item && typeof item === "object") : [];
|
|
580
|
+
const str = (value, fallback = "") => typeof value === "string" ? value : fallback;
|
|
581
|
+
const num = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
582
|
+
this.network = list(source.network).slice(0, this.config.maxNetworkEntries).map((item) => {
|
|
583
|
+
var _a;
|
|
584
|
+
return {
|
|
585
|
+
id: str(item.id, nextId()),
|
|
586
|
+
type: item.type === "xhr" ? "xhr" : "fetch",
|
|
587
|
+
url: str(item.url),
|
|
588
|
+
method: str(item.method, "GET"),
|
|
589
|
+
status: typeof item.status === "number" ? item.status : item.status === "pending" ? "pending" : "error",
|
|
590
|
+
timestamp: (_a = num(item.timestamp)) != null ? _a : Date.now(),
|
|
591
|
+
duration: num(item.duration),
|
|
592
|
+
error: typeof item.error === "string" ? item.error : void 0
|
|
593
|
+
};
|
|
594
|
+
});
|
|
595
|
+
this.consoleEntries = list(source.console).slice(0, this.config.maxConsoleEntries).map((item) => {
|
|
596
|
+
var _a;
|
|
597
|
+
return {
|
|
598
|
+
id: str(item.id, nextId()),
|
|
599
|
+
level: CONSOLE_METHODS.includes(item.level) ? item.level : "log",
|
|
600
|
+
message: truncate(str(item.message)),
|
|
601
|
+
timestamp: (_a = num(item.timestamp)) != null ? _a : Date.now()
|
|
602
|
+
};
|
|
603
|
+
});
|
|
604
|
+
this.errors = list(source.errors).slice(0, this.config.maxErrorEntries).map((item) => {
|
|
605
|
+
var _a;
|
|
606
|
+
return {
|
|
607
|
+
id: str(item.id, nextId()),
|
|
608
|
+
type: item.type === "Promise Rejection" ? "Promise Rejection" : "JavaScript Error",
|
|
609
|
+
message: truncate(str(item.message)),
|
|
610
|
+
timestamp: (_a = num(item.timestamp)) != null ? _a : Date.now(),
|
|
611
|
+
stack: typeof item.stack === "string" ? truncate(item.stack) : void 0
|
|
612
|
+
};
|
|
613
|
+
});
|
|
614
|
+
this.metrics = list(source.metrics).slice(0, MAX_METRIC_ENTRIES).map((item) => {
|
|
615
|
+
var _a;
|
|
616
|
+
return {
|
|
617
|
+
id: str(item.id, nextId()),
|
|
618
|
+
name: str(item.name),
|
|
619
|
+
data: item.data,
|
|
620
|
+
duration: num(item.duration),
|
|
621
|
+
timestamp: (_a = num(item.timestamp)) != null ? _a : Date.now()
|
|
622
|
+
};
|
|
623
|
+
});
|
|
624
|
+
this.selectedRequestId = null;
|
|
625
|
+
this.scheduleRender();
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Removes the UI, restores every patched API, detaches listeners, stops the
|
|
629
|
+
* frame loop and uninstalls plugins. Safe to call more than once.
|
|
630
|
+
*/
|
|
631
|
+
destroy() {
|
|
632
|
+
var _a, _b;
|
|
633
|
+
if (this.destroyed) return;
|
|
634
|
+
this.destroyed = true;
|
|
635
|
+
for (const patch of this.patches.reverse()) {
|
|
636
|
+
if (patch.target[patch.key] === patch.replacement) patch.target[patch.key] = patch.original;
|
|
637
|
+
}
|
|
638
|
+
this.patches = [];
|
|
639
|
+
for (const cleanup of this.cleanups.splice(0)) {
|
|
640
|
+
try {
|
|
641
|
+
cleanup();
|
|
642
|
+
} catch (e) {
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
this.stopPerformanceLoop();
|
|
646
|
+
(_a = this.widget) == null ? void 0 : _a.remove();
|
|
647
|
+
(_b = this.panel) == null ? void 0 : _b.remove();
|
|
648
|
+
this.widget = null;
|
|
649
|
+
this.panel = null;
|
|
650
|
+
for (const plugin of this.pluginSystem.getAll()) {
|
|
651
|
+
this.pluginSystem.unregister(plugin.name).catch((error) => this.reportInternal(`Failed to uninstall plugin "${plugin.name}"`, error));
|
|
652
|
+
}
|
|
653
|
+
this.emitSafely("inspector:destroy", void 0);
|
|
654
|
+
this.events.removeAllListeners();
|
|
655
|
+
this.network = [];
|
|
656
|
+
this.consoleEntries = [];
|
|
657
|
+
this.errors = [];
|
|
658
|
+
this.metrics = [];
|
|
659
|
+
this.marks.clear();
|
|
660
|
+
_EnhancedDevInspector.instances = _EnhancedDevInspector.instances.filter((instance) => instance !== this);
|
|
661
|
+
}
|
|
662
|
+
// ---------------------------------------------------------------------------
|
|
663
|
+
// Capture
|
|
664
|
+
// ---------------------------------------------------------------------------
|
|
665
|
+
get capturingAllowed() {
|
|
666
|
+
return !this.destroyed && this.isRecording && !this.capturing;
|
|
667
|
+
}
|
|
668
|
+
/** Runs capture code with re-entrancy protection; capture failures never reach the page. */
|
|
669
|
+
capture(fn) {
|
|
670
|
+
if (!this.capturingAllowed) return;
|
|
671
|
+
this.capturing = true;
|
|
672
|
+
try {
|
|
673
|
+
fn();
|
|
674
|
+
} catch (error) {
|
|
675
|
+
this.reportInternal("Capture failed", error);
|
|
676
|
+
} finally {
|
|
677
|
+
this.capturing = false;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
emitSafely(event, data) {
|
|
681
|
+
this.events.emit(event, data);
|
|
682
|
+
}
|
|
683
|
+
pushBounded(list, entry, max) {
|
|
684
|
+
list.unshift(entry);
|
|
685
|
+
if (list.length > max) list.length = max;
|
|
686
|
+
}
|
|
687
|
+
patch(target, key, replacement) {
|
|
688
|
+
const original = target[key];
|
|
689
|
+
target[key] = replacement;
|
|
690
|
+
this.patches.push({ target, key, original, replacement });
|
|
691
|
+
}
|
|
692
|
+
listen(target, type, handler) {
|
|
693
|
+
target.addEventListener(type, handler);
|
|
694
|
+
this.cleanups.push(() => target.removeEventListener(type, handler));
|
|
695
|
+
}
|
|
696
|
+
addNetworkEntry(entry) {
|
|
697
|
+
this.pushBounded(this.network, entry, this.config.maxNetworkEntries);
|
|
698
|
+
this.emitSafely("network:request", { ...entry });
|
|
699
|
+
this.scheduleRender();
|
|
700
|
+
}
|
|
701
|
+
finishNetworkEntry(entry, status, duration, error) {
|
|
702
|
+
entry.status = status;
|
|
703
|
+
entry.duration = Math.round(duration);
|
|
704
|
+
if (error !== void 0) entry.error = error;
|
|
705
|
+
this.emitSafely(status === "error" ? "network:error" : "network:response", { ...entry });
|
|
706
|
+
if (duration > this.config.slowRequestThreshold) {
|
|
707
|
+
const issue = { type: "slow-network", message: `Slow network request: ${entry.url}`, url: entry.url, duration: entry.duration };
|
|
708
|
+
this.emitSafely("performance:issue", issue);
|
|
709
|
+
this.callUser(this.config.onPerformanceIssue, issue);
|
|
710
|
+
}
|
|
711
|
+
this.scheduleRender();
|
|
712
|
+
}
|
|
713
|
+
interceptFetch() {
|
|
714
|
+
const originalFetch = typeof window.fetch === "function" ? window.fetch : null;
|
|
715
|
+
if (!originalFetch) return;
|
|
716
|
+
const self = this;
|
|
717
|
+
const instrumentedFetch = function(...args) {
|
|
718
|
+
let entry = null;
|
|
719
|
+
const start = performance.now();
|
|
720
|
+
self.capture(() => {
|
|
721
|
+
entry = { id: nextId(), type: "fetch", url: requestUrl(args[0]), method: requestMethod(args[0], args[1]), status: "pending", timestamp: Date.now() };
|
|
722
|
+
self.addNetworkEntry(entry);
|
|
723
|
+
});
|
|
724
|
+
if (!entry) return Reflect.apply(originalFetch, this, args);
|
|
725
|
+
const tracked = entry;
|
|
726
|
+
let result;
|
|
727
|
+
try {
|
|
728
|
+
result = Reflect.apply(originalFetch, this, args);
|
|
729
|
+
} catch (error) {
|
|
730
|
+
self.capture(() => self.finishNetworkEntry(tracked, "error", performance.now() - start, error instanceof Error ? error.message : String(error)));
|
|
731
|
+
throw error;
|
|
732
|
+
}
|
|
733
|
+
return Promise.resolve(result).then(
|
|
734
|
+
(response) => {
|
|
735
|
+
self.capture(() => self.finishNetworkEntry(tracked, response.status, performance.now() - start));
|
|
736
|
+
return response;
|
|
737
|
+
},
|
|
738
|
+
(error) => {
|
|
739
|
+
self.capture(() => self.finishNetworkEntry(tracked, "error", performance.now() - start, error instanceof Error ? error.message : String(error)));
|
|
740
|
+
throw error;
|
|
741
|
+
}
|
|
742
|
+
);
|
|
743
|
+
};
|
|
744
|
+
this.patch(window, "fetch", instrumentedFetch);
|
|
745
|
+
}
|
|
746
|
+
interceptXHR() {
|
|
747
|
+
const XHR = typeof XMLHttpRequest === "function" ? XMLHttpRequest : null;
|
|
748
|
+
if (!XHR) return;
|
|
749
|
+
const proto = XHR.prototype;
|
|
750
|
+
const originalOpen = proto.open;
|
|
751
|
+
const originalSend = proto.send;
|
|
752
|
+
const self = this;
|
|
753
|
+
const open = function(...args) {
|
|
754
|
+
if (!self.destroyed) {
|
|
755
|
+
self.xhrState.set(this, { method: typeof args[0] === "string" ? args[0].toUpperCase() : "GET", url: requestUrl(args[1]) });
|
|
756
|
+
}
|
|
757
|
+
return Reflect.apply(originalOpen, this, args);
|
|
758
|
+
};
|
|
759
|
+
const send = function(...args) {
|
|
760
|
+
const state = self.xhrState.get(this);
|
|
761
|
+
if (state) self.capture(() => self.trackXhr(this, state));
|
|
762
|
+
return Reflect.apply(originalSend, this, args);
|
|
763
|
+
};
|
|
764
|
+
this.patch(proto, "open", open);
|
|
765
|
+
this.patch(proto, "send", send);
|
|
766
|
+
}
|
|
767
|
+
trackXhr(xhr, state) {
|
|
768
|
+
const entry = { id: nextId(), type: "xhr", url: state.url, method: state.method, status: "pending", timestamp: Date.now() };
|
|
769
|
+
state.entry = entry;
|
|
770
|
+
state.start = performance.now();
|
|
771
|
+
state.failure = void 0;
|
|
772
|
+
const fail = (reason) => () => {
|
|
773
|
+
state.failure = reason;
|
|
774
|
+
};
|
|
775
|
+
const onError = fail("Network error");
|
|
776
|
+
const onAbort = fail("Request aborted");
|
|
777
|
+
const onTimeout = fail("Request timed out");
|
|
778
|
+
const onLoadEnd = () => {
|
|
779
|
+
var _a;
|
|
780
|
+
xhr.removeEventListener("error", onError);
|
|
781
|
+
xhr.removeEventListener("abort", onAbort);
|
|
782
|
+
xhr.removeEventListener("timeout", onTimeout);
|
|
783
|
+
xhr.removeEventListener("loadend", onLoadEnd);
|
|
784
|
+
if (state.entry !== entry || this.destroyed) return;
|
|
785
|
+
const duration = performance.now() - ((_a = state.start) != null ? _a : performance.now());
|
|
786
|
+
const failed = state.failure !== void 0 || xhr.status === 0;
|
|
787
|
+
this.capture(() => {
|
|
788
|
+
var _a2;
|
|
789
|
+
return this.finishNetworkEntry(entry, failed ? "error" : xhr.status, duration, failed ? (_a2 = state.failure) != null ? _a2 : "Network error" : void 0);
|
|
790
|
+
});
|
|
791
|
+
};
|
|
792
|
+
xhr.addEventListener("error", onError);
|
|
793
|
+
xhr.addEventListener("abort", onAbort);
|
|
794
|
+
xhr.addEventListener("timeout", onTimeout);
|
|
795
|
+
xhr.addEventListener("loadend", onLoadEnd);
|
|
796
|
+
this.addNetworkEntry(entry);
|
|
797
|
+
}
|
|
798
|
+
interceptConsole() {
|
|
799
|
+
const self = this;
|
|
800
|
+
for (const level of CONSOLE_METHODS) {
|
|
801
|
+
const original = console[level];
|
|
802
|
+
if (typeof original !== "function") continue;
|
|
803
|
+
const wrapper = function(...args) {
|
|
804
|
+
const result = Reflect.apply(original, this === void 0 ? console : this, args);
|
|
805
|
+
self.capture(() => {
|
|
806
|
+
const entry = {
|
|
807
|
+
id: nextId(),
|
|
808
|
+
level,
|
|
809
|
+
message: truncate(args.map(stringifyArg).join(" ")),
|
|
810
|
+
timestamp: Date.now()
|
|
811
|
+
};
|
|
812
|
+
self.pushBounded(self.consoleEntries, entry, self.config.maxConsoleEntries);
|
|
813
|
+
self.emitSafely("console:log", { ...entry });
|
|
814
|
+
self.scheduleRender();
|
|
815
|
+
});
|
|
816
|
+
return result;
|
|
817
|
+
};
|
|
818
|
+
this.patch(console, level, wrapper);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
interceptErrors() {
|
|
822
|
+
const record = (entry, error) => {
|
|
823
|
+
this.pushBounded(this.errors, entry, this.config.maxErrorEntries);
|
|
824
|
+
this.emitSafely("error:uncaught", { ...entry });
|
|
825
|
+
this.callUser(this.config.onError, error);
|
|
826
|
+
this.scheduleRender();
|
|
827
|
+
};
|
|
828
|
+
this.listen(window, "error", (event) => {
|
|
829
|
+
this.capture(() => {
|
|
830
|
+
var _a;
|
|
831
|
+
const error = event.error instanceof Error ? event.error : new Error(String((_a = event.message) != null ? _a : "Unknown error"));
|
|
832
|
+
record(
|
|
833
|
+
{
|
|
834
|
+
id: nextId(),
|
|
835
|
+
type: "JavaScript Error",
|
|
836
|
+
message: truncate(String(event.message || error.message)),
|
|
837
|
+
timestamp: Date.now(),
|
|
838
|
+
stack: this.config.captureStackTraces && error.stack ? truncate(error.stack) : void 0,
|
|
839
|
+
filename: typeof event.filename === "string" && event.filename ? event.filename : void 0,
|
|
840
|
+
lineno: typeof event.lineno === "number" ? event.lineno : void 0,
|
|
841
|
+
colno: typeof event.colno === "number" ? event.colno : void 0
|
|
842
|
+
},
|
|
843
|
+
error
|
|
844
|
+
);
|
|
845
|
+
});
|
|
846
|
+
});
|
|
847
|
+
this.listen(window, "unhandledrejection", (event) => {
|
|
848
|
+
this.capture(() => {
|
|
849
|
+
const reason = event.reason;
|
|
850
|
+
const error = reason instanceof Error ? reason : new Error(stringifyArg(reason));
|
|
851
|
+
record(
|
|
852
|
+
{
|
|
853
|
+
id: nextId(),
|
|
854
|
+
type: "Promise Rejection",
|
|
855
|
+
message: truncate(error.message),
|
|
856
|
+
timestamp: Date.now(),
|
|
857
|
+
stack: this.config.captureStackTraces && reason instanceof Error && reason.stack ? truncate(reason.stack) : void 0
|
|
858
|
+
},
|
|
859
|
+
error
|
|
860
|
+
);
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
setupHotkeys() {
|
|
865
|
+
const { toggle, minimize } = this.config.hotkeys;
|
|
866
|
+
if (!toggle && !minimize) return;
|
|
867
|
+
this.listen(document, "keydown", (event) => {
|
|
868
|
+
const combo = eventCombo(event);
|
|
869
|
+
if (toggle && combo === toggle) {
|
|
870
|
+
event.preventDefault();
|
|
871
|
+
this.toggle();
|
|
872
|
+
} else if (minimize && combo === minimize) {
|
|
873
|
+
event.preventDefault();
|
|
874
|
+
if (!this.isVisible) this.show();
|
|
875
|
+
this.minimize();
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
/** Calls a user callback; a throwing callback is reported but never breaks capture. */
|
|
880
|
+
callUser(callback, value) {
|
|
881
|
+
if (!callback) return;
|
|
882
|
+
try {
|
|
883
|
+
callback(value);
|
|
884
|
+
} catch (error) {
|
|
885
|
+
this.reportInternal("A DevInspector callback threw", error);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
reportInternal(message, error) {
|
|
889
|
+
const patched = this.patches.find((patch) => patch.target === console && patch.key === "error");
|
|
890
|
+
const log = patched ? patched.original : console.error;
|
|
891
|
+
try {
|
|
892
|
+
log.call(console, `[DevInspector] ${message}:`, error);
|
|
893
|
+
} catch (e) {
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
// ---------------------------------------------------------------------------
|
|
897
|
+
// Performance loop (runs only while the panel is visible)
|
|
898
|
+
// ---------------------------------------------------------------------------
|
|
899
|
+
startPerformanceLoop() {
|
|
900
|
+
if (!this.config.features.performance || this.rafId !== null || typeof requestAnimationFrame !== "function") return;
|
|
901
|
+
let last = performance.now();
|
|
902
|
+
let frames = 0;
|
|
903
|
+
const tick = () => {
|
|
904
|
+
if (this.destroyed || !this.isVisible) {
|
|
905
|
+
this.rafId = null;
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
frames++;
|
|
909
|
+
const now = performance.now();
|
|
910
|
+
if (now - last >= 1e3) {
|
|
911
|
+
this.performanceStats.fps = Math.round(frames * 1e3 / (now - last));
|
|
912
|
+
frames = 0;
|
|
913
|
+
last = now;
|
|
914
|
+
const memory = performance.memory;
|
|
915
|
+
if (memory) {
|
|
916
|
+
this.performanceStats.memory = {
|
|
917
|
+
used: Math.round(memory.usedJSHeapSize / 1048576),
|
|
918
|
+
total: Math.round(memory.totalJSHeapSize / 1048576),
|
|
919
|
+
limit: Math.round(memory.jsHeapSizeLimit / 1048576)
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
if (this.activeTab === "performance") this.scheduleRender();
|
|
923
|
+
}
|
|
924
|
+
this.rafId = requestAnimationFrame(tick);
|
|
925
|
+
};
|
|
926
|
+
this.rafId = requestAnimationFrame(tick);
|
|
927
|
+
}
|
|
928
|
+
stopPerformanceLoop() {
|
|
929
|
+
if (this.rafId !== null && typeof cancelAnimationFrame === "function") cancelAnimationFrame(this.rafId);
|
|
930
|
+
this.rafId = null;
|
|
931
|
+
}
|
|
932
|
+
// ---------------------------------------------------------------------------
|
|
933
|
+
// UI
|
|
934
|
+
// ---------------------------------------------------------------------------
|
|
935
|
+
mountWhenReady() {
|
|
936
|
+
if (document.body) {
|
|
937
|
+
this.mount();
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
const onReady = () => {
|
|
941
|
+
if (!this.destroyed && !this.widget) this.mount();
|
|
942
|
+
};
|
|
943
|
+
this.listen(document, "DOMContentLoaded", onReady);
|
|
944
|
+
}
|
|
945
|
+
get colors() {
|
|
946
|
+
return PALETTES[this.config.theme];
|
|
947
|
+
}
|
|
948
|
+
placement(offset) {
|
|
949
|
+
const [vertical, horizontal] = this.config.position.split("-");
|
|
950
|
+
return `${vertical}: ${offset}px; ${horizontal}: ${offset}px;`;
|
|
951
|
+
}
|
|
952
|
+
mount() {
|
|
953
|
+
const widget = document.createElement("div");
|
|
954
|
+
widget.className = "devinspector-widget";
|
|
955
|
+
widget.setAttribute("role", "button");
|
|
956
|
+
widget.setAttribute("aria-label", "Open DevInspector");
|
|
957
|
+
widget.title = "DevInspector";
|
|
958
|
+
widget.textContent = "\u{1F50D}";
|
|
959
|
+
widget.style.cssText = `position: fixed; ${this.placement(24)} width: 56px; height: 56px;
|
|
960
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 50%;
|
|
961
|
+
display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 999999;
|
|
962
|
+
color: white; font-size: 24px; box-shadow: 0 8px 32px rgba(102, 126, 234, 0.4); user-select: none;`;
|
|
963
|
+
widget.addEventListener("click", () => this.toggle());
|
|
964
|
+
const panel = document.createElement("div");
|
|
965
|
+
panel.className = "devinspector-panel";
|
|
966
|
+
panel.style.cssText = `position: fixed; ${this.placement(24)} width: 480px; max-width: calc(100vw - 48px);
|
|
967
|
+
height: 650px; max-height: calc(100vh - 48px); background: ${this.colors.bg}; border: 1px solid ${this.colors.border};
|
|
968
|
+
border-radius: 12px; display: none; flex-direction: column; z-index: 999998; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
|
|
969
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 13px;
|
|
970
|
+
color: ${this.colors.text}; overflow: hidden;`;
|
|
971
|
+
panel.addEventListener("click", (event) => this.handlePanelClick(event));
|
|
972
|
+
this.widget = widget;
|
|
973
|
+
this.panel = panel;
|
|
974
|
+
document.body.appendChild(widget);
|
|
975
|
+
document.body.appendChild(panel);
|
|
976
|
+
this.render();
|
|
977
|
+
}
|
|
978
|
+
handlePanelClick(event) {
|
|
979
|
+
var _a, _b;
|
|
980
|
+
const target = event.target;
|
|
981
|
+
const actionable = (_a = target == null ? void 0 : target.closest) == null ? void 0 : _a.call(target, "[data-action]");
|
|
982
|
+
if (!actionable) return;
|
|
983
|
+
const action = actionable.getAttribute("data-action");
|
|
984
|
+
switch (action) {
|
|
985
|
+
case "minimize":
|
|
986
|
+
this.minimize();
|
|
987
|
+
break;
|
|
988
|
+
case "close":
|
|
989
|
+
this.hide();
|
|
990
|
+
break;
|
|
991
|
+
case "tab": {
|
|
992
|
+
const tab = actionable.getAttribute("data-tab");
|
|
993
|
+
if (["network", "console", "performance", "errors"].includes(tab)) {
|
|
994
|
+
this.activeTab = tab;
|
|
995
|
+
this.render();
|
|
996
|
+
}
|
|
997
|
+
break;
|
|
998
|
+
}
|
|
999
|
+
case "clear":
|
|
1000
|
+
this.clear((_b = actionable.getAttribute("data-target")) != null ? _b : "all");
|
|
1001
|
+
break;
|
|
1002
|
+
case "toggle-recording":
|
|
1003
|
+
this.toggleRecording();
|
|
1004
|
+
break;
|
|
1005
|
+
case "select-request":
|
|
1006
|
+
this.selectedRequestId = actionable.getAttribute("data-id");
|
|
1007
|
+
this.render();
|
|
1008
|
+
break;
|
|
1009
|
+
case "close-details":
|
|
1010
|
+
this.selectedRequestId = null;
|
|
1011
|
+
this.render();
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
/** Coalesces renders triggered by bursts of captured events into one microtask. */
|
|
1016
|
+
scheduleRender() {
|
|
1017
|
+
if (this.renderQueued || !this.panel || !this.isVisible) return;
|
|
1018
|
+
this.renderQueued = true;
|
|
1019
|
+
queueMicrotask(() => {
|
|
1020
|
+
this.renderQueued = false;
|
|
1021
|
+
if (!this.destroyed) this.render();
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
render() {
|
|
1025
|
+
if (!this.panel || !this.isVisible) return;
|
|
1026
|
+
const c = this.colors;
|
|
1027
|
+
const button = (action, label, extra = "", background = "#374151") => `<button type="button" data-action="${action}" ${extra} style="padding: 6px 12px; background: ${background}; border: none; color: white; cursor: pointer; border-radius: 6px; margin-right: 8px;">${label}</button>`;
|
|
1028
|
+
const tabs = [
|
|
1029
|
+
{ id: "network", label: "Network", count: this.network.length },
|
|
1030
|
+
{ id: "console", label: "Console", count: this.consoleEntries.length },
|
|
1031
|
+
{ id: "performance", label: "Performance" },
|
|
1032
|
+
{ id: "errors", label: "Errors", count: this.errors.length }
|
|
1033
|
+
];
|
|
1034
|
+
const header = `
|
|
1035
|
+
<div style="display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: ${c.header}; border-bottom: 1px solid ${c.border};">
|
|
1036
|
+
<div style="display: flex; align-items: center; gap: 8px;">
|
|
1037
|
+
<span style="width: 8px; height: 8px; border-radius: 50%; background: ${this.isRecording ? "#ef4444" : "#6b7280"};"></span>
|
|
1038
|
+
<span style="font-weight: 600; font-size: 14px;">DevInspector v${escapeHtml(VERSION)}</span>
|
|
1039
|
+
</div>
|
|
1040
|
+
<div style="display: flex; gap: 4px;">
|
|
1041
|
+
<button type="button" data-action="minimize" aria-label="Minimize" style="padding: 6px; background: none; border: none; color: ${c.muted}; cursor: pointer;">\u2212</button>
|
|
1042
|
+
<button type="button" data-action="close" aria-label="Close" style="padding: 6px; background: none; border: none; color: ${c.muted}; cursor: pointer;">\xD7</button>
|
|
1043
|
+
</div>
|
|
1044
|
+
</div>`;
|
|
1045
|
+
if (this.isMinimized) {
|
|
1046
|
+
this.panel.innerHTML = header;
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
const tabBar = tabs.map(
|
|
1050
|
+
(tab) => `<button type="button" data-action="tab" data-tab="${tab.id}" style="padding: 12px 16px; border: none; cursor: pointer;
|
|
1051
|
+
background: ${this.activeTab === tab.id ? c.bg : "transparent"}; color: ${this.activeTab === tab.id ? "#3b82f6" : c.muted};
|
|
1052
|
+
border-bottom: 2px solid ${this.activeTab === tab.id ? "#3b82f6" : "transparent"};">${tab.label}${tab.count !== void 0 ? ` <span style="background: #374151; color: white; padding: 2px 6px; border-radius: 10px; font-size: 11px; margin-left: 4px;">${tab.count}</span>` : ""}</button>`
|
|
1053
|
+
).join("");
|
|
1054
|
+
let content = "";
|
|
1055
|
+
switch (this.activeTab) {
|
|
1056
|
+
case "network":
|
|
1057
|
+
content = this.renderNetwork(button);
|
|
1058
|
+
break;
|
|
1059
|
+
case "console":
|
|
1060
|
+
content = this.renderConsole(button);
|
|
1061
|
+
break;
|
|
1062
|
+
case "performance":
|
|
1063
|
+
content = this.renderPerformance(button);
|
|
1064
|
+
break;
|
|
1065
|
+
case "errors":
|
|
1066
|
+
content = this.renderErrors(button);
|
|
1067
|
+
break;
|
|
1068
|
+
}
|
|
1069
|
+
this.panel.innerHTML = `${header}
|
|
1070
|
+
<div style="display: flex; background: ${c.header}; border-bottom: 1px solid ${c.border};">${tabBar}</div>
|
|
1071
|
+
<div style="flex: 1; min-height: 0; display: flex; flex-direction: column;">${content}</div>`;
|
|
1072
|
+
}
|
|
1073
|
+
toolbar(buttons, summary) {
|
|
1074
|
+
const c = this.colors;
|
|
1075
|
+
return `<div style="padding: 12px; border-bottom: 1px solid ${c.border}; background: ${c.toolbar}; display: flex; align-items: center;">
|
|
1076
|
+
${buttons}<span style="margin-left: auto; color: ${c.muted}; font-size: 12px;">${summary}</span></div>`;
|
|
1077
|
+
}
|
|
1078
|
+
empty(text) {
|
|
1079
|
+
return `<div style="display: flex; align-items: center; justify-content: center; height: 200px; color: ${this.colors.muted};">${text}</div>`;
|
|
1080
|
+
}
|
|
1081
|
+
renderNetwork(button) {
|
|
1082
|
+
var _a;
|
|
1083
|
+
const c = this.colors;
|
|
1084
|
+
const visible = this.config.hideAssets ? this.network.filter((entry) => !ASSET_PATTERN.test(entry.url)) : this.network;
|
|
1085
|
+
const rows = visible.map((entry) => {
|
|
1086
|
+
var _a2;
|
|
1087
|
+
const selected2 = entry.id === this.selectedRequestId;
|
|
1088
|
+
return `<div data-action="select-request" data-id="${escapeHtml(entry.id)}" style="padding: 10px 16px; border-bottom: 1px solid ${c.row}; cursor: pointer; ${selected2 ? "background: rgba(59, 130, 246, 0.25);" : ""}">
|
|
1089
|
+
<div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
|
|
1090
|
+
<div style="display: flex; gap: 8px;">
|
|
1091
|
+
<span style="background: ${methodColor(entry.method)}; color: white; padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: 600;">${escapeHtml(entry.method)}</span>
|
|
1092
|
+
<span style="color: ${statusColor(entry.status)}; font-weight: 600;">${escapeHtml(entry.status)}</span>
|
|
1093
|
+
<span style="color: ${c.muted};">${(_a2 = entry.duration) != null ? _a2 : "-"}ms</span>
|
|
1094
|
+
</div>
|
|
1095
|
+
<span style="color: ${c.muted}; font-size: 11px;">${escapeHtml(new Date(entry.timestamp).toLocaleTimeString())}</span>
|
|
1096
|
+
</div>
|
|
1097
|
+
<div style="font-size: 12px; word-break: break-all;">${escapeHtml(entry.url)}</div>
|
|
1098
|
+
</div>`;
|
|
1099
|
+
}).join("");
|
|
1100
|
+
const selected = this.selectedRequestId ? this.network.find((entry) => entry.id === this.selectedRequestId) : void 0;
|
|
1101
|
+
const details = selected ? `<div style="border-top: 1px solid ${c.border}; max-height: 200px; overflow-y: auto; background: ${c.toolbar}; padding: 12px 16px; font-size: 12px;">
|
|
1102
|
+
<div style="display: flex; justify-content: space-between; margin-bottom: 8px;"><strong>Request details</strong>
|
|
1103
|
+
<button type="button" data-action="close-details" aria-label="Close details" style="background: none; border: none; color: ${c.muted}; cursor: pointer;">\xD7</button></div>
|
|
1104
|
+
<div><strong>URL:</strong> ${escapeHtml(selected.url)}</div>
|
|
1105
|
+
<div><strong>Method:</strong> ${escapeHtml(selected.method)}</div>
|
|
1106
|
+
<div><strong>Type:</strong> ${escapeHtml(selected.type)}</div>
|
|
1107
|
+
<div><strong>Status:</strong> ${escapeHtml(selected.status)}</div>
|
|
1108
|
+
<div><strong>Duration:</strong> ${(_a = selected.duration) != null ? _a : "-"}ms</div>
|
|
1109
|
+
${selected.error ? `<div><strong>Error:</strong> ${escapeHtml(selected.error)}</div>` : ""}
|
|
1110
|
+
</div>` : "";
|
|
1111
|
+
return `${this.toolbar(
|
|
1112
|
+
button("clear", "Clear", 'data-target="network"') + button("toggle-recording", this.isRecording ? "Pause" : "Resume", "", this.isRecording ? "#ef4444" : "#22c55e"),
|
|
1113
|
+
`${visible.length} requests`
|
|
1114
|
+
)}
|
|
1115
|
+
<div style="flex: 1; overflow-y: auto;">${rows || this.empty("No network activity")}</div>${details}`;
|
|
1116
|
+
}
|
|
1117
|
+
renderConsole(button) {
|
|
1118
|
+
const c = this.colors;
|
|
1119
|
+
const rows = this.consoleEntries.map(
|
|
1120
|
+
(entry) => `<div style="padding: 8px 16px; border-bottom: 1px solid ${c.row}; font-size: 12px;">
|
|
1121
|
+
<span style="color: ${levelColor(entry.level)}; text-transform: uppercase; font-weight: 600;">[${escapeHtml(entry.level)}]</span>
|
|
1122
|
+
<span style="color: ${c.muted}; margin: 0 8px;">${escapeHtml(new Date(entry.timestamp).toLocaleTimeString())}</span>
|
|
1123
|
+
<span style="white-space: pre-wrap; word-break: break-word;">${escapeHtml(entry.message)}</span>
|
|
1124
|
+
</div>`
|
|
1125
|
+
).join("");
|
|
1126
|
+
return `${this.toolbar(button("clear", "Clear", 'data-target="console"'), `${this.consoleEntries.length} logs`)}
|
|
1127
|
+
<div style="flex: 1; overflow-y: auto; font-family: monospace;">${rows || this.empty("No console logs")}</div>`;
|
|
1128
|
+
}
|
|
1129
|
+
renderPerformance(button) {
|
|
1130
|
+
const c = this.colors;
|
|
1131
|
+
const { fps, memory } = this.performanceStats;
|
|
1132
|
+
const rows = this.metrics.slice(0, 100).map(
|
|
1133
|
+
(metric) => `<div style="padding: 6px 0; border-bottom: 1px solid ${c.row}; font-size: 12px;">
|
|
1134
|
+
<strong>${escapeHtml(metric.name)}</strong>
|
|
1135
|
+
${metric.duration !== void 0 ? `<span style="color: ${c.muted};"> ${metric.duration.toFixed(1)}ms</span>` : ""}
|
|
1136
|
+
${metric.data !== void 0 ? `<span style="color: ${c.muted};"> ${escapeHtml(truncate(stringifyArg(metric.data)))}</span>` : ""}
|
|
1137
|
+
</div>`
|
|
1138
|
+
).join("");
|
|
1139
|
+
return `${this.toolbar(button("clear", "Clear", 'data-target="metrics"'), `${this.metrics.length} metrics`)}
|
|
1140
|
+
<div style="flex: 1; overflow-y: auto; padding: 16px;">
|
|
1141
|
+
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px;">
|
|
1142
|
+
<div style="background: #1e3a8a; border-radius: 12px; padding: 16px; text-align: center;">
|
|
1143
|
+
<div style="font-size: 28px; font-weight: 700; color: #93c5fd;">${this.config.features.performance ? fps : "-"}</div>
|
|
1144
|
+
<div style="font-size: 12px; color: #bfdbfe;">FPS</div>
|
|
1145
|
+
</div>
|
|
1146
|
+
<div style="background: #166534; border-radius: 12px; padding: 16px; text-align: center;">
|
|
1147
|
+
<div style="font-size: 28px; font-weight: 700; color: #86efac;">${memory ? `${memory.used} MB` : "N/A"}</div>
|
|
1148
|
+
<div style="font-size: 12px; color: #bbf7d0;">Memory</div>
|
|
1149
|
+
</div>
|
|
1150
|
+
</div>
|
|
1151
|
+
${rows || `<div style="color: ${c.muted};">Use track(), markStart() and markEnd() to record metrics.</div>`}
|
|
1152
|
+
</div>`;
|
|
1153
|
+
}
|
|
1154
|
+
renderErrors(button) {
|
|
1155
|
+
const c = this.colors;
|
|
1156
|
+
const rows = this.errors.map(
|
|
1157
|
+
(error) => `<div style="padding: 12px 16px; border-bottom: 1px solid ${c.row};">
|
|
1158
|
+
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
|
|
1159
|
+
<span style="color: #ef4444; font-weight: 600;">${escapeHtml(error.type)}</span>
|
|
1160
|
+
<span style="color: ${c.muted}; font-size: 11px;">${escapeHtml(new Date(error.timestamp).toLocaleTimeString())}</span>
|
|
1161
|
+
</div>
|
|
1162
|
+
<div style="color: #f87171; margin-bottom: 6px; word-break: break-word;">${escapeHtml(error.message)}</div>
|
|
1163
|
+
${error.stack ? `<pre style="background: ${c.code}; padding: 8px; border-radius: 4px; font-size: 11px; color: ${c.muted}; overflow-x: auto; white-space: pre-wrap;">${escapeHtml(error.stack)}</pre>` : ""}
|
|
1164
|
+
</div>`
|
|
1165
|
+
).join("");
|
|
1166
|
+
return `${this.toolbar(button("clear", "Clear", 'data-target="errors"'), `${this.errors.length} errors`)}
|
|
1167
|
+
<div style="flex: 1; overflow-y: auto;">${rows || this.empty("No errors recorded")}</div>`;
|
|
1168
|
+
}
|
|
1169
|
+
};
|
|
1170
|
+
_EnhancedDevInspector.instances = [];
|
|
1171
|
+
var EnhancedDevInspector = _EnhancedDevInspector;
|
|
1172
|
+
function statusColor(status) {
|
|
1173
|
+
if (typeof status !== "number") return "#6b7280";
|
|
1174
|
+
if (status >= 200 && status < 300) return "#22c55e";
|
|
1175
|
+
if (status >= 300 && status < 400) return "#f59e0b";
|
|
1176
|
+
if (status >= 400) return "#ef4444";
|
|
1177
|
+
return "#6b7280";
|
|
1178
|
+
}
|
|
1179
|
+
function methodColor(method) {
|
|
1180
|
+
switch (method) {
|
|
1181
|
+
case "GET":
|
|
1182
|
+
return "#16a34a";
|
|
1183
|
+
case "POST":
|
|
1184
|
+
return "#2563eb";
|
|
1185
|
+
case "PUT":
|
|
1186
|
+
return "#d97706";
|
|
1187
|
+
case "DELETE":
|
|
1188
|
+
return "#dc2626";
|
|
1189
|
+
case "PATCH":
|
|
1190
|
+
return "#7c3aed";
|
|
1191
|
+
default:
|
|
1192
|
+
return "#6b7280";
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
function levelColor(level) {
|
|
1196
|
+
switch (level) {
|
|
1197
|
+
case "info":
|
|
1198
|
+
return "#60a5fa";
|
|
1199
|
+
case "warn":
|
|
1200
|
+
return "#fbbf24";
|
|
1201
|
+
case "error":
|
|
1202
|
+
return "#f87171";
|
|
1203
|
+
case "debug":
|
|
1204
|
+
return "#a78bfa";
|
|
1205
|
+
default:
|
|
1206
|
+
return "inherit";
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
// src/core/storage.ts
|
|
1211
|
+
var CircularStorage = class {
|
|
1212
|
+
constructor(options) {
|
|
1213
|
+
this.head = 0;
|
|
1214
|
+
this.tail = 0;
|
|
1215
|
+
this.size = 0;
|
|
1216
|
+
this.idCounter = 0;
|
|
1217
|
+
this.maxSize = options.maxSize;
|
|
1218
|
+
this.ttl = options.ttl;
|
|
1219
|
+
this.onEvict = options.onEvict;
|
|
1220
|
+
this.buffer = new Array(this.maxSize);
|
|
1221
|
+
}
|
|
1222
|
+
push(data) {
|
|
1223
|
+
const id = `${Date.now()}-${++this.idCounter}`;
|
|
1224
|
+
const entry = {
|
|
1225
|
+
id,
|
|
1226
|
+
timestamp: Date.now(),
|
|
1227
|
+
data
|
|
1228
|
+
};
|
|
1229
|
+
if (this.size === this.maxSize) {
|
|
1230
|
+
const evictedEntry = this.buffer[this.tail];
|
|
1231
|
+
if (evictedEntry && this.onEvict) {
|
|
1232
|
+
this.onEvict(evictedEntry);
|
|
1233
|
+
}
|
|
1234
|
+
this.tail = (this.tail + 1) % this.maxSize;
|
|
1235
|
+
} else {
|
|
1236
|
+
this.size++;
|
|
1237
|
+
}
|
|
1238
|
+
this.buffer[this.head] = entry;
|
|
1239
|
+
this.head = (this.head + 1) % this.maxSize;
|
|
1240
|
+
return id;
|
|
1241
|
+
}
|
|
1242
|
+
get(id) {
|
|
1243
|
+
const entry = this.findEntry(id);
|
|
1244
|
+
if (entry && !this.isExpired(entry)) {
|
|
1245
|
+
return entry.data;
|
|
1246
|
+
}
|
|
1247
|
+
return void 0;
|
|
1248
|
+
}
|
|
1249
|
+
getAll() {
|
|
1250
|
+
return this.getAllEntries().map((entry) => entry.data);
|
|
1251
|
+
}
|
|
1252
|
+
getAllEntries() {
|
|
1253
|
+
const entries = [];
|
|
1254
|
+
const now = Date.now();
|
|
1255
|
+
for (let i = 0; i < this.size; i++) {
|
|
1256
|
+
const index = (this.tail + i) % this.maxSize;
|
|
1257
|
+
const entry = this.buffer[index];
|
|
1258
|
+
if (entry && !this.isExpired(entry, now)) {
|
|
1259
|
+
entries.push(entry);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
return entries;
|
|
1263
|
+
}
|
|
1264
|
+
find(predicate) {
|
|
1265
|
+
const entries = this.getAllEntries();
|
|
1266
|
+
for (const entry of entries) {
|
|
1267
|
+
if (predicate(entry.data)) {
|
|
1268
|
+
return entry.data;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
return void 0;
|
|
1272
|
+
}
|
|
1273
|
+
filter(predicate) {
|
|
1274
|
+
return this.getAllEntries().filter((entry) => predicate(entry.data)).map((entry) => entry.data);
|
|
1275
|
+
}
|
|
1276
|
+
clear() {
|
|
1277
|
+
this.buffer = new Array(this.maxSize);
|
|
1278
|
+
this.head = 0;
|
|
1279
|
+
this.tail = 0;
|
|
1280
|
+
this.size = 0;
|
|
1281
|
+
}
|
|
1282
|
+
getSize() {
|
|
1283
|
+
return this.size;
|
|
1284
|
+
}
|
|
1285
|
+
isFull() {
|
|
1286
|
+
return this.size === this.maxSize;
|
|
1287
|
+
}
|
|
1288
|
+
findEntry(id) {
|
|
1289
|
+
for (let i = 0; i < this.size; i++) {
|
|
1290
|
+
const index = (this.tail + i) % this.maxSize;
|
|
1291
|
+
const entry = this.buffer[index];
|
|
1292
|
+
if (entry && entry.id === id) {
|
|
1293
|
+
return entry;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
return void 0;
|
|
1297
|
+
}
|
|
1298
|
+
isExpired(entry, now = Date.now()) {
|
|
1299
|
+
if (!this.ttl) return false;
|
|
1300
|
+
return now - entry.timestamp > this.ttl;
|
|
1301
|
+
}
|
|
1302
|
+
removeExpired() {
|
|
1303
|
+
if (!this.ttl) return 0;
|
|
1304
|
+
const now = Date.now();
|
|
1305
|
+
let removedCount = 0;
|
|
1306
|
+
const validEntries = [];
|
|
1307
|
+
for (let i = 0; i < this.size; i++) {
|
|
1308
|
+
const index = (this.tail + i) % this.maxSize;
|
|
1309
|
+
const entry = this.buffer[index];
|
|
1310
|
+
if (entry && !this.isExpired(entry, now)) {
|
|
1311
|
+
validEntries.push(entry);
|
|
1312
|
+
} else if (entry && this.onEvict) {
|
|
1313
|
+
this.onEvict(entry);
|
|
1314
|
+
removedCount++;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
this.buffer = new Array(this.maxSize);
|
|
1318
|
+
this.size = validEntries.length;
|
|
1319
|
+
this.tail = 0;
|
|
1320
|
+
this.head = this.size;
|
|
1321
|
+
validEntries.forEach((entry, i) => {
|
|
1322
|
+
this.buffer[i] = entry;
|
|
1323
|
+
});
|
|
1324
|
+
return removedCount;
|
|
1325
|
+
}
|
|
1326
|
+
};
|
|
1327
|
+
var IndexedStorage = class {
|
|
1328
|
+
constructor(options) {
|
|
1329
|
+
this.storage = /* @__PURE__ */ new Map();
|
|
1330
|
+
this.accessOrder = [];
|
|
1331
|
+
this.maxSize = options.maxSize;
|
|
1332
|
+
this.ttl = options.ttl;
|
|
1333
|
+
this.onEvict = options.onEvict;
|
|
1334
|
+
}
|
|
1335
|
+
set(key, data) {
|
|
1336
|
+
const entry = {
|
|
1337
|
+
id: key,
|
|
1338
|
+
timestamp: Date.now(),
|
|
1339
|
+
data
|
|
1340
|
+
};
|
|
1341
|
+
if (this.storage.has(key)) {
|
|
1342
|
+
const index = this.accessOrder.indexOf(key);
|
|
1343
|
+
if (index > -1) {
|
|
1344
|
+
this.accessOrder.splice(index, 1);
|
|
1345
|
+
}
|
|
1346
|
+
} else if (this.storage.size >= this.maxSize) {
|
|
1347
|
+
const evictKey = this.accessOrder.shift();
|
|
1348
|
+
if (evictKey) {
|
|
1349
|
+
const evictedEntry = this.storage.get(evictKey);
|
|
1350
|
+
if (evictedEntry && this.onEvict) {
|
|
1351
|
+
this.onEvict(evictedEntry);
|
|
1352
|
+
}
|
|
1353
|
+
this.storage.delete(evictKey);
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
this.storage.set(key, entry);
|
|
1357
|
+
this.accessOrder.push(key);
|
|
1358
|
+
}
|
|
1359
|
+
get(key) {
|
|
1360
|
+
const entry = this.storage.get(key);
|
|
1361
|
+
if (entry && !this.isExpired(entry)) {
|
|
1362
|
+
this.updateAccessOrder(key);
|
|
1363
|
+
return entry.data;
|
|
1364
|
+
} else if (entry) {
|
|
1365
|
+
this.delete(key);
|
|
1366
|
+
}
|
|
1367
|
+
return void 0;
|
|
1368
|
+
}
|
|
1369
|
+
has(key) {
|
|
1370
|
+
const entry = this.storage.get(key);
|
|
1371
|
+
if (entry && !this.isExpired(entry)) {
|
|
1372
|
+
return true;
|
|
1373
|
+
} else if (entry) {
|
|
1374
|
+
this.delete(key);
|
|
1375
|
+
}
|
|
1376
|
+
return false;
|
|
1377
|
+
}
|
|
1378
|
+
delete(key) {
|
|
1379
|
+
const entry = this.storage.get(key);
|
|
1380
|
+
if (entry) {
|
|
1381
|
+
if (this.onEvict) {
|
|
1382
|
+
this.onEvict(entry);
|
|
1383
|
+
}
|
|
1384
|
+
this.storage.delete(key);
|
|
1385
|
+
this.accessOrder = this.accessOrder.filter((k) => k !== key);
|
|
1386
|
+
return true;
|
|
1387
|
+
}
|
|
1388
|
+
return false;
|
|
1389
|
+
}
|
|
1390
|
+
clear() {
|
|
1391
|
+
if (this.onEvict) {
|
|
1392
|
+
this.storage.forEach((entry) => this.onEvict(entry));
|
|
1393
|
+
}
|
|
1394
|
+
this.storage.clear();
|
|
1395
|
+
this.accessOrder = [];
|
|
1396
|
+
}
|
|
1397
|
+
getSize() {
|
|
1398
|
+
return this.storage.size;
|
|
1399
|
+
}
|
|
1400
|
+
getAllKeys() {
|
|
1401
|
+
return Array.from(this.storage.keys());
|
|
1402
|
+
}
|
|
1403
|
+
getAllValues() {
|
|
1404
|
+
return Array.from(this.storage.values()).filter((entry) => !this.isExpired(entry)).map((entry) => entry.data);
|
|
1405
|
+
}
|
|
1406
|
+
updateAccessOrder(key) {
|
|
1407
|
+
const index = this.accessOrder.indexOf(key);
|
|
1408
|
+
if (index > -1) {
|
|
1409
|
+
this.accessOrder.splice(index, 1);
|
|
1410
|
+
}
|
|
1411
|
+
this.accessOrder.push(key);
|
|
1412
|
+
}
|
|
1413
|
+
isExpired(entry) {
|
|
1414
|
+
if (!this.ttl) return false;
|
|
1415
|
+
return Date.now() - entry.timestamp > this.ttl;
|
|
1416
|
+
}
|
|
1417
|
+
removeExpired() {
|
|
1418
|
+
let removedCount = 0;
|
|
1419
|
+
const expiredKeys = [];
|
|
1420
|
+
this.storage.forEach((entry, key) => {
|
|
1421
|
+
if (this.isExpired(entry)) {
|
|
1422
|
+
expiredKeys.push(key);
|
|
1423
|
+
}
|
|
1424
|
+
});
|
|
1425
|
+
expiredKeys.forEach((key) => {
|
|
1426
|
+
if (this.delete(key)) {
|
|
1427
|
+
removedCount++;
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
1430
|
+
return removedCount;
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
|
|
1434
|
+
// src/core/inspector.ts
|
|
1435
|
+
var _DevInspector = class _DevInspector {
|
|
1436
|
+
constructor(config = {}) {
|
|
1437
|
+
this.isVisible = false;
|
|
1438
|
+
this.isMinimized = false;
|
|
1439
|
+
this.monitors = /* @__PURE__ */ new Map();
|
|
1440
|
+
this.ui = null;
|
|
1441
|
+
this.initialized = false;
|
|
1442
|
+
this.cleanupFunctions = [];
|
|
1443
|
+
this.initPromise = null;
|
|
1444
|
+
this.destroyed = false;
|
|
1445
|
+
if (_DevInspector.instance) {
|
|
1446
|
+
console.warn("DevInspector instance already exists. Returning existing instance.");
|
|
1447
|
+
return _DevInspector.instance;
|
|
1448
|
+
}
|
|
1449
|
+
this.config = this.mergeConfig(config);
|
|
1450
|
+
this.events = new EventEmitter({ maxListeners: 100 });
|
|
1451
|
+
this.networkStorage = new CircularStorage({
|
|
1452
|
+
maxSize: this.config.maxNetworkEntries,
|
|
1453
|
+
onEvict: (entry) => this.events.emit("network:evict", entry)
|
|
1454
|
+
});
|
|
1455
|
+
this.consoleStorage = new CircularStorage({
|
|
1456
|
+
maxSize: this.config.maxConsoleEntries,
|
|
1457
|
+
onEvict: (entry) => this.events.emit("console:evict", entry)
|
|
1458
|
+
});
|
|
1459
|
+
this.performanceStorage = new IndexedStorage({
|
|
1460
|
+
maxSize: 1e3,
|
|
1461
|
+
ttl: 60 * 60 * 1e3
|
|
1462
|
+
// 1 hour
|
|
1463
|
+
});
|
|
1464
|
+
this.errorStorage = new CircularStorage({
|
|
1465
|
+
maxSize: this.config.maxErrorEntries,
|
|
1466
|
+
onEvict: (entry) => this.events.emit("error:evict", entry)
|
|
1467
|
+
});
|
|
1468
|
+
this.pluginSystem = new PluginSystem({
|
|
1469
|
+
inspector: this,
|
|
1470
|
+
storage: {
|
|
1471
|
+
network: this.networkStorage,
|
|
1472
|
+
console: this.consoleStorage,
|
|
1473
|
+
performance: this.performanceStorage,
|
|
1474
|
+
error: this.errorStorage
|
|
1475
|
+
},
|
|
1476
|
+
events: this.events,
|
|
1477
|
+
config: this.config
|
|
1478
|
+
});
|
|
1479
|
+
if (this.config.enabled) {
|
|
1480
|
+
this.init();
|
|
1481
|
+
}
|
|
1482
|
+
_DevInspector.instance = this;
|
|
1483
|
+
}
|
|
1484
|
+
mergeConfig(config) {
|
|
1485
|
+
const defaultConfig = {
|
|
1486
|
+
enabled: defaultEnabled(),
|
|
1487
|
+
position: "bottom-right",
|
|
1488
|
+
theme: "auto",
|
|
1489
|
+
hotkeys: {
|
|
1490
|
+
toggle: "ctrl+shift+d",
|
|
1491
|
+
minimize: "ctrl+shift+m"
|
|
1492
|
+
},
|
|
1493
|
+
features: {
|
|
1494
|
+
network: true,
|
|
1495
|
+
console: true,
|
|
1496
|
+
performance: true,
|
|
1497
|
+
errors: true,
|
|
1498
|
+
state: true,
|
|
1499
|
+
dom: true,
|
|
1500
|
+
storage: true
|
|
1501
|
+
},
|
|
1502
|
+
plugins: [],
|
|
1503
|
+
maxNetworkEntries: 1e3,
|
|
1504
|
+
maxConsoleEntries: 500,
|
|
1505
|
+
captureStackTraces: true,
|
|
1506
|
+
networkFilters: {
|
|
1507
|
+
hideAssets: false,
|
|
1508
|
+
hideCached: false
|
|
1509
|
+
},
|
|
1510
|
+
onError: () => {
|
|
1511
|
+
},
|
|
1512
|
+
onPerformanceIssue: () => {
|
|
1513
|
+
},
|
|
1514
|
+
maxErrorEntries: 100,
|
|
1515
|
+
slowRequestThreshold: 3e3,
|
|
1516
|
+
workerUrl: void 0,
|
|
1517
|
+
remoteConfig: null
|
|
1518
|
+
};
|
|
1519
|
+
return {
|
|
1520
|
+
...defaultConfig,
|
|
1521
|
+
...config,
|
|
1522
|
+
hotkeys: { ...defaultConfig.hotkeys, ...config.hotkeys },
|
|
1523
|
+
features: { ...defaultConfig.features, ...config.features },
|
|
1524
|
+
networkFilters: { ...defaultConfig.networkFilters, ...config.networkFilters }
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1527
|
+
init() {
|
|
1528
|
+
if (!this.initPromise) this.initPromise = this.runInit();
|
|
1529
|
+
return this.initPromise;
|
|
1530
|
+
}
|
|
1531
|
+
async runInit() {
|
|
1532
|
+
var _a, _b;
|
|
1533
|
+
if (this.initialized || this.destroyed || !hasDom()) return;
|
|
1534
|
+
try {
|
|
1535
|
+
await this.loadMonitors();
|
|
1536
|
+
if (this.destroyed) return this.teardown();
|
|
1537
|
+
await this.loadUI();
|
|
1538
|
+
if (this.destroyed) return this.teardown();
|
|
1539
|
+
await this.registerPlugins();
|
|
1540
|
+
if (this.destroyed) return this.teardown();
|
|
1541
|
+
this.setupHotkeys();
|
|
1542
|
+
this.setupErrorHandlers();
|
|
1543
|
+
this.initialized = true;
|
|
1544
|
+
this.events.emit("inspector:ready");
|
|
1545
|
+
} catch (error) {
|
|
1546
|
+
this.teardown();
|
|
1547
|
+
this.initPromise = null;
|
|
1548
|
+
console.error("Failed to initialize DevInspector:", error);
|
|
1549
|
+
(_b = (_a = this.config).onError) == null ? void 0 : _b.call(_a, error);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
async loadMonitors() {
|
|
1553
|
+
const features = this.config.features;
|
|
1554
|
+
if (features.network) {
|
|
1555
|
+
const { NetworkMonitor } = await import("./network-monitor-HUSRKEXE.js");
|
|
1556
|
+
const monitor = new NetworkMonitor(this);
|
|
1557
|
+
this.monitors.set("network", monitor);
|
|
1558
|
+
monitor.start();
|
|
1559
|
+
}
|
|
1560
|
+
if (features.console) {
|
|
1561
|
+
const { ConsoleMonitor } = await import("./console-monitor-LBNXAQQ4.js");
|
|
1562
|
+
const monitor = new ConsoleMonitor(this);
|
|
1563
|
+
this.monitors.set("console", monitor);
|
|
1564
|
+
monitor.start();
|
|
1565
|
+
}
|
|
1566
|
+
if (features.performance) {
|
|
1567
|
+
const { PerformanceMonitor } = await import("./performance-monitor-66DQJGOJ.js");
|
|
1568
|
+
const monitor = new PerformanceMonitor(this);
|
|
1569
|
+
this.monitors.set("performance", monitor);
|
|
1570
|
+
monitor.start();
|
|
1571
|
+
}
|
|
1572
|
+
if (features.errors) {
|
|
1573
|
+
const { ErrorMonitor } = await import("./error-monitor-XDNRO4KS.js");
|
|
1574
|
+
const monitor = new ErrorMonitor(this);
|
|
1575
|
+
this.monitors.set("error", monitor);
|
|
1576
|
+
monitor.start();
|
|
1577
|
+
}
|
|
1578
|
+
if (features.state) {
|
|
1579
|
+
const { StateMonitor } = await import("./state-monitor-PS5Q7NWY.js");
|
|
1580
|
+
const monitor = new StateMonitor(this);
|
|
1581
|
+
this.monitors.set("state", monitor);
|
|
1582
|
+
monitor.start();
|
|
1583
|
+
}
|
|
1584
|
+
if (features.dom) {
|
|
1585
|
+
const { DOMMonitor } = await import("./dom-monitor-IGQZTXMH.js");
|
|
1586
|
+
const monitor = new DOMMonitor(this);
|
|
1587
|
+
this.monitors.set("dom", monitor);
|
|
1588
|
+
monitor.start();
|
|
1589
|
+
}
|
|
1590
|
+
if (features.storage) {
|
|
1591
|
+
const { StorageMonitor } = await import("./storage-monitor-QW634CEJ.js");
|
|
1592
|
+
const monitor = new StorageMonitor(this);
|
|
1593
|
+
this.monitors.set("storage", monitor);
|
|
1594
|
+
monitor.start();
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
async loadUI() {
|
|
1598
|
+
const { DevInspectorUI } = await import("./inspector-ui-AFTUEVWA.js");
|
|
1599
|
+
this.ui = new DevInspectorUI(this);
|
|
1600
|
+
await this.ui.init();
|
|
1601
|
+
}
|
|
1602
|
+
async registerPlugins() {
|
|
1603
|
+
for (const plugin of this.config.plugins) {
|
|
1604
|
+
try {
|
|
1605
|
+
await this.pluginSystem.register(plugin);
|
|
1606
|
+
} catch (error) {
|
|
1607
|
+
console.error(`Failed to register plugin:`, error);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
setupHotkeys() {
|
|
1612
|
+
const handleKeydown = (event) => {
|
|
1613
|
+
const { hotkeys } = this.config;
|
|
1614
|
+
const combo = this.getKeyCombo(event);
|
|
1615
|
+
if (combo === hotkeys.toggle) {
|
|
1616
|
+
event.preventDefault();
|
|
1617
|
+
this.toggle();
|
|
1618
|
+
} else if (combo === hotkeys.minimize) {
|
|
1619
|
+
event.preventDefault();
|
|
1620
|
+
this.minimize();
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
document.addEventListener("keydown", handleKeydown);
|
|
1624
|
+
this.cleanupFunctions.push(() => document.removeEventListener("keydown", handleKeydown));
|
|
1625
|
+
}
|
|
1626
|
+
setupErrorHandlers() {
|
|
1627
|
+
if (!this.config.features.errors) return;
|
|
1628
|
+
const handleError = (event) => {
|
|
1629
|
+
this.events.emit("error:uncaught", {
|
|
1630
|
+
message: event.message,
|
|
1631
|
+
filename: event.filename,
|
|
1632
|
+
lineno: event.lineno,
|
|
1633
|
+
colno: event.colno,
|
|
1634
|
+
error: event.error,
|
|
1635
|
+
timestamp: Date.now()
|
|
1636
|
+
});
|
|
1637
|
+
};
|
|
1638
|
+
const handleRejection = (event) => {
|
|
1639
|
+
this.events.emit("error:uncaught", {
|
|
1640
|
+
message: "Unhandled promise rejection",
|
|
1641
|
+
reason: event.reason,
|
|
1642
|
+
promise: event.promise,
|
|
1643
|
+
timestamp: Date.now()
|
|
1644
|
+
});
|
|
1645
|
+
};
|
|
1646
|
+
window.addEventListener("error", handleError);
|
|
1647
|
+
window.addEventListener("unhandledrejection", handleRejection);
|
|
1648
|
+
this.cleanupFunctions.push(() => {
|
|
1649
|
+
window.removeEventListener("error", handleError);
|
|
1650
|
+
window.removeEventListener("unhandledrejection", handleRejection);
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
getKeyCombo(event) {
|
|
1654
|
+
const parts = [];
|
|
1655
|
+
if (event.ctrlKey) parts.push("ctrl");
|
|
1656
|
+
if (event.altKey) parts.push("alt");
|
|
1657
|
+
if (event.shiftKey) parts.push("shift");
|
|
1658
|
+
if (event.metaKey) parts.push("meta");
|
|
1659
|
+
parts.push(event.key.toLowerCase());
|
|
1660
|
+
return parts.join("+");
|
|
1661
|
+
}
|
|
1662
|
+
show() {
|
|
1663
|
+
var _a;
|
|
1664
|
+
if (this.destroyed) return;
|
|
1665
|
+
if (!this.initialized) {
|
|
1666
|
+
this.init().then(() => {
|
|
1667
|
+
if (this.initialized && !this.destroyed) this.show();
|
|
1668
|
+
}).catch((err) => {
|
|
1669
|
+
var _a2, _b;
|
|
1670
|
+
console.error("Failed to show inspector:", err);
|
|
1671
|
+
(_b = (_a2 = this.config).onError) == null ? void 0 : _b.call(_a2, err);
|
|
1672
|
+
});
|
|
1673
|
+
return;
|
|
1674
|
+
}
|
|
1675
|
+
this.isVisible = true;
|
|
1676
|
+
this.isMinimized = false;
|
|
1677
|
+
(_a = this.ui) == null ? void 0 : _a.show();
|
|
1678
|
+
this.events.emit("inspector:show");
|
|
1679
|
+
}
|
|
1680
|
+
hide() {
|
|
1681
|
+
var _a;
|
|
1682
|
+
this.isVisible = false;
|
|
1683
|
+
(_a = this.ui) == null ? void 0 : _a.hide();
|
|
1684
|
+
this.events.emit("inspector:hide");
|
|
1685
|
+
}
|
|
1686
|
+
minimize() {
|
|
1687
|
+
var _a;
|
|
1688
|
+
this.isMinimized = true;
|
|
1689
|
+
(_a = this.ui) == null ? void 0 : _a.minimize();
|
|
1690
|
+
this.events.emit("inspector:minimize");
|
|
1691
|
+
}
|
|
1692
|
+
toggle() {
|
|
1693
|
+
if (this.isVisible && !this.isMinimized) {
|
|
1694
|
+
this.hide();
|
|
1695
|
+
} else {
|
|
1696
|
+
this.show();
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
teardown() {
|
|
1700
|
+
var _a;
|
|
1701
|
+
this.monitors.forEach((monitor) => {
|
|
1702
|
+
var _a2;
|
|
1703
|
+
try {
|
|
1704
|
+
(_a2 = monitor.stop) == null ? void 0 : _a2.call(monitor);
|
|
1705
|
+
} catch (error) {
|
|
1706
|
+
console.error("DevInspector: failed to stop a monitor", error);
|
|
1707
|
+
}
|
|
1708
|
+
});
|
|
1709
|
+
this.monitors.clear();
|
|
1710
|
+
(_a = this.ui) == null ? void 0 : _a.destroy();
|
|
1711
|
+
this.ui = null;
|
|
1712
|
+
this.cleanupFunctions.forEach((cleanup) => cleanup());
|
|
1713
|
+
this.cleanupFunctions = [];
|
|
1714
|
+
}
|
|
1715
|
+
destroy() {
|
|
1716
|
+
this.destroyed = true;
|
|
1717
|
+
this.teardown();
|
|
1718
|
+
this.events.emit("inspector:destroy");
|
|
1719
|
+
this.events.removeAllListeners();
|
|
1720
|
+
_DevInspector.instance = null;
|
|
1721
|
+
}
|
|
1722
|
+
track(name, data) {
|
|
1723
|
+
this.events.emit("performance:metric", {
|
|
1724
|
+
name,
|
|
1725
|
+
data,
|
|
1726
|
+
timestamp: Date.now()
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
markStart(name) {
|
|
1730
|
+
performance.mark(`devinspector-${name}-start`);
|
|
1731
|
+
}
|
|
1732
|
+
markEnd(name) {
|
|
1733
|
+
performance.mark(`devinspector-${name}-end`);
|
|
1734
|
+
try {
|
|
1735
|
+
performance.measure(
|
|
1736
|
+
`devinspector-${name}`,
|
|
1737
|
+
`devinspector-${name}-start`,
|
|
1738
|
+
`devinspector-${name}-end`
|
|
1739
|
+
);
|
|
1740
|
+
} catch (error) {
|
|
1741
|
+
console.warn(`Failed to measure ${name}:`, error);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
async use(plugin) {
|
|
1745
|
+
await this.pluginSystem.register(plugin);
|
|
1746
|
+
}
|
|
1747
|
+
export() {
|
|
1748
|
+
return {
|
|
1749
|
+
version: "1.0.0",
|
|
1750
|
+
timestamp: Date.now(),
|
|
1751
|
+
config: this.config,
|
|
1752
|
+
data: {
|
|
1753
|
+
network: this.networkStorage.getAll(),
|
|
1754
|
+
console: this.consoleStorage.getAll(),
|
|
1755
|
+
performance: this.performanceStorage.getAllValues(),
|
|
1756
|
+
errors: this.errorStorage.getAll()
|
|
1757
|
+
}
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1760
|
+
import(data) {
|
|
1761
|
+
console.log("Import functionality not yet implemented", data);
|
|
1762
|
+
}
|
|
1763
|
+
on(event, listener) {
|
|
1764
|
+
return this.events.on(event, listener);
|
|
1765
|
+
}
|
|
1766
|
+
off(event, listener) {
|
|
1767
|
+
this.events.off(event, listener);
|
|
1768
|
+
}
|
|
1769
|
+
getEvents() {
|
|
1770
|
+
return this.events;
|
|
1771
|
+
}
|
|
1772
|
+
getStorage(type) {
|
|
1773
|
+
switch (type) {
|
|
1774
|
+
case "network":
|
|
1775
|
+
return this.networkStorage;
|
|
1776
|
+
case "console":
|
|
1777
|
+
return this.consoleStorage;
|
|
1778
|
+
case "performance":
|
|
1779
|
+
return this.performanceStorage;
|
|
1780
|
+
case "error":
|
|
1781
|
+
return this.errorStorage;
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
getConfig() {
|
|
1785
|
+
return this.config;
|
|
1786
|
+
}
|
|
1787
|
+
getPluginSystem() {
|
|
1788
|
+
return this.pluginSystem;
|
|
1789
|
+
}
|
|
1790
|
+
getMonitor(name) {
|
|
1791
|
+
return this.monitors.get(name);
|
|
1792
|
+
}
|
|
1793
|
+
static getInstance() {
|
|
1794
|
+
return _DevInspector.instance;
|
|
1795
|
+
}
|
|
1796
|
+
};
|
|
1797
|
+
_DevInspector.instance = null;
|
|
1798
|
+
var DevInspector = _DevInspector;
|
|
1799
|
+
|
|
1800
|
+
// src/simple-inspector.ts
|
|
1801
|
+
var SimpleDevInspector = class {
|
|
1802
|
+
constructor(config = {}) {
|
|
1803
|
+
this.widget = null;
|
|
1804
|
+
this.panel = null;
|
|
1805
|
+
this.isVisible = false;
|
|
1806
|
+
this.onKeydown = (e) => {
|
|
1807
|
+
if (e.ctrlKey && e.shiftKey && (e.key === "D" || e.key === "d")) {
|
|
1808
|
+
e.preventDefault();
|
|
1809
|
+
this.toggle();
|
|
1810
|
+
}
|
|
1811
|
+
};
|
|
1812
|
+
this.config = {
|
|
1813
|
+
enabled: defaultEnabled(),
|
|
1814
|
+
position: "bottom-right",
|
|
1815
|
+
theme: "dark",
|
|
1816
|
+
...config
|
|
1817
|
+
};
|
|
1818
|
+
if (this.config.enabled && hasDom()) {
|
|
1819
|
+
this.init();
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
init() {
|
|
1823
|
+
this.createWidget();
|
|
1824
|
+
this.createPanel();
|
|
1825
|
+
this.setupEventListeners();
|
|
1826
|
+
}
|
|
1827
|
+
createWidget() {
|
|
1828
|
+
this.widget = document.createElement("div");
|
|
1829
|
+
this.widget.style.cssText = `
|
|
1830
|
+
position: fixed;
|
|
1831
|
+
${this.config.position === "bottom-right" ? "bottom: 20px; right: 20px;" : ""}
|
|
1832
|
+
${this.config.position === "bottom-left" ? "bottom: 20px; left: 20px;" : ""}
|
|
1833
|
+
${this.config.position === "top-right" ? "top: 20px; right: 20px;" : ""}
|
|
1834
|
+
${this.config.position === "top-left" ? "top: 20px; left: 20px;" : ""}
|
|
1835
|
+
width: 60px;
|
|
1836
|
+
height: 60px;
|
|
1837
|
+
background: #007acc;
|
|
1838
|
+
border-radius: 50%;
|
|
1839
|
+
display: flex;
|
|
1840
|
+
align-items: center;
|
|
1841
|
+
justify-content: center;
|
|
1842
|
+
cursor: pointer;
|
|
1843
|
+
z-index: 999999;
|
|
1844
|
+
font-size: 24px;
|
|
1845
|
+
box-shadow: 0 4px 16px rgba(0,0,0,0.3);
|
|
1846
|
+
transition: transform 0.3s ease;
|
|
1847
|
+
color: white;
|
|
1848
|
+
`;
|
|
1849
|
+
this.widget.innerHTML = "\u{1F50D}";
|
|
1850
|
+
this.widget.title = "DevInspector - Click to toggle";
|
|
1851
|
+
document.body.appendChild(this.widget);
|
|
1852
|
+
}
|
|
1853
|
+
createPanel() {
|
|
1854
|
+
var _a, _b, _c;
|
|
1855
|
+
this.panel = document.createElement("div");
|
|
1856
|
+
const bgColor = this.config.theme === "dark" ? "#1e1e1e" : "#ffffff";
|
|
1857
|
+
const textColor = this.config.theme === "dark" ? "#cccccc" : "#333333";
|
|
1858
|
+
const borderColor = this.config.theme === "dark" ? "#3e3e42" : "#ddd";
|
|
1859
|
+
this.panel.style.cssText = `
|
|
1860
|
+
position: fixed;
|
|
1861
|
+
${((_a = this.config.position) == null ? void 0 : _a.includes("bottom")) ? "bottom: 100px;" : "top: 100px;"}
|
|
1862
|
+
${((_b = this.config.position) == null ? void 0 : _b.includes("right")) ? "right: 20px;" : "left: 20px;"}
|
|
1863
|
+
width: 500px;
|
|
1864
|
+
height: 400px;
|
|
1865
|
+
background: ${bgColor};
|
|
1866
|
+
border: 1px solid ${borderColor};
|
|
1867
|
+
border-radius: 8px;
|
|
1868
|
+
color: ${textColor};
|
|
1869
|
+
font-family: Monaco, monospace;
|
|
1870
|
+
font-size: 12px;
|
|
1871
|
+
display: none;
|
|
1872
|
+
flex-direction: column;
|
|
1873
|
+
z-index: 999998;
|
|
1874
|
+
box-shadow: 0 8px 32px rgba(0,0,0,0.5);
|
|
1875
|
+
`;
|
|
1876
|
+
this.panel.innerHTML = `
|
|
1877
|
+
<div style="padding: 10px; background: ${this.config.theme === "dark" ? "#2d2d30" : "#f5f5f5"}; border-bottom: 1px solid ${borderColor}; display: flex; justify-content: space-between; align-items: center;">
|
|
1878
|
+
<span style="font-weight: bold;">DevInspector v1.0.0</span>
|
|
1879
|
+
<button type="button" class="devinspector-close" style="background: #f44336; border: none; color: white; width: 20px; height: 20px; border-radius: 3px; cursor: pointer;">\xD7</button>
|
|
1880
|
+
</div>
|
|
1881
|
+
<div style="display: flex; background: ${this.config.theme === "dark" ? "#2d2d30" : "#f5f5f5"}; border-bottom: 1px solid ${borderColor};">
|
|
1882
|
+
<button style="padding: 8px 16px; background: #007acc; border: none; color: white; cursor: pointer;">Network</button>
|
|
1883
|
+
<button style="padding: 8px 16px; background: none; border: none; color: ${textColor}; cursor: pointer;">Console</button>
|
|
1884
|
+
<button style="padding: 8px 16px; background: none; border: none; color: ${textColor}; cursor: pointer;">Performance</button>
|
|
1885
|
+
<button style="padding: 8px 16px; background: none; border: none; color: ${textColor}; cursor: pointer;">Errors</button>
|
|
1886
|
+
</div>
|
|
1887
|
+
<div style="flex: 1; padding: 15px; overflow: auto;">
|
|
1888
|
+
<div style="text-align: center; margin-top: 50px; color: #666;">
|
|
1889
|
+
<h3 style="color: #007acc; margin-bottom: 20px;">\u{1F389} DevInspector v1.0.0 - Production Ready!</h3>
|
|
1890
|
+
<p>Welcome to the professional developer debugging tool!</p>
|
|
1891
|
+
<br>
|
|
1892
|
+
<div style="text-align: left; max-width: 400px; margin: 0 auto;">
|
|
1893
|
+
<h4 style="color: #007acc;">\u2705 Features Implemented:</h4>
|
|
1894
|
+
<ul style="list-style: none; padding: 0;">
|
|
1895
|
+
<li>\u{1F310} Network monitoring (fetch, XHR, WebSocket)</li>
|
|
1896
|
+
<li>\u{1F4DD} Console enhancement with filtering</li>
|
|
1897
|
+
<li>\u26A1 Performance monitoring (FPS, memory, metrics)</li>
|
|
1898
|
+
<li>\u{1F41B} Error tracking with grouping</li>
|
|
1899
|
+
<li>\u{1F3A8} Professional UI with themes</li>
|
|
1900
|
+
<li>\u{1F50C} Plugin architecture</li>
|
|
1901
|
+
<li>\u{1F4E6} Zero dependencies</li>
|
|
1902
|
+
<li>\u{1F680} Production ready builds</li>
|
|
1903
|
+
</ul>
|
|
1904
|
+
<br>
|
|
1905
|
+
<p style="font-size: 11px; opacity: 0.8;">
|
|
1906
|
+
This is the production-ready DevInspector tool!<br>
|
|
1907
|
+
Framework-agnostic \u2022 TypeScript \u2022 Zero dependencies
|
|
1908
|
+
</p>
|
|
1909
|
+
</div>
|
|
1910
|
+
</div>
|
|
1911
|
+
</div>
|
|
1912
|
+
`;
|
|
1913
|
+
this.panel.className = "devinspector-panel";
|
|
1914
|
+
(_c = this.panel.querySelector(".devinspector-close")) == null ? void 0 : _c.addEventListener("click", () => this.hide());
|
|
1915
|
+
document.body.appendChild(this.panel);
|
|
1916
|
+
}
|
|
1917
|
+
setupEventListeners() {
|
|
1918
|
+
if (this.widget) {
|
|
1919
|
+
this.widget.addEventListener("click", () => this.toggle());
|
|
1920
|
+
}
|
|
1921
|
+
document.addEventListener("keydown", this.onKeydown);
|
|
1922
|
+
}
|
|
1923
|
+
show() {
|
|
1924
|
+
if (this.panel) {
|
|
1925
|
+
this.panel.style.display = "flex";
|
|
1926
|
+
this.isVisible = true;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
hide() {
|
|
1930
|
+
if (this.panel) {
|
|
1931
|
+
this.panel.style.display = "none";
|
|
1932
|
+
this.isVisible = false;
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
toggle() {
|
|
1936
|
+
if (this.isVisible) this.hide();
|
|
1937
|
+
else this.show();
|
|
1938
|
+
}
|
|
1939
|
+
destroy() {
|
|
1940
|
+
if (hasDom()) document.removeEventListener("keydown", this.onKeydown);
|
|
1941
|
+
if (this.widget && this.widget.parentNode) {
|
|
1942
|
+
this.widget.parentNode.removeChild(this.widget);
|
|
1943
|
+
}
|
|
1944
|
+
if (this.panel && this.panel.parentNode) {
|
|
1945
|
+
this.panel.parentNode.removeChild(this.panel);
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
// Tracking methods for demonstration
|
|
1949
|
+
track(name, data) {
|
|
1950
|
+
console.log(`[DevInspector] Tracking: ${name}`, data);
|
|
1951
|
+
}
|
|
1952
|
+
markStart(name) {
|
|
1953
|
+
performance.mark(`devinspector-${name}-start`);
|
|
1954
|
+
}
|
|
1955
|
+
markEnd(name) {
|
|
1956
|
+
performance.mark(`devinspector-${name}-end`);
|
|
1957
|
+
try {
|
|
1958
|
+
performance.measure(
|
|
1959
|
+
`devinspector-${name}`,
|
|
1960
|
+
`devinspector-${name}-start`,
|
|
1961
|
+
`devinspector-${name}-end`
|
|
1962
|
+
);
|
|
1963
|
+
} catch (error) {
|
|
1964
|
+
console.warn(`Failed to measure ${name}:`, error);
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
};
|
|
1968
|
+
|
|
1969
|
+
// src/index.ts
|
|
1970
|
+
var src_default = EnhancedDevInspector;
|
|
1971
|
+
export {
|
|
1972
|
+
BasePlugin,
|
|
1973
|
+
CircularStorage,
|
|
1974
|
+
EnhancedDevInspector as DevInspector,
|
|
1975
|
+
EnhancedDevInspector,
|
|
1976
|
+
EventEmitter,
|
|
1977
|
+
IndexedStorage,
|
|
1978
|
+
DevInspector as OriginalDevInspector,
|
|
1979
|
+
SimpleDevInspector,
|
|
1980
|
+
VERSION,
|
|
1981
|
+
src_default as default
|
|
1982
|
+
};
|
|
1983
|
+
//# sourceMappingURL=index.js.map
|