@oxog/devinspector 1.4.0 → 1.5.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 +27 -0
- package/dist/chunk-5QIYNQ4C.js +19 -0
- package/dist/chunk-5QIYNQ4C.js.map +1 -0
- package/dist/{chunk-LNBLBFDA.js → chunk-NP2SAIEA.js} +23 -19
- package/dist/chunk-NP2SAIEA.js.map +1 -0
- package/dist/{chunk-VZORB655.js → chunk-WUYUDBSC.js} +6 -2
- package/dist/chunk-WUYUDBSC.js.map +1 -0
- package/dist/{console-monitor-AVTNZCED.js → console-monitor-AO67CSAK.js} +17 -10
- package/dist/console-monitor-AO67CSAK.js.map +1 -0
- package/dist/devinspector.umd.cjs +766 -489
- package/dist/devinspector.umd.cjs.map +1 -1
- package/dist/devinspector.umd.js +766 -489
- package/dist/devinspector.umd.js.map +1 -1
- package/dist/devinspector.umd.min.cjs +2 -2
- package/dist/devinspector.umd.min.cjs.map +1 -1
- package/dist/devinspector.umd.min.js +2 -2
- package/dist/devinspector.umd.min.js.map +1 -1
- package/dist/{dom-monitor-JHJVZYS4.js → dom-monitor-D6GHCDBP.js} +1 -1
- package/dist/{dom-monitor-JHJVZYS4.js.map → dom-monitor-D6GHCDBP.js.map} +1 -1
- package/dist/{error-monitor-3CRFREH3.js → error-monitor-AVTYBTS7.js} +27 -52
- package/dist/error-monitor-AVTYBTS7.js.map +1 -0
- package/dist/index.cjs +513 -286
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +268 -98
- package/dist/index.js.map +1 -1
- package/dist/{inspector-ui-475ZNEHC.js → inspector-ui-TEAZXDPM.js} +17 -7
- package/dist/inspector-ui-TEAZXDPM.js.map +1 -0
- package/dist/{network-monitor-WNRL2JI7.js → network-monitor-6XRFHXMV.js} +152 -114
- package/dist/network-monitor-6XRFHXMV.js.map +1 -0
- package/dist/{performance-monitor-UKQFA7ZR.js → performance-monitor-ULNHXBYX.js} +8 -6
- package/dist/performance-monitor-ULNHXBYX.js.map +1 -0
- package/dist/{state-monitor-JGJLBAD7.js → state-monitor-UNAVEOGH.js} +1 -1
- package/dist/{state-monitor-JGJLBAD7.js.map → state-monitor-UNAVEOGH.js.map} +1 -1
- package/dist/{storage-monitor-3NPTWRTY.js → storage-monitor-5RCRXYMX.js} +1 -1
- package/dist/{storage-monitor-3NPTWRTY.js.map → storage-monitor-5RCRXYMX.js.map} +1 -1
- package/package.json +6 -3
- package/dist/chunk-LNBLBFDA.js.map +0 -1
- package/dist/chunk-VZORB655.js.map +0 -1
- package/dist/console-monitor-AVTNZCED.js.map +0 -1
- package/dist/error-monitor-3CRFREH3.js.map +0 -1
- package/dist/inspector-ui-475ZNEHC.js.map +0 -1
- package/dist/network-monitor-WNRL2JI7.js.map +0 -1
- package/dist/performance-monitor-UKQFA7ZR.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @oxog/devinspector v1.
|
|
2
|
+
* @oxog/devinspector v1.5.0
|
|
3
3
|
* (c) Ersin Koc <ersinkoc@gmail.com>
|
|
4
4
|
* Released under the MIT License
|
|
5
5
|
*/
|
|
@@ -32,6 +32,15 @@
|
|
|
32
32
|
function defaultEnabled() {
|
|
33
33
|
return readNodeEnv() !== 'production';
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* A size limit from user config: non-negative finite numbers are floored (0 keeps
|
|
37
|
+
* nothing); anything else falls back to the default.
|
|
38
|
+
*/
|
|
39
|
+
function normalizeLimit(value, fallback) {
|
|
40
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0
|
|
41
|
+
? Math.floor(value)
|
|
42
|
+
: fallback;
|
|
43
|
+
}
|
|
35
44
|
/** True when a DOM is available (browser, jsdom), false during SSR/Node. */
|
|
36
45
|
function hasDom() {
|
|
37
46
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
@@ -46,7 +55,7 @@
|
|
|
46
55
|
};
|
|
47
56
|
/** Escapes a value for use in HTML text or a quoted attribute. */
|
|
48
57
|
function escapeHtml(value) {
|
|
49
|
-
return String(value).replace(/[&<>"'`]/g, ch => HTML_ESCAPES[ch]);
|
|
58
|
+
return String(value).replace(/[&<>"'`]/g, (ch) => HTML_ESCAPES[ch]);
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
class EventEmitter {
|
|
@@ -87,7 +96,7 @@
|
|
|
87
96
|
return false;
|
|
88
97
|
}
|
|
89
98
|
const data = args[0];
|
|
90
|
-
listeners.forEach(listener => {
|
|
99
|
+
listeners.forEach((listener) => {
|
|
91
100
|
try {
|
|
92
101
|
listener(data);
|
|
93
102
|
}
|
|
@@ -139,6 +148,30 @@
|
|
|
139
148
|
}
|
|
140
149
|
}
|
|
141
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Restoring monkey patches when several wrappers are stacked on one API.
|
|
153
|
+
*
|
|
154
|
+
* A wrapper that cannot be removed (something else wrapped it since) stays in
|
|
155
|
+
* place and passes straight through; it is remembered here with the value it
|
|
156
|
+
* wraps, so whoever restores the wrapper on top of it skips over it. Destroying
|
|
157
|
+
* inspectors or monitors in any order then still ends at the original API.
|
|
158
|
+
*/
|
|
159
|
+
const retired = new WeakMap();
|
|
160
|
+
function unwrapRetired(value) {
|
|
161
|
+
let current = value;
|
|
162
|
+
while (current !== null && typeof current === 'function' && retired.has(current))
|
|
163
|
+
current = retired.get(current);
|
|
164
|
+
return current;
|
|
165
|
+
}
|
|
166
|
+
/** Puts `original` back on `target[key]` if `replacement` is still installed there. */
|
|
167
|
+
function restorePatch(target, key, replacement, original) {
|
|
168
|
+
const record = target;
|
|
169
|
+
if (record[key] === replacement)
|
|
170
|
+
record[key] = unwrapRetired(original);
|
|
171
|
+
else if (replacement !== null && typeof replacement === 'function')
|
|
172
|
+
retired.set(replacement, original);
|
|
173
|
+
}
|
|
174
|
+
|
|
142
175
|
class PluginSystem {
|
|
143
176
|
constructor(context) {
|
|
144
177
|
this.plugins = new Map();
|
|
@@ -163,7 +196,7 @@
|
|
|
163
196
|
}
|
|
164
197
|
this.context.events.emit('plugin:registered', {
|
|
165
198
|
name: plugin.name,
|
|
166
|
-
version: plugin.version
|
|
199
|
+
version: plugin.version,
|
|
167
200
|
});
|
|
168
201
|
}
|
|
169
202
|
catch (error) {
|
|
@@ -178,17 +211,23 @@
|
|
|
178
211
|
if (!plugin) {
|
|
179
212
|
throw new Error(`Plugin "${pluginName}" is not registered`);
|
|
180
213
|
}
|
|
181
|
-
|
|
182
|
-
plugin.disable
|
|
214
|
+
try {
|
|
215
|
+
if (plugin.disable) {
|
|
216
|
+
plugin.disable();
|
|
217
|
+
}
|
|
218
|
+
if (plugin.uninstall) {
|
|
219
|
+
await plugin.uninstall();
|
|
220
|
+
}
|
|
183
221
|
}
|
|
184
|
-
|
|
185
|
-
|
|
222
|
+
finally {
|
|
223
|
+
// Removed even when disable()/uninstall() throws (the error still reaches the
|
|
224
|
+
// caller), so a broken plugin is not left registered and active.
|
|
225
|
+
this.plugins.delete(pluginName);
|
|
226
|
+
this.activePlugins.delete(pluginName);
|
|
227
|
+
this.context.events.emit('plugin:unregistered', {
|
|
228
|
+
name: pluginName,
|
|
229
|
+
});
|
|
186
230
|
}
|
|
187
|
-
this.plugins.delete(pluginName);
|
|
188
|
-
this.activePlugins.delete(pluginName);
|
|
189
|
-
this.context.events.emit('plugin:unregistered', {
|
|
190
|
-
name: pluginName
|
|
191
|
-
});
|
|
192
231
|
}
|
|
193
232
|
enable(pluginName) {
|
|
194
233
|
const plugin = this.plugins.get(pluginName);
|
|
@@ -203,7 +242,7 @@
|
|
|
203
242
|
}
|
|
204
243
|
this.activePlugins.add(pluginName);
|
|
205
244
|
this.context.events.emit('plugin:enabled', {
|
|
206
|
-
name: pluginName
|
|
245
|
+
name: pluginName,
|
|
207
246
|
});
|
|
208
247
|
}
|
|
209
248
|
disable(pluginName) {
|
|
@@ -219,7 +258,7 @@
|
|
|
219
258
|
}
|
|
220
259
|
this.activePlugins.delete(pluginName);
|
|
221
260
|
this.context.events.emit('plugin:disabled', {
|
|
222
|
-
name: pluginName
|
|
261
|
+
name: pluginName,
|
|
223
262
|
});
|
|
224
263
|
}
|
|
225
264
|
get(pluginName) {
|
|
@@ -235,7 +274,7 @@
|
|
|
235
274
|
return Array.from(this.plugins.values());
|
|
236
275
|
}
|
|
237
276
|
getActive() {
|
|
238
|
-
return Array.from(this.activePlugins).map(name => this.plugins.get(name));
|
|
277
|
+
return Array.from(this.activePlugins).map((name) => this.plugins.get(name));
|
|
239
278
|
}
|
|
240
279
|
getMetadata(pluginName) {
|
|
241
280
|
const plugin = this.plugins.get(pluginName);
|
|
@@ -245,14 +284,14 @@
|
|
|
245
284
|
return {
|
|
246
285
|
name: plugin.name,
|
|
247
286
|
version: plugin.version,
|
|
248
|
-
description: plugin.description
|
|
287
|
+
description: plugin.description,
|
|
249
288
|
};
|
|
250
289
|
}
|
|
251
290
|
getAllMetadata() {
|
|
252
|
-
return this.getAll().map(plugin => ({
|
|
291
|
+
return this.getAll().map((plugin) => ({
|
|
253
292
|
name: plugin.name,
|
|
254
293
|
version: plugin.version,
|
|
255
|
-
description: plugin.description
|
|
294
|
+
description: plugin.description,
|
|
256
295
|
}));
|
|
257
296
|
}
|
|
258
297
|
}
|
|
@@ -296,7 +335,7 @@
|
|
|
296
335
|
}
|
|
297
336
|
|
|
298
337
|
/** Package version, kept in sync with package.json (checked by tests). */
|
|
299
|
-
const VERSION = '1.
|
|
338
|
+
const VERSION = '1.5.0';
|
|
300
339
|
|
|
301
340
|
/**
|
|
302
341
|
* DevInspector - the default inspector: floating widget plus a panel with
|
|
@@ -312,38 +351,71 @@
|
|
|
312
351
|
const ASSET_PATTERN = /\.(?:css|js|mjs|map|png|jpe?g|gif|svg|webp|avif|ico|woff2?|ttf|otf|eot)(?:[?#]|$)/i;
|
|
313
352
|
const POSITIONS = ['top-left', 'top-right', 'bottom-left', 'bottom-right'];
|
|
314
353
|
const PALETTES = {
|
|
315
|
-
dark: {
|
|
316
|
-
|
|
354
|
+
dark: {
|
|
355
|
+
bg: '#1a1a1a',
|
|
356
|
+
header: '#262626',
|
|
357
|
+
toolbar: '#1e1e1e',
|
|
358
|
+
border: '#333',
|
|
359
|
+
row: '#2a2a2a',
|
|
360
|
+
text: '#e4e4e7',
|
|
361
|
+
muted: '#9ca3af',
|
|
362
|
+
code: '#0f0f0f',
|
|
363
|
+
},
|
|
364
|
+
light: {
|
|
365
|
+
bg: '#ffffff',
|
|
366
|
+
header: '#f3f4f6',
|
|
367
|
+
toolbar: '#f9fafb',
|
|
368
|
+
border: '#d1d5db',
|
|
369
|
+
row: '#e5e7eb',
|
|
370
|
+
text: '#111827',
|
|
371
|
+
muted: '#4b5563',
|
|
372
|
+
code: '#f3f4f6',
|
|
373
|
+
},
|
|
317
374
|
};
|
|
318
375
|
let idCounter = 0;
|
|
319
376
|
function nextId() {
|
|
320
377
|
idCounter = (idCounter + 1) % Number.MAX_SAFE_INTEGER;
|
|
321
378
|
return `${Date.now().toString(36)}-${idCounter.toString(36)}`;
|
|
322
379
|
}
|
|
323
|
-
function limit(value, fallback) {
|
|
324
|
-
return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? Math.floor(value) : fallback;
|
|
325
|
-
}
|
|
326
380
|
function normalizeCombo(combo) {
|
|
327
381
|
if (typeof combo !== 'string')
|
|
328
382
|
return '';
|
|
329
|
-
const parts = combo
|
|
330
|
-
|
|
383
|
+
const parts = combo
|
|
384
|
+
.toLowerCase()
|
|
385
|
+
.split('+')
|
|
386
|
+
.map((part) => part.trim())
|
|
387
|
+
.filter(Boolean);
|
|
388
|
+
const key = parts.filter((part) => !['ctrl', 'control', 'alt', 'shift', 'meta', 'cmd'].includes(part));
|
|
331
389
|
if (key.length !== 1)
|
|
332
390
|
return '';
|
|
333
|
-
const has = (...names) => names.some(name => parts.includes(name));
|
|
334
|
-
return [
|
|
391
|
+
const has = (...names) => names.some((name) => parts.includes(name));
|
|
392
|
+
return [
|
|
393
|
+
has('ctrl', 'control') && 'ctrl',
|
|
394
|
+
has('alt') && 'alt',
|
|
395
|
+
has('shift') && 'shift',
|
|
396
|
+
has('meta', 'cmd') && 'meta',
|
|
397
|
+
key[0],
|
|
398
|
+
]
|
|
335
399
|
.filter(Boolean)
|
|
336
400
|
.join('+');
|
|
337
401
|
}
|
|
338
402
|
function eventCombo(event) {
|
|
339
403
|
if (typeof event.key !== 'string')
|
|
340
404
|
return '';
|
|
341
|
-
return [
|
|
405
|
+
return [
|
|
406
|
+
event.ctrlKey && 'ctrl',
|
|
407
|
+
event.altKey && 'alt',
|
|
408
|
+
event.shiftKey && 'shift',
|
|
409
|
+
event.metaKey && 'meta',
|
|
410
|
+
event.key.toLowerCase(),
|
|
411
|
+
]
|
|
342
412
|
.filter(Boolean)
|
|
343
413
|
.join('+');
|
|
344
414
|
}
|
|
345
415
|
function truncate(text) {
|
|
346
|
-
return text.length > MAX_MESSAGE_LENGTH
|
|
416
|
+
return text.length > MAX_MESSAGE_LENGTH
|
|
417
|
+
? `${text.slice(0, MAX_MESSAGE_LENGTH)}… (${text.length - MAX_MESSAGE_LENGTH} more characters)`
|
|
418
|
+
: text;
|
|
347
419
|
}
|
|
348
420
|
function stringifyArg(arg) {
|
|
349
421
|
if (typeof arg === 'string')
|
|
@@ -465,7 +537,11 @@
|
|
|
465
537
|
this.setupHotkeys();
|
|
466
538
|
this.mountWhenReady();
|
|
467
539
|
for (const plugin of (_a = config.plugins) !== null && _a !== void 0 ? _a : []) {
|
|
468
|
-
this.use(plugin).catch(error =>
|
|
540
|
+
this.use(plugin).catch((error) => {
|
|
541
|
+
// After destroy() the plugin was uninstalled again; nothing to report.
|
|
542
|
+
if (!this.destroyed)
|
|
543
|
+
this.reportInternal('Failed to register plugin', error);
|
|
544
|
+
});
|
|
469
545
|
}
|
|
470
546
|
this.events.emit('inspector:ready');
|
|
471
547
|
}
|
|
@@ -491,7 +567,9 @@
|
|
|
491
567
|
const hotkeys = (_b = config.hotkeys) !== null && _b !== void 0 ? _b : {};
|
|
492
568
|
return {
|
|
493
569
|
enabled: typeof config.enabled === 'boolean' ? config.enabled : defaultEnabled(),
|
|
494
|
-
position: POSITIONS.includes(config.position)
|
|
570
|
+
position: POSITIONS.includes(config.position)
|
|
571
|
+
? config.position
|
|
572
|
+
: 'bottom-right',
|
|
495
573
|
theme: theme === 'auto' ? (prefersDark ? 'dark' : 'light') : theme,
|
|
496
574
|
hotkeys: {
|
|
497
575
|
toggle: normalizeCombo((_c = hotkeys.toggle) !== null && _c !== void 0 ? _c : 'ctrl+shift+d'),
|
|
@@ -503,12 +581,12 @@
|
|
|
503
581
|
performance: features.performance !== false,
|
|
504
582
|
errors: features.errors !== false,
|
|
505
583
|
},
|
|
506
|
-
maxNetworkEntries:
|
|
507
|
-
maxConsoleEntries:
|
|
508
|
-
maxErrorEntries:
|
|
584
|
+
maxNetworkEntries: normalizeLimit(config.maxNetworkEntries, 1000),
|
|
585
|
+
maxConsoleEntries: normalizeLimit(config.maxConsoleEntries, 500),
|
|
586
|
+
maxErrorEntries: normalizeLimit(config.maxErrorEntries, 100),
|
|
509
587
|
captureStackTraces: config.captureStackTraces !== false,
|
|
510
588
|
hideAssets: ((_e = config.networkFilters) === null || _e === void 0 ? void 0 : _e.hideAssets) === true,
|
|
511
|
-
slowRequestThreshold:
|
|
589
|
+
slowRequestThreshold: normalizeLimit(config.slowRequestThreshold, 3000),
|
|
512
590
|
onError: typeof config.onError === 'function' ? config.onError : undefined,
|
|
513
591
|
onPerformanceIssue: typeof config.onPerformanceIssue === 'function' ? config.onPerformanceIssue : undefined,
|
|
514
592
|
};
|
|
@@ -584,20 +662,25 @@
|
|
|
584
662
|
getEntries(type) {
|
|
585
663
|
switch (type) {
|
|
586
664
|
case 'network':
|
|
587
|
-
return this.network.map(entry => ({ ...entry }));
|
|
665
|
+
return this.network.map((entry) => ({ ...entry }));
|
|
588
666
|
case 'console':
|
|
589
|
-
return this.consoleEntries.map(entry => ({ ...entry }));
|
|
667
|
+
return this.consoleEntries.map((entry) => ({ ...entry }));
|
|
590
668
|
case 'errors':
|
|
591
|
-
return this.errors.map(entry => ({ ...entry }));
|
|
669
|
+
return this.errors.map((entry) => ({ ...entry }));
|
|
592
670
|
default:
|
|
593
|
-
return this.metrics.map(entry => ({ ...entry }));
|
|
671
|
+
return this.metrics.map((entry) => ({ ...entry }));
|
|
594
672
|
}
|
|
595
673
|
}
|
|
596
674
|
/** Records a custom metric and emits `performance:metric`. */
|
|
597
675
|
track(name, data) {
|
|
598
676
|
if (!this.isEnabled)
|
|
599
677
|
return;
|
|
600
|
-
const entry = {
|
|
678
|
+
const entry = {
|
|
679
|
+
id: nextId(),
|
|
680
|
+
name: String(name),
|
|
681
|
+
data,
|
|
682
|
+
timestamp: Date.now(),
|
|
683
|
+
};
|
|
601
684
|
this.pushBounded(this.metrics, entry, MAX_METRIC_ENTRIES);
|
|
602
685
|
this.emitSafely('performance:metric', entry);
|
|
603
686
|
this.scheduleRender();
|
|
@@ -632,7 +715,12 @@
|
|
|
632
715
|
catch (_c) {
|
|
633
716
|
// See markStart().
|
|
634
717
|
}
|
|
635
|
-
const entry = {
|
|
718
|
+
const entry = {
|
|
719
|
+
id: nextId(),
|
|
720
|
+
name: key,
|
|
721
|
+
duration,
|
|
722
|
+
timestamp: Date.now(),
|
|
723
|
+
};
|
|
636
724
|
this.pushBounded(this.metrics, entry, MAX_METRIC_ENTRIES);
|
|
637
725
|
this.emitSafely('performance:mark', entry);
|
|
638
726
|
this.scheduleRender();
|
|
@@ -642,7 +730,15 @@
|
|
|
642
730
|
use(plugin) {
|
|
643
731
|
if (this.destroyed)
|
|
644
732
|
return Promise.reject(new Error('DevInspector has been destroyed'));
|
|
645
|
-
return this.pluginSystem.register(plugin)
|
|
733
|
+
return this.pluginSystem.register(plugin).then(async () => {
|
|
734
|
+
if (!this.destroyed)
|
|
735
|
+
return;
|
|
736
|
+
// destroy() ran while install() was pending and could not see the plugin yet.
|
|
737
|
+
await this.pluginSystem
|
|
738
|
+
.unregister(plugin.name)
|
|
739
|
+
.catch((error) => this.reportInternal(`Failed to uninstall plugin "${plugin.name}"`, error));
|
|
740
|
+
throw new Error('DevInspector has been destroyed');
|
|
741
|
+
});
|
|
646
742
|
}
|
|
647
743
|
on(event, listener) {
|
|
648
744
|
return this.events.on(event, listener);
|
|
@@ -675,19 +771,25 @@
|
|
|
675
771
|
if (!data || typeof data !== 'object')
|
|
676
772
|
throw new TypeError('DevInspector.import() expects an object produced by export()');
|
|
677
773
|
const source = data;
|
|
678
|
-
const list = (value) => Array.isArray(value)
|
|
679
|
-
|
|
680
|
-
|
|
774
|
+
const list = (value) => Array.isArray(value)
|
|
775
|
+
? value.filter((item) => !!item && typeof item === 'object')
|
|
776
|
+
: [];
|
|
777
|
+
const str = (value, fallback = '') => typeof value === 'string' ? value : fallback;
|
|
778
|
+
const num = (value) => typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
681
779
|
this.network = list(source.network)
|
|
682
780
|
.slice(0, this.config.maxNetworkEntries)
|
|
683
|
-
.map(item => {
|
|
781
|
+
.map((item) => {
|
|
684
782
|
var _a;
|
|
685
783
|
return ({
|
|
686
784
|
id: str(item.id, nextId()),
|
|
687
785
|
type: item.type === 'xhr' ? 'xhr' : 'fetch',
|
|
688
786
|
url: str(item.url),
|
|
689
787
|
method: str(item.method, 'GET'),
|
|
690
|
-
status: typeof item.status === 'number'
|
|
788
|
+
status: typeof item.status === 'number'
|
|
789
|
+
? item.status
|
|
790
|
+
: item.status === 'pending'
|
|
791
|
+
? 'pending'
|
|
792
|
+
: 'error',
|
|
691
793
|
timestamp: (_a = num(item.timestamp)) !== null && _a !== void 0 ? _a : Date.now(),
|
|
692
794
|
duration: num(item.duration),
|
|
693
795
|
error: typeof item.error === 'string' ? item.error : undefined,
|
|
@@ -695,18 +797,20 @@
|
|
|
695
797
|
});
|
|
696
798
|
this.consoleEntries = list(source.console)
|
|
697
799
|
.slice(0, this.config.maxConsoleEntries)
|
|
698
|
-
.map(item => {
|
|
800
|
+
.map((item) => {
|
|
699
801
|
var _a;
|
|
700
802
|
return ({
|
|
701
803
|
id: str(item.id, nextId()),
|
|
702
|
-
level: CONSOLE_METHODS.includes(item.level)
|
|
804
|
+
level: CONSOLE_METHODS.includes(item.level)
|
|
805
|
+
? item.level
|
|
806
|
+
: 'log',
|
|
703
807
|
message: truncate(str(item.message)),
|
|
704
808
|
timestamp: (_a = num(item.timestamp)) !== null && _a !== void 0 ? _a : Date.now(),
|
|
705
809
|
});
|
|
706
810
|
});
|
|
707
811
|
this.errors = list(source.errors)
|
|
708
812
|
.slice(0, this.config.maxErrorEntries)
|
|
709
|
-
.map(item => {
|
|
813
|
+
.map((item) => {
|
|
710
814
|
var _a;
|
|
711
815
|
return ({
|
|
712
816
|
id: str(item.id, nextId()),
|
|
@@ -718,7 +822,7 @@
|
|
|
718
822
|
});
|
|
719
823
|
this.metrics = list(source.metrics)
|
|
720
824
|
.slice(0, MAX_METRIC_ENTRIES)
|
|
721
|
-
.map(item => {
|
|
825
|
+
.map((item) => {
|
|
722
826
|
var _a;
|
|
723
827
|
return ({
|
|
724
828
|
id: str(item.id, nextId()),
|
|
@@ -741,10 +845,9 @@
|
|
|
741
845
|
return;
|
|
742
846
|
this.destroyed = true;
|
|
743
847
|
for (const patch of this.patches.reverse()) {
|
|
744
|
-
// Only
|
|
848
|
+
// Only restored when nobody has wrapped our replacement since; otherwise the
|
|
745
849
|
// replacement stays in place but passes straight through (destroyed flag).
|
|
746
|
-
|
|
747
|
-
patch.target[patch.key] = patch.original;
|
|
850
|
+
restorePatch(patch.target, patch.key, patch.replacement, patch.original);
|
|
748
851
|
}
|
|
749
852
|
this.patches = [];
|
|
750
853
|
for (const cleanup of this.cleanups.splice(0)) {
|
|
@@ -761,7 +864,9 @@
|
|
|
761
864
|
this.widget = null;
|
|
762
865
|
this.panel = null;
|
|
763
866
|
for (const plugin of this.pluginSystem.getAll()) {
|
|
764
|
-
this.pluginSystem
|
|
867
|
+
this.pluginSystem
|
|
868
|
+
.unregister(plugin.name)
|
|
869
|
+
.catch((error) => this.reportInternal(`Failed to uninstall plugin "${plugin.name}"`, error));
|
|
765
870
|
}
|
|
766
871
|
this.emitSafely('inspector:destroy', undefined);
|
|
767
872
|
this.events.removeAllListeners();
|
|
@@ -770,7 +875,7 @@
|
|
|
770
875
|
this.errors = [];
|
|
771
876
|
this.metrics = [];
|
|
772
877
|
this.marks.clear();
|
|
773
|
-
EnhancedDevInspector.instances = EnhancedDevInspector.instances.filter(instance => instance !== this);
|
|
878
|
+
EnhancedDevInspector.instances = EnhancedDevInspector.instances.filter((instance) => instance !== this);
|
|
774
879
|
}
|
|
775
880
|
// ---------------------------------------------------------------------------
|
|
776
881
|
// Capture
|
|
@@ -822,7 +927,12 @@
|
|
|
822
927
|
entry.error = error;
|
|
823
928
|
this.emitSafely(status === 'error' ? 'network:error' : 'network:response', { ...entry });
|
|
824
929
|
if (duration > this.config.slowRequestThreshold) {
|
|
825
|
-
const issue = {
|
|
930
|
+
const issue = {
|
|
931
|
+
type: 'slow-network',
|
|
932
|
+
message: `Slow network request: ${entry.url}`,
|
|
933
|
+
url: entry.url,
|
|
934
|
+
duration: entry.duration,
|
|
935
|
+
};
|
|
826
936
|
this.emitSafely('performance:issue', issue);
|
|
827
937
|
this.callUser(this.config.onPerformanceIssue, issue);
|
|
828
938
|
}
|
|
@@ -839,7 +949,14 @@
|
|
|
839
949
|
let entry = null;
|
|
840
950
|
const start = performance.now();
|
|
841
951
|
self.capture(() => {
|
|
842
|
-
entry = {
|
|
952
|
+
entry = {
|
|
953
|
+
id: nextId(),
|
|
954
|
+
type: 'fetch',
|
|
955
|
+
url: requestUrl(args[0]),
|
|
956
|
+
method: requestMethod(args[0], args[1]),
|
|
957
|
+
status: 'pending',
|
|
958
|
+
timestamp: Date.now(),
|
|
959
|
+
};
|
|
843
960
|
self.addNetworkEntry(entry);
|
|
844
961
|
});
|
|
845
962
|
if (!entry)
|
|
@@ -854,7 +971,7 @@
|
|
|
854
971
|
self.capture(() => self.finishNetworkEntry(tracked, 'error', performance.now() - start, error instanceof Error ? error.message : String(error)));
|
|
855
972
|
throw error;
|
|
856
973
|
}
|
|
857
|
-
return Promise.resolve(result).then(response => {
|
|
974
|
+
return Promise.resolve(result).then((response) => {
|
|
858
975
|
self.capture(() => self.finishNetworkEntry(tracked, response.status, performance.now() - start));
|
|
859
976
|
return response;
|
|
860
977
|
}, (error) => {
|
|
@@ -878,24 +995,56 @@
|
|
|
878
995
|
// Patch the prototype rather than replacing the constructor, so
|
|
879
996
|
// `instanceof XMLHttpRequest` and constants such as XMLHttpRequest.DONE keep working.
|
|
880
997
|
const open = function (...args) {
|
|
998
|
+
var _a, _b;
|
|
999
|
+
const result = Reflect.apply(originalOpen, this, args);
|
|
881
1000
|
if (!self.destroyed) {
|
|
882
|
-
|
|
1001
|
+
// open() on a request in flight terminates it without abort/loadend events.
|
|
1002
|
+
(_b = (_a = self.xhrState.get(this)) === null || _a === void 0 ? void 0 : _a.terminate) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1003
|
+
self.xhrState.set(this, {
|
|
1004
|
+
method: typeof args[0] === 'string' ? args[0].toUpperCase() : 'GET',
|
|
1005
|
+
url: requestUrl(args[1]),
|
|
1006
|
+
});
|
|
883
1007
|
}
|
|
884
|
-
return
|
|
1008
|
+
return result;
|
|
885
1009
|
};
|
|
886
1010
|
const send = function (...args) {
|
|
1011
|
+
var _a;
|
|
887
1012
|
const state = self.xhrState.get(this);
|
|
1013
|
+
const tracking = {};
|
|
888
1014
|
if (state)
|
|
889
|
-
self.capture(() => self.trackXhr(this, state));
|
|
890
|
-
|
|
1015
|
+
self.capture(() => (tracking.fail = self.trackXhr(this, state)));
|
|
1016
|
+
try {
|
|
1017
|
+
return Reflect.apply(originalSend, this, args);
|
|
1018
|
+
}
|
|
1019
|
+
catch (error) {
|
|
1020
|
+
// send() threw (e.g. InvalidStateError on a second send(), or a synchronous
|
|
1021
|
+
// NetworkError): no request was started by this call.
|
|
1022
|
+
(_a = tracking.fail) === null || _a === void 0 ? void 0 : _a.call(tracking, error);
|
|
1023
|
+
throw error;
|
|
1024
|
+
}
|
|
891
1025
|
};
|
|
892
1026
|
this.patch(proto, 'open', open);
|
|
893
1027
|
this.patch(proto, 'send', send);
|
|
894
1028
|
}
|
|
895
1029
|
trackXhr(xhr, state) {
|
|
896
|
-
const
|
|
1030
|
+
const previous = {
|
|
1031
|
+
entry: state.entry,
|
|
1032
|
+
start: state.start,
|
|
1033
|
+
failure: state.failure,
|
|
1034
|
+
terminate: state.terminate,
|
|
1035
|
+
};
|
|
1036
|
+
let settled = false;
|
|
1037
|
+
const entry = {
|
|
1038
|
+
id: nextId(),
|
|
1039
|
+
type: 'xhr',
|
|
1040
|
+
url: state.url,
|
|
1041
|
+
method: state.method,
|
|
1042
|
+
status: 'pending',
|
|
1043
|
+
timestamp: Date.now(),
|
|
1044
|
+
};
|
|
1045
|
+
const startedAt = performance.now();
|
|
897
1046
|
state.entry = entry;
|
|
898
|
-
state.start =
|
|
1047
|
+
state.start = startedAt;
|
|
899
1048
|
state.failure = undefined;
|
|
900
1049
|
const fail = (reason) => () => {
|
|
901
1050
|
state.failure = reason;
|
|
@@ -903,23 +1052,50 @@
|
|
|
903
1052
|
const onError = fail('Network error');
|
|
904
1053
|
const onAbort = fail('Request aborted');
|
|
905
1054
|
const onTimeout = fail('Request timed out');
|
|
906
|
-
const
|
|
907
|
-
var _a;
|
|
1055
|
+
const detach = () => {
|
|
908
1056
|
xhr.removeEventListener('error', onError);
|
|
909
1057
|
xhr.removeEventListener('abort', onAbort);
|
|
910
1058
|
xhr.removeEventListener('timeout', onTimeout);
|
|
911
1059
|
xhr.removeEventListener('loadend', onLoadEnd);
|
|
912
|
-
|
|
1060
|
+
};
|
|
1061
|
+
const onLoadEnd = () => {
|
|
1062
|
+
var _a;
|
|
1063
|
+
detach();
|
|
1064
|
+
if (settled || state.entry !== entry || this.destroyed)
|
|
913
1065
|
return;
|
|
1066
|
+
settled = true;
|
|
914
1067
|
const duration = performance.now() - ((_a = state.start) !== null && _a !== void 0 ? _a : performance.now());
|
|
915
1068
|
const failed = state.failure !== undefined || xhr.status === 0;
|
|
916
|
-
this.capture(() => {
|
|
1069
|
+
this.capture(() => {
|
|
1070
|
+
var _a;
|
|
1071
|
+
return this.finishNetworkEntry(entry, failed ? 'error' : xhr.status, duration, failed ? ((_a = state.failure) !== null && _a !== void 0 ? _a : 'Network error') : undefined);
|
|
1072
|
+
});
|
|
917
1073
|
};
|
|
918
1074
|
xhr.addEventListener('error', onError);
|
|
919
1075
|
xhr.addEventListener('abort', onAbort);
|
|
920
1076
|
xhr.addEventListener('timeout', onTimeout);
|
|
921
1077
|
xhr.addEventListener('loadend', onLoadEnd);
|
|
1078
|
+
state.terminate = () => {
|
|
1079
|
+
detach();
|
|
1080
|
+
if (settled || this.destroyed)
|
|
1081
|
+
return;
|
|
1082
|
+
settled = true;
|
|
1083
|
+
this.capture(() => this.finishNetworkEntry(entry, 'error', performance.now() - startedAt, 'Request aborted'));
|
|
1084
|
+
};
|
|
922
1085
|
this.addNetworkEntry(entry);
|
|
1086
|
+
// Called when send() throws: the request already in flight (if any) keeps its
|
|
1087
|
+
// own entry, and this attempt is recorded as failed.
|
|
1088
|
+
return (error) => {
|
|
1089
|
+
detach();
|
|
1090
|
+
if (settled)
|
|
1091
|
+
return;
|
|
1092
|
+
settled = true;
|
|
1093
|
+
if (state.entry === entry)
|
|
1094
|
+
Object.assign(state, previous);
|
|
1095
|
+
if (this.destroyed)
|
|
1096
|
+
return;
|
|
1097
|
+
this.capture(() => this.finishNetworkEntry(entry, 'error', performance.now() - startedAt, error instanceof Error ? error.message : String(error)));
|
|
1098
|
+
};
|
|
923
1099
|
}
|
|
924
1100
|
interceptConsole() {
|
|
925
1101
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
@@ -957,7 +1133,9 @@
|
|
|
957
1133
|
this.listen(window, 'error', (event) => {
|
|
958
1134
|
this.capture(() => {
|
|
959
1135
|
var _a;
|
|
960
|
-
const error = event.error instanceof Error
|
|
1136
|
+
const error = event.error instanceof Error
|
|
1137
|
+
? event.error
|
|
1138
|
+
: new Error(String((_a = event.message) !== null && _a !== void 0 ? _a : 'Unknown error'));
|
|
961
1139
|
record({
|
|
962
1140
|
id: nextId(),
|
|
963
1141
|
type: 'JavaScript Error',
|
|
@@ -979,7 +1157,9 @@
|
|
|
979
1157
|
type: 'Promise Rejection',
|
|
980
1158
|
message: truncate(error.message),
|
|
981
1159
|
timestamp: Date.now(),
|
|
982
|
-
stack: this.config.captureStackTraces && reason instanceof Error && reason.stack
|
|
1160
|
+
stack: this.config.captureStackTraces && reason instanceof Error && reason.stack
|
|
1161
|
+
? truncate(reason.stack)
|
|
1162
|
+
: undefined,
|
|
983
1163
|
}, error);
|
|
984
1164
|
});
|
|
985
1165
|
});
|
|
@@ -1015,7 +1195,7 @@
|
|
|
1015
1195
|
}
|
|
1016
1196
|
reportInternal(message, error) {
|
|
1017
1197
|
// Use the unpatched console so internal problems are visible but never captured.
|
|
1018
|
-
const patched = this.patches.find(patch => patch.target === console && patch.key === 'error');
|
|
1198
|
+
const patched = this.patches.find((patch) => patch.target === console && patch.key === 'error');
|
|
1019
1199
|
const log = (patched ? patched.original : console.error);
|
|
1020
1200
|
try {
|
|
1021
1201
|
log.call(console, `[DevInspector] ${message}:`, error);
|
|
@@ -1028,7 +1208,9 @@
|
|
|
1028
1208
|
// Performance loop (runs only while the panel is visible)
|
|
1029
1209
|
// ---------------------------------------------------------------------------
|
|
1030
1210
|
startPerformanceLoop() {
|
|
1031
|
-
if (!this.config.features.performance ||
|
|
1211
|
+
if (!this.config.features.performance ||
|
|
1212
|
+
this.rafId !== null ||
|
|
1213
|
+
typeof requestAnimationFrame !== 'function')
|
|
1032
1214
|
return;
|
|
1033
1215
|
let last = performance.now();
|
|
1034
1216
|
let frames = 0;
|
|
@@ -1104,7 +1286,7 @@
|
|
|
1104
1286
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 13px;
|
|
1105
1287
|
color: ${this.colors.text}; overflow: hidden;`;
|
|
1106
1288
|
// One delegated listener survives every re-render (no per-render listener churn).
|
|
1107
|
-
panel.addEventListener('click', event => this.handlePanelClick(event));
|
|
1289
|
+
panel.addEventListener('click', (event) => this.handlePanelClick(event));
|
|
1108
1290
|
this.widget = widget;
|
|
1109
1291
|
this.panel = panel;
|
|
1110
1292
|
document.body.appendChild(widget);
|
|
@@ -1187,7 +1369,7 @@
|
|
|
1187
1369
|
return;
|
|
1188
1370
|
}
|
|
1189
1371
|
const tabBar = tabs
|
|
1190
|
-
.map(tab => `<button type="button" data-action="tab" data-tab="${tab.id}" style="padding: 12px 16px; border: none; cursor: pointer;
|
|
1372
|
+
.map((tab) => `<button type="button" data-action="tab" data-tab="${tab.id}" style="padding: 12px 16px; border: none; cursor: pointer;
|
|
1191
1373
|
background: ${this.activeTab === tab.id ? c.bg : 'transparent'}; color: ${this.activeTab === tab.id ? '#3b82f6' : c.muted};
|
|
1192
1374
|
border-bottom: 2px solid ${this.activeTab === tab.id ? '#3b82f6' : 'transparent'};">${tab.label}${tab.count !== undefined
|
|
1193
1375
|
? ` <span style="background: #374151; color: white; padding: 2px 6px; border-radius: 10px; font-size: 11px; margin-left: 4px;">${tab.count}</span>`
|
|
@@ -1223,9 +1405,11 @@
|
|
|
1223
1405
|
renderNetwork(button) {
|
|
1224
1406
|
var _a;
|
|
1225
1407
|
const c = this.colors;
|
|
1226
|
-
const visible = this.config.hideAssets
|
|
1408
|
+
const visible = this.config.hideAssets
|
|
1409
|
+
? this.network.filter((entry) => !ASSET_PATTERN.test(entry.url))
|
|
1410
|
+
: this.network;
|
|
1227
1411
|
const rows = visible
|
|
1228
|
-
.map(entry => {
|
|
1412
|
+
.map((entry) => {
|
|
1229
1413
|
var _a;
|
|
1230
1414
|
const selected = entry.id === this.selectedRequestId;
|
|
1231
1415
|
return `<div data-action="select-request" data-id="${escapeHtml(entry.id)}" style="padding: 10px 16px; border-bottom: 1px solid ${c.row}; cursor: pointer; ${selected ? 'background: rgba(59, 130, 246, 0.25);' : ''}">
|
|
@@ -1241,7 +1425,9 @@
|
|
|
1241
1425
|
</div>`;
|
|
1242
1426
|
})
|
|
1243
1427
|
.join('');
|
|
1244
|
-
const selected = this.selectedRequestId
|
|
1428
|
+
const selected = this.selectedRequestId
|
|
1429
|
+
? this.network.find((entry) => entry.id === this.selectedRequestId)
|
|
1430
|
+
: undefined;
|
|
1245
1431
|
const details = selected
|
|
1246
1432
|
? `<div style="border-top: 1px solid ${c.border}; max-height: 200px; overflow-y: auto; background: ${c.toolbar}; padding: 12px 16px; font-size: 12px;">
|
|
1247
1433
|
<div style="display: flex; justify-content: space-between; margin-bottom: 8px;"><strong>Request details</strong>
|
|
@@ -1261,7 +1447,7 @@
|
|
|
1261
1447
|
renderConsole(button) {
|
|
1262
1448
|
const c = this.colors;
|
|
1263
1449
|
const rows = this.consoleEntries
|
|
1264
|
-
.map(entry => `<div style="padding: 8px 16px; border-bottom: 1px solid ${c.row}; font-size: 12px;">
|
|
1450
|
+
.map((entry) => `<div style="padding: 8px 16px; border-bottom: 1px solid ${c.row}; font-size: 12px;">
|
|
1265
1451
|
<span style="color: ${levelColor(entry.level)}; text-transform: uppercase; font-weight: 600;">[${escapeHtml(entry.level)}]</span>
|
|
1266
1452
|
<span style="color: ${c.muted}; margin: 0 8px;">${escapeHtml(new Date(entry.timestamp).toLocaleTimeString())}</span>
|
|
1267
1453
|
<span style="white-space: pre-wrap; word-break: break-word;">${escapeHtml(entry.message)}</span>
|
|
@@ -1275,7 +1461,7 @@
|
|
|
1275
1461
|
const { fps, memory } = this.performanceStats;
|
|
1276
1462
|
const rows = this.metrics
|
|
1277
1463
|
.slice(0, 100)
|
|
1278
|
-
.map(metric => `<div style="padding: 6px 0; border-bottom: 1px solid ${c.row}; font-size: 12px;">
|
|
1464
|
+
.map((metric) => `<div style="padding: 6px 0; border-bottom: 1px solid ${c.row}; font-size: 12px;">
|
|
1279
1465
|
<strong>${escapeHtml(metric.name)}</strong>
|
|
1280
1466
|
${metric.duration !== undefined ? `<span style="color: ${c.muted};"> ${metric.duration.toFixed(1)}ms</span>` : ''}
|
|
1281
1467
|
${metric.data !== undefined ? `<span style="color: ${c.muted};"> ${escapeHtml(truncate(stringifyArg(metric.data)))}</span>` : ''}
|
|
@@ -1299,7 +1485,7 @@
|
|
|
1299
1485
|
renderErrors(button) {
|
|
1300
1486
|
const c = this.colors;
|
|
1301
1487
|
const rows = this.errors
|
|
1302
|
-
.map(error => `<div style="padding: 12px 16px; border-bottom: 1px solid ${c.row};">
|
|
1488
|
+
.map((error) => `<div style="padding: 12px 16px; border-bottom: 1px solid ${c.row};">
|
|
1303
1489
|
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
|
|
1304
1490
|
<span style="color: #ef4444; font-weight: 600;">${escapeHtml(error.type)}</span>
|
|
1305
1491
|
<span style="color: ${c.muted}; font-size: 11px;">${escapeHtml(new Date(error.timestamp).toLocaleTimeString())}</span>
|
|
@@ -1361,17 +1547,25 @@
|
|
|
1361
1547
|
this.tail = 0;
|
|
1362
1548
|
this.size = 0;
|
|
1363
1549
|
this.idCounter = 0;
|
|
1364
|
-
|
|
1550
|
+
const { maxSize } = options;
|
|
1551
|
+
if (typeof maxSize !== 'number' || !Number.isFinite(maxSize) || maxSize < 0) {
|
|
1552
|
+
throw new RangeError(`CircularStorage maxSize must be a non-negative finite number, got ${String(maxSize)}`);
|
|
1553
|
+
}
|
|
1554
|
+
// Fractions are floored; 0 keeps nothing (as the inspectors' entry limits do).
|
|
1555
|
+
this.maxSize = Math.floor(maxSize);
|
|
1365
1556
|
this.ttl = options.ttl;
|
|
1366
1557
|
this.onEvict = options.onEvict;
|
|
1367
1558
|
this.buffer = new Array(this.maxSize);
|
|
1368
1559
|
}
|
|
1369
1560
|
push(data) {
|
|
1370
1561
|
const id = `${Date.now()}-${++this.idCounter}`;
|
|
1562
|
+
// maxSize 0 stores nothing (and the ring arithmetic below would divide by zero).
|
|
1563
|
+
if (this.maxSize === 0)
|
|
1564
|
+
return id;
|
|
1371
1565
|
const entry = {
|
|
1372
1566
|
id,
|
|
1373
1567
|
timestamp: Date.now(),
|
|
1374
|
-
data
|
|
1568
|
+
data,
|
|
1375
1569
|
};
|
|
1376
1570
|
if (this.size === this.maxSize) {
|
|
1377
1571
|
const evictedEntry = this.buffer[this.tail];
|
|
@@ -1395,7 +1589,7 @@
|
|
|
1395
1589
|
return undefined;
|
|
1396
1590
|
}
|
|
1397
1591
|
getAll() {
|
|
1398
|
-
return this.getAllEntries().map(entry => entry.data);
|
|
1592
|
+
return this.getAllEntries().map((entry) => entry.data);
|
|
1399
1593
|
}
|
|
1400
1594
|
getAllEntries() {
|
|
1401
1595
|
const entries = [];
|
|
@@ -1420,8 +1614,8 @@
|
|
|
1420
1614
|
}
|
|
1421
1615
|
filter(predicate) {
|
|
1422
1616
|
return this.getAllEntries()
|
|
1423
|
-
.filter(entry => predicate(entry.data))
|
|
1424
|
-
.map(entry => entry.data);
|
|
1617
|
+
.filter((entry) => predicate(entry.data))
|
|
1618
|
+
.map((entry) => entry.data);
|
|
1425
1619
|
}
|
|
1426
1620
|
clear() {
|
|
1427
1621
|
this.buffer = new Array(this.maxSize);
|
|
@@ -1451,6 +1645,7 @@
|
|
|
1451
1645
|
return now - entry.timestamp > this.ttl;
|
|
1452
1646
|
}
|
|
1453
1647
|
removeExpired() {
|
|
1648
|
+
var _a;
|
|
1454
1649
|
if (!this.ttl)
|
|
1455
1650
|
return 0;
|
|
1456
1651
|
const now = Date.now();
|
|
@@ -1462,8 +1657,8 @@
|
|
|
1462
1657
|
if (entry && !this.isExpired(entry, now)) {
|
|
1463
1658
|
validEntries.push(entry);
|
|
1464
1659
|
}
|
|
1465
|
-
else if (entry
|
|
1466
|
-
this.onEvict(entry);
|
|
1660
|
+
else if (entry) {
|
|
1661
|
+
(_a = this.onEvict) === null || _a === void 0 ? void 0 : _a.call(this, entry);
|
|
1467
1662
|
removedCount++;
|
|
1468
1663
|
}
|
|
1469
1664
|
}
|
|
@@ -1489,7 +1684,7 @@
|
|
|
1489
1684
|
const entry = {
|
|
1490
1685
|
id: key,
|
|
1491
1686
|
timestamp: Date.now(),
|
|
1492
|
-
data
|
|
1687
|
+
data,
|
|
1493
1688
|
};
|
|
1494
1689
|
if (this.storage.has(key)) {
|
|
1495
1690
|
// Optimize: use splice instead of filter to avoid creating new array
|
|
@@ -1539,14 +1734,14 @@
|
|
|
1539
1734
|
this.onEvict(entry);
|
|
1540
1735
|
}
|
|
1541
1736
|
this.storage.delete(key);
|
|
1542
|
-
this.accessOrder = this.accessOrder.filter(k => k !== key);
|
|
1737
|
+
this.accessOrder = this.accessOrder.filter((k) => k !== key);
|
|
1543
1738
|
return true;
|
|
1544
1739
|
}
|
|
1545
1740
|
return false;
|
|
1546
1741
|
}
|
|
1547
1742
|
clear() {
|
|
1548
1743
|
if (this.onEvict) {
|
|
1549
|
-
this.storage.forEach(entry => this.onEvict(entry));
|
|
1744
|
+
this.storage.forEach((entry) => this.onEvict(entry));
|
|
1550
1745
|
}
|
|
1551
1746
|
this.storage.clear();
|
|
1552
1747
|
this.accessOrder = [];
|
|
@@ -1559,8 +1754,8 @@
|
|
|
1559
1754
|
}
|
|
1560
1755
|
getAllValues() {
|
|
1561
1756
|
return Array.from(this.storage.values())
|
|
1562
|
-
.filter(entry => !this.isExpired(entry))
|
|
1563
|
-
.map(entry => entry.data);
|
|
1757
|
+
.filter((entry) => !this.isExpired(entry))
|
|
1758
|
+
.map((entry) => entry.data);
|
|
1564
1759
|
}
|
|
1565
1760
|
updateAccessOrder(key) {
|
|
1566
1761
|
// Optimize: use splice instead of filter to avoid creating new array
|
|
@@ -1583,7 +1778,7 @@
|
|
|
1583
1778
|
expiredKeys.push(key);
|
|
1584
1779
|
}
|
|
1585
1780
|
});
|
|
1586
|
-
expiredKeys.forEach(key => {
|
|
1781
|
+
expiredKeys.forEach((key) => {
|
|
1587
1782
|
if (this.delete(key)) {
|
|
1588
1783
|
removedCount++;
|
|
1589
1784
|
}
|
|
@@ -1606,6 +1801,7 @@
|
|
|
1606
1801
|
this.cleanupFunctions = [];
|
|
1607
1802
|
this.initPromise = null;
|
|
1608
1803
|
this.destroyed = false;
|
|
1804
|
+
this.uninstallingPlugins = new Set();
|
|
1609
1805
|
if (DevInspector.instance) {
|
|
1610
1806
|
console.warn('DevInspector instance already exists. Returning existing instance.');
|
|
1611
1807
|
return DevInspector.instance;
|
|
@@ -1614,19 +1810,19 @@
|
|
|
1614
1810
|
this.events = new EventEmitter({ maxListeners: 100 });
|
|
1615
1811
|
this.networkStorage = new CircularStorage({
|
|
1616
1812
|
maxSize: this.config.maxNetworkEntries,
|
|
1617
|
-
onEvict: (entry) => this.events.emit('network:evict', entry)
|
|
1813
|
+
onEvict: (entry) => this.events.emit('network:evict', entry),
|
|
1618
1814
|
});
|
|
1619
1815
|
this.consoleStorage = new CircularStorage({
|
|
1620
1816
|
maxSize: this.config.maxConsoleEntries,
|
|
1621
|
-
onEvict: (entry) => this.events.emit('console:evict', entry)
|
|
1817
|
+
onEvict: (entry) => this.events.emit('console:evict', entry),
|
|
1622
1818
|
});
|
|
1623
1819
|
this.performanceStorage = new IndexedStorage({
|
|
1624
1820
|
maxSize: 1000,
|
|
1625
|
-
ttl: 60 * 60 * 1000 // 1 hour
|
|
1821
|
+
ttl: 60 * 60 * 1000, // 1 hour
|
|
1626
1822
|
});
|
|
1627
1823
|
this.errorStorage = new CircularStorage({
|
|
1628
1824
|
maxSize: this.config.maxErrorEntries,
|
|
1629
|
-
onEvict: (entry) => this.events.emit('error:evict', entry)
|
|
1825
|
+
onEvict: (entry) => this.events.emit('error:evict', entry),
|
|
1630
1826
|
});
|
|
1631
1827
|
this.pluginSystem = new PluginSystem({
|
|
1632
1828
|
inspector: this,
|
|
@@ -1634,10 +1830,10 @@
|
|
|
1634
1830
|
network: this.networkStorage,
|
|
1635
1831
|
console: this.consoleStorage,
|
|
1636
1832
|
performance: this.performanceStorage,
|
|
1637
|
-
error: this.errorStorage
|
|
1833
|
+
error: this.errorStorage,
|
|
1638
1834
|
},
|
|
1639
1835
|
events: this.events,
|
|
1640
|
-
config: this.config
|
|
1836
|
+
config: this.config,
|
|
1641
1837
|
});
|
|
1642
1838
|
if (this.config.enabled) {
|
|
1643
1839
|
void this.init();
|
|
@@ -1651,7 +1847,7 @@
|
|
|
1651
1847
|
theme: 'auto',
|
|
1652
1848
|
hotkeys: {
|
|
1653
1849
|
toggle: 'ctrl+shift+d',
|
|
1654
|
-
minimize: 'ctrl+shift+m'
|
|
1850
|
+
minimize: 'ctrl+shift+m',
|
|
1655
1851
|
},
|
|
1656
1852
|
features: {
|
|
1657
1853
|
network: true,
|
|
@@ -1660,7 +1856,7 @@
|
|
|
1660
1856
|
errors: true,
|
|
1661
1857
|
state: true,
|
|
1662
1858
|
dom: true,
|
|
1663
|
-
storage: true
|
|
1859
|
+
storage: true,
|
|
1664
1860
|
},
|
|
1665
1861
|
plugins: [],
|
|
1666
1862
|
maxNetworkEntries: 1000,
|
|
@@ -1668,21 +1864,25 @@
|
|
|
1668
1864
|
captureStackTraces: true,
|
|
1669
1865
|
networkFilters: {
|
|
1670
1866
|
hideAssets: false,
|
|
1671
|
-
hideCached: false
|
|
1867
|
+
hideCached: false,
|
|
1672
1868
|
},
|
|
1673
1869
|
onError: () => { },
|
|
1674
1870
|
onPerformanceIssue: () => { },
|
|
1675
1871
|
maxErrorEntries: 100,
|
|
1676
1872
|
slowRequestThreshold: 3000,
|
|
1677
1873
|
workerUrl: undefined,
|
|
1678
|
-
remoteConfig: null
|
|
1874
|
+
remoteConfig: null,
|
|
1679
1875
|
};
|
|
1680
1876
|
return {
|
|
1681
1877
|
...defaultConfig,
|
|
1682
1878
|
...config,
|
|
1683
1879
|
hotkeys: { ...defaultConfig.hotkeys, ...config.hotkeys },
|
|
1684
1880
|
features: { ...defaultConfig.features, ...config.features },
|
|
1685
|
-
networkFilters: { ...defaultConfig.networkFilters, ...config.networkFilters }
|
|
1881
|
+
networkFilters: { ...defaultConfig.networkFilters, ...config.networkFilters },
|
|
1882
|
+
// Invalid limits (negative, NaN, Infinity) fall back to the defaults, as in DevInspector.
|
|
1883
|
+
maxNetworkEntries: normalizeLimit(config.maxNetworkEntries, defaultConfig.maxNetworkEntries),
|
|
1884
|
+
maxConsoleEntries: normalizeLimit(config.maxConsoleEntries, defaultConfig.maxConsoleEntries),
|
|
1885
|
+
maxErrorEntries: normalizeLimit(config.maxErrorEntries, defaultConfig.maxErrorEntries),
|
|
1686
1886
|
};
|
|
1687
1887
|
}
|
|
1688
1888
|
init() {
|
|
@@ -1707,7 +1907,6 @@
|
|
|
1707
1907
|
if (this.destroyed)
|
|
1708
1908
|
return this.teardown();
|
|
1709
1909
|
this.setupHotkeys();
|
|
1710
|
-
this.setupErrorHandlers();
|
|
1711
1910
|
this.initialized = true;
|
|
1712
1911
|
this.events.emit('inspector:ready');
|
|
1713
1912
|
}
|
|
@@ -1795,34 +1994,6 @@
|
|
|
1795
1994
|
document.addEventListener('keydown', handleKeydown);
|
|
1796
1995
|
this.cleanupFunctions.push(() => document.removeEventListener('keydown', handleKeydown));
|
|
1797
1996
|
}
|
|
1798
|
-
setupErrorHandlers() {
|
|
1799
|
-
if (!this.config.features.errors)
|
|
1800
|
-
return;
|
|
1801
|
-
const handleError = (event) => {
|
|
1802
|
-
this.events.emit('error:uncaught', {
|
|
1803
|
-
message: event.message,
|
|
1804
|
-
filename: event.filename,
|
|
1805
|
-
lineno: event.lineno,
|
|
1806
|
-
colno: event.colno,
|
|
1807
|
-
error: event.error,
|
|
1808
|
-
timestamp: Date.now()
|
|
1809
|
-
});
|
|
1810
|
-
};
|
|
1811
|
-
const handleRejection = (event) => {
|
|
1812
|
-
this.events.emit('error:uncaught', {
|
|
1813
|
-
message: 'Unhandled promise rejection',
|
|
1814
|
-
reason: event.reason,
|
|
1815
|
-
promise: event.promise,
|
|
1816
|
-
timestamp: Date.now()
|
|
1817
|
-
});
|
|
1818
|
-
};
|
|
1819
|
-
window.addEventListener('error', handleError);
|
|
1820
|
-
window.addEventListener('unhandledrejection', handleRejection);
|
|
1821
|
-
this.cleanupFunctions.push(() => {
|
|
1822
|
-
window.removeEventListener('error', handleError);
|
|
1823
|
-
window.removeEventListener('unhandledrejection', handleRejection);
|
|
1824
|
-
});
|
|
1825
|
-
}
|
|
1826
1997
|
getKeyCombo(event) {
|
|
1827
1998
|
const parts = [];
|
|
1828
1999
|
if (event.ctrlKey)
|
|
@@ -1841,11 +2012,13 @@
|
|
|
1841
2012
|
if (this.destroyed)
|
|
1842
2013
|
return;
|
|
1843
2014
|
if (!this.initialized) {
|
|
1844
|
-
this.init()
|
|
2015
|
+
this.init()
|
|
2016
|
+
.then(() => {
|
|
1845
2017
|
// Only retry show() once init has actually succeeded (no retry loop on failure).
|
|
1846
2018
|
if (this.initialized && !this.destroyed)
|
|
1847
2019
|
this.show();
|
|
1848
|
-
})
|
|
2020
|
+
})
|
|
2021
|
+
.catch((err) => {
|
|
1849
2022
|
var _a, _b;
|
|
1850
2023
|
console.error('Failed to show inspector:', err);
|
|
1851
2024
|
(_b = (_a = this.config).onError) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
|
@@ -1879,7 +2052,7 @@
|
|
|
1879
2052
|
}
|
|
1880
2053
|
teardown() {
|
|
1881
2054
|
var _a;
|
|
1882
|
-
this.monitors.forEach(monitor => {
|
|
2055
|
+
this.monitors.forEach((monitor) => {
|
|
1883
2056
|
var _a;
|
|
1884
2057
|
try {
|
|
1885
2058
|
(_a = monitor.stop) === null || _a === void 0 ? void 0 : _a.call(monitor);
|
|
@@ -1891,8 +2064,24 @@
|
|
|
1891
2064
|
this.monitors.clear();
|
|
1892
2065
|
(_a = this.ui) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
1893
2066
|
this.ui = null;
|
|
1894
|
-
this.cleanupFunctions.forEach(cleanup => cleanup());
|
|
2067
|
+
this.cleanupFunctions.forEach((cleanup) => cleanup());
|
|
1895
2068
|
this.cleanupFunctions = [];
|
|
2069
|
+
this.uninstallPlugins();
|
|
2070
|
+
}
|
|
2071
|
+
/** Disables and uninstalls every registered plugin; failures are reported, not thrown. */
|
|
2072
|
+
uninstallPlugins(names = this.pluginSystem.getAll().map((plugin) => plugin.name)) {
|
|
2073
|
+
for (const name of names) {
|
|
2074
|
+
// teardown() can run twice (destroy() during init); uninstall each plugin once.
|
|
2075
|
+
if (this.uninstallingPlugins.has(name))
|
|
2076
|
+
continue;
|
|
2077
|
+
this.uninstallingPlugins.add(name);
|
|
2078
|
+
this.pluginSystem
|
|
2079
|
+
.unregister(name)
|
|
2080
|
+
.catch((error) => {
|
|
2081
|
+
console.error(`DevInspector: failed to uninstall plugin "${name}"`, error);
|
|
2082
|
+
})
|
|
2083
|
+
.finally(() => this.uninstallingPlugins.delete(name));
|
|
2084
|
+
}
|
|
1896
2085
|
}
|
|
1897
2086
|
destroy() {
|
|
1898
2087
|
// A destroy() during the asynchronous init is honoured once init resumes.
|
|
@@ -1906,7 +2095,7 @@
|
|
|
1906
2095
|
this.events.emit('performance:metric', {
|
|
1907
2096
|
name,
|
|
1908
2097
|
data,
|
|
1909
|
-
timestamp: Date.now()
|
|
2098
|
+
timestamp: Date.now(),
|
|
1910
2099
|
});
|
|
1911
2100
|
}
|
|
1912
2101
|
markStart(name) {
|
|
@@ -1922,7 +2111,14 @@
|
|
|
1922
2111
|
}
|
|
1923
2112
|
}
|
|
1924
2113
|
async use(plugin) {
|
|
2114
|
+
if (this.destroyed)
|
|
2115
|
+
throw new Error('DevInspector has been destroyed');
|
|
1925
2116
|
await this.pluginSystem.register(plugin);
|
|
2117
|
+
if (this.destroyed) {
|
|
2118
|
+
// destroy() ran while install() was pending and could not see the plugin yet.
|
|
2119
|
+
this.uninstallPlugins([plugin.name]);
|
|
2120
|
+
throw new Error('DevInspector has been destroyed');
|
|
2121
|
+
}
|
|
1926
2122
|
}
|
|
1927
2123
|
export() {
|
|
1928
2124
|
return {
|
|
@@ -1933,8 +2129,8 @@
|
|
|
1933
2129
|
network: this.networkStorage.getAll(),
|
|
1934
2130
|
console: this.consoleStorage.getAll(),
|
|
1935
2131
|
performance: this.performanceStorage.getAllValues(),
|
|
1936
|
-
errors: this.errorStorage.getAll()
|
|
1937
|
-
}
|
|
2132
|
+
errors: this.errorStorage.getAll(),
|
|
2133
|
+
},
|
|
1938
2134
|
};
|
|
1939
2135
|
}
|
|
1940
2136
|
import(data) {
|
|
@@ -1952,10 +2148,14 @@
|
|
|
1952
2148
|
}
|
|
1953
2149
|
getStorage(type) {
|
|
1954
2150
|
switch (type) {
|
|
1955
|
-
case 'network':
|
|
1956
|
-
|
|
1957
|
-
case '
|
|
1958
|
-
|
|
2151
|
+
case 'network':
|
|
2152
|
+
return this.networkStorage;
|
|
2153
|
+
case 'console':
|
|
2154
|
+
return this.consoleStorage;
|
|
2155
|
+
case 'performance':
|
|
2156
|
+
return this.performanceStorage;
|
|
2157
|
+
case 'error':
|
|
2158
|
+
return this.errorStorage;
|
|
1959
2159
|
}
|
|
1960
2160
|
}
|
|
1961
2161
|
getConfig() {
|
|
@@ -1992,7 +2192,7 @@
|
|
|
1992
2192
|
enabled: defaultEnabled(),
|
|
1993
2193
|
position: 'bottom-right',
|
|
1994
2194
|
theme: 'dark',
|
|
1995
|
-
...config
|
|
2195
|
+
...config,
|
|
1996
2196
|
};
|
|
1997
2197
|
if (this.config.enabled && hasDom()) {
|
|
1998
2198
|
this.init();
|
|
@@ -2239,7 +2439,7 @@
|
|
|
2239
2439
|
return {
|
|
2240
2440
|
name: value.name,
|
|
2241
2441
|
message: value.message,
|
|
2242
|
-
stack: value.stack
|
|
2442
|
+
stack: value.stack,
|
|
2243
2443
|
};
|
|
2244
2444
|
}
|
|
2245
2445
|
return value;
|
|
@@ -2250,8 +2450,8 @@
|
|
|
2250
2450
|
return stack
|
|
2251
2451
|
.split('\n')
|
|
2252
2452
|
.slice(1)
|
|
2253
|
-
.map(line => line.trim())
|
|
2254
|
-
.filter(line => line.startsWith('at '));
|
|
2453
|
+
.map((line) => line.trim())
|
|
2454
|
+
.filter((line) => line.startsWith('at '));
|
|
2255
2455
|
}
|
|
2256
2456
|
function parseStackFrame(frame) {
|
|
2257
2457
|
const match = frame.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);
|
|
@@ -2263,7 +2463,7 @@
|
|
|
2263
2463
|
functionName: functionName || '<anonymous>',
|
|
2264
2464
|
fileName: fileName || '<unknown>',
|
|
2265
2465
|
lineNumber: parseInt(lineNumber || '0', 10),
|
|
2266
|
-
columnNumber: parseInt(columnNumber || '0', 10)
|
|
2466
|
+
columnNumber: parseInt(columnNumber || '0', 10),
|
|
2267
2467
|
};
|
|
2268
2468
|
}
|
|
2269
2469
|
|
|
@@ -2282,26 +2482,28 @@
|
|
|
2282
2482
|
if (this.installed || typeof this.originalFetch !== 'function')
|
|
2283
2483
|
return;
|
|
2284
2484
|
const instrumented = async function (input, init) {
|
|
2285
|
-
|
|
2485
|
+
// Uninstalled but still wrapped by someone else: pass straight through.
|
|
2486
|
+
if (self.installed !== instrumented)
|
|
2487
|
+
return self.originalFetch.apply(this !== null && this !== void 0 ? this : window, [input, init]);
|
|
2286
2488
|
const id = generateId();
|
|
2287
2489
|
const startTime = performance.now();
|
|
2288
2490
|
let url;
|
|
2289
2491
|
let method;
|
|
2290
2492
|
let headers = {};
|
|
2291
2493
|
let body;
|
|
2494
|
+
let bodyPreview;
|
|
2495
|
+
let stopPreview;
|
|
2496
|
+
const previewStopped = new Promise((resolve) => (stopPreview = resolve));
|
|
2292
2497
|
if (typeof Request !== 'undefined' && input instanceof Request) {
|
|
2293
2498
|
url = input.url;
|
|
2294
2499
|
method = input.method;
|
|
2295
2500
|
input.headers.forEach((value, key) => {
|
|
2296
2501
|
headers[key] = value;
|
|
2297
2502
|
});
|
|
2298
|
-
//
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
catch (e) {
|
|
2303
|
-
body = '[Body unavailable - request already used]';
|
|
2304
|
-
}
|
|
2503
|
+
// The clone is taken synchronously (before the real fetch reads the body);
|
|
2504
|
+
// the preview is read from it in the background, so the real fetch starts
|
|
2505
|
+
// at once even for a streaming upload whose next chunk is not ready yet.
|
|
2506
|
+
bodyPreview = self.extractBody(input, previewStopped);
|
|
2305
2507
|
}
|
|
2306
2508
|
else {
|
|
2307
2509
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string -- a URL object here
|
|
@@ -2324,43 +2526,67 @@
|
|
|
2324
2526
|
}
|
|
2325
2527
|
body = init === null || init === void 0 ? void 0 : init.body;
|
|
2326
2528
|
}
|
|
2327
|
-
|
|
2328
|
-
id,
|
|
2329
|
-
method,
|
|
2330
|
-
url,
|
|
2331
|
-
headers,
|
|
2332
|
-
body: self.sanitizeBody(body),
|
|
2333
|
-
timestamp: Date.now(),
|
|
2334
|
-
type: 'fetch'
|
|
2335
|
-
};
|
|
2336
|
-
self.requestMap.set(id, request);
|
|
2337
|
-
(_b = (_a = self.handlers).onRequest) === null || _b === void 0 ? void 0 : _b.call(_a, request);
|
|
2338
|
-
let response;
|
|
2529
|
+
let pending;
|
|
2339
2530
|
try {
|
|
2340
|
-
|
|
2531
|
+
pending = Promise.resolve(self.originalFetch.apply(this !== null && this !== void 0 ? this : window, [input, init]));
|
|
2341
2532
|
}
|
|
2342
2533
|
catch (error) {
|
|
2343
|
-
|
|
2534
|
+
pending = Promise.reject(error);
|
|
2535
|
+
}
|
|
2536
|
+
// onRequest fires once the body preview is ready; response and error reports
|
|
2537
|
+
// are queued behind it so handlers always see the request first.
|
|
2538
|
+
const requestReported = (async () => {
|
|
2539
|
+
var _a, _b;
|
|
2540
|
+
if (bodyPreview)
|
|
2541
|
+
body = await bodyPreview;
|
|
2542
|
+
const request = {
|
|
2344
2543
|
id,
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2544
|
+
method,
|
|
2545
|
+
url,
|
|
2546
|
+
headers,
|
|
2547
|
+
body: self.sanitizeBody(body),
|
|
2548
|
+
timestamp: Date.now(),
|
|
2549
|
+
type: 'fetch',
|
|
2348
2550
|
};
|
|
2349
|
-
|
|
2350
|
-
self.
|
|
2551
|
+
self.requestMap.set(id, request);
|
|
2552
|
+
(_b = (_a = self.handlers).onRequest) === null || _b === void 0 ? void 0 : _b.call(_a, request);
|
|
2553
|
+
})().catch(() => undefined);
|
|
2554
|
+
let response;
|
|
2555
|
+
try {
|
|
2556
|
+
response = await pending;
|
|
2557
|
+
}
|
|
2558
|
+
catch (error) {
|
|
2559
|
+
// The body will not be sent any more: stop reading its preview.
|
|
2560
|
+
stopPreview();
|
|
2561
|
+
void requestReported.then(() => {
|
|
2562
|
+
var _a, _b;
|
|
2563
|
+
const networkError = {
|
|
2564
|
+
id,
|
|
2565
|
+
message: (error === null || error === void 0 ? void 0 : error.message) || 'Network request failed',
|
|
2566
|
+
stack: error === null || error === void 0 ? void 0 : error.stack,
|
|
2567
|
+
timestamp: Date.now(),
|
|
2568
|
+
};
|
|
2569
|
+
try {
|
|
2570
|
+
(_b = (_a = self.handlers).onError) === null || _b === void 0 ? void 0 : _b.call(_a, networkError);
|
|
2571
|
+
}
|
|
2572
|
+
catch (_c) {
|
|
2573
|
+
// A failing handler must not replace the page's own error.
|
|
2574
|
+
}
|
|
2575
|
+
self.requestMap.delete(id);
|
|
2576
|
+
});
|
|
2351
2577
|
throw error;
|
|
2352
2578
|
}
|
|
2353
2579
|
// Hand the response to the caller right away. The body preview is read from
|
|
2354
2580
|
// a clone in the background (capped), so streaming responses (SSE, long
|
|
2355
2581
|
// polling, large downloads) are never held back by the inspector.
|
|
2356
2582
|
const duration = performance.now() - startTime;
|
|
2357
|
-
void self.reportResponse(id, response, duration);
|
|
2583
|
+
void self.reportResponse(id, response, duration, requestReported);
|
|
2358
2584
|
return response;
|
|
2359
2585
|
};
|
|
2360
2586
|
this.installed = instrumented;
|
|
2361
2587
|
window.fetch = instrumented;
|
|
2362
2588
|
}
|
|
2363
|
-
async reportResponse(id, response, duration) {
|
|
2589
|
+
async reportResponse(id, response, duration, after) {
|
|
2364
2590
|
var _a, _b;
|
|
2365
2591
|
try {
|
|
2366
2592
|
const responseHeaders = {};
|
|
@@ -2369,11 +2595,14 @@
|
|
|
2369
2595
|
});
|
|
2370
2596
|
let responseBody;
|
|
2371
2597
|
try {
|
|
2372
|
-
responseBody = response.bodyUsed
|
|
2598
|
+
responseBody = response.bodyUsed
|
|
2599
|
+
? '[Body already read]'
|
|
2600
|
+
: await this.extractResponseBody(response.clone());
|
|
2373
2601
|
}
|
|
2374
2602
|
catch (_c) {
|
|
2375
2603
|
responseBody = '[Unable to read response]';
|
|
2376
2604
|
}
|
|
2605
|
+
await after;
|
|
2377
2606
|
(_b = (_a = this.handlers).onResponse) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
2378
2607
|
id,
|
|
2379
2608
|
status: response.status,
|
|
@@ -2383,7 +2612,7 @@
|
|
|
2383
2612
|
size: this.calculateSize(responseBody, responseHeaders),
|
|
2384
2613
|
duration,
|
|
2385
2614
|
timestamp: Date.now(),
|
|
2386
|
-
fromCache: this.isFromCache(response, duration)
|
|
2615
|
+
fromCache: this.isFromCache(response, duration),
|
|
2387
2616
|
});
|
|
2388
2617
|
}
|
|
2389
2618
|
catch (_d) {
|
|
@@ -2394,29 +2623,32 @@
|
|
|
2394
2623
|
}
|
|
2395
2624
|
}
|
|
2396
2625
|
uninstall() {
|
|
2397
|
-
if (this.installed
|
|
2398
|
-
window
|
|
2399
|
-
}
|
|
2626
|
+
if (this.installed)
|
|
2627
|
+
restorePatch(window, 'fetch', this.installed, this.originalFetch);
|
|
2400
2628
|
this.installed = null;
|
|
2401
2629
|
this.requestMap.clear();
|
|
2402
2630
|
}
|
|
2403
|
-
|
|
2631
|
+
/**
|
|
2632
|
+
* Previews a Request body. Everything up to the clone runs synchronously, so
|
|
2633
|
+
* call it before the real fetch takes the body. Only previewable bodies are
|
|
2634
|
+
* cloned (an unread clone would buffer the whole upload).
|
|
2635
|
+
*/
|
|
2636
|
+
async extractBody(request, stop) {
|
|
2404
2637
|
try {
|
|
2405
|
-
const contentType = request.headers.get('content-type') || '';
|
|
2406
2638
|
if (request.bodyUsed) {
|
|
2407
2639
|
return '[Body already read]';
|
|
2408
2640
|
}
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
return await this.readPreview(cloned, true);
|
|
2412
|
-
}
|
|
2413
|
-
else if (contentType.includes('text/')) {
|
|
2414
|
-
return await this.readPreview(cloned, false);
|
|
2641
|
+
if (!request.body) {
|
|
2642
|
+
return undefined;
|
|
2415
2643
|
}
|
|
2416
|
-
|
|
2417
|
-
|
|
2644
|
+
const contentType = request.headers.get('content-type') || '';
|
|
2645
|
+
const asJson = contentType.includes('application/json');
|
|
2646
|
+
if (asJson ||
|
|
2647
|
+
contentType.includes('text/') ||
|
|
2648
|
+
contentType.includes('application/x-www-form-urlencoded')) {
|
|
2649
|
+
return await this.readPreview(request.clone(), asJson, stop);
|
|
2418
2650
|
}
|
|
2419
|
-
|
|
2651
|
+
if (contentType.includes('multipart/form-data')) {
|
|
2420
2652
|
return '[FormData]';
|
|
2421
2653
|
}
|
|
2422
2654
|
return '[Binary data]';
|
|
@@ -2426,11 +2658,13 @@
|
|
|
2426
2658
|
}
|
|
2427
2659
|
}
|
|
2428
2660
|
/** Reads at most MAX_BODY_PREVIEW bytes from a cloned body, then cancels the clone. */
|
|
2429
|
-
async readCapped(body) {
|
|
2661
|
+
async readCapped(body, stop) {
|
|
2430
2662
|
const stream = body.body;
|
|
2431
2663
|
if (!stream || typeof stream.getReader !== 'function') {
|
|
2432
2664
|
const text = await body.text();
|
|
2433
|
-
return text.length > MAX_BODY_PREVIEW
|
|
2665
|
+
return text.length > MAX_BODY_PREVIEW
|
|
2666
|
+
? { text: text.slice(0, MAX_BODY_PREVIEW), truncated: true }
|
|
2667
|
+
: { text, truncated: false };
|
|
2434
2668
|
}
|
|
2435
2669
|
const reader = stream.getReader();
|
|
2436
2670
|
const decoder = new TextDecoder();
|
|
@@ -2438,7 +2672,12 @@
|
|
|
2438
2672
|
let received = 0;
|
|
2439
2673
|
try {
|
|
2440
2674
|
for (;;) {
|
|
2441
|
-
const
|
|
2675
|
+
const next = await (stop
|
|
2676
|
+
? Promise.race([reader.read(), stop.then(() => null)])
|
|
2677
|
+
: reader.read());
|
|
2678
|
+
if (!next)
|
|
2679
|
+
return { text: text + decoder.decode(), truncated: true };
|
|
2680
|
+
const { done, value } = next;
|
|
2442
2681
|
if (done)
|
|
2443
2682
|
return { text: text + decoder.decode(), truncated: false };
|
|
2444
2683
|
received += value.byteLength;
|
|
@@ -2451,8 +2690,8 @@
|
|
|
2451
2690
|
reader.cancel().catch(() => undefined);
|
|
2452
2691
|
}
|
|
2453
2692
|
}
|
|
2454
|
-
async readPreview(body, asJson) {
|
|
2455
|
-
const { text, truncated } = await this.readCapped(body);
|
|
2693
|
+
async readPreview(body, asJson, stop) {
|
|
2694
|
+
const { text, truncated } = await this.readCapped(body, stop);
|
|
2456
2695
|
if (truncated)
|
|
2457
2696
|
return `${text}... [truncated]`;
|
|
2458
2697
|
if (asJson) {
|
|
@@ -2569,11 +2808,15 @@
|
|
|
2569
2808
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
2570
2809
|
const self = this;
|
|
2571
2810
|
XMLHttpRequest.prototype.open = function (method, url, async = true, username, password) {
|
|
2811
|
+
var _a;
|
|
2812
|
+
const result = self.originalOpen.apply(this, [method, url, async, username, password]);
|
|
2813
|
+
// open() on a request in flight cancels it without abort/loadend events.
|
|
2814
|
+
(_a = this._devinspectorCancel) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
2572
2815
|
this._devinspectorId = generateId();
|
|
2573
2816
|
this._devinspectorMethod = method;
|
|
2574
2817
|
this._devinspectorUrl = url.toString();
|
|
2575
2818
|
this._devinspectorRequestHeaders = {};
|
|
2576
|
-
return
|
|
2819
|
+
return result;
|
|
2577
2820
|
};
|
|
2578
2821
|
XMLHttpRequest.prototype.setRequestHeader = function (name, value) {
|
|
2579
2822
|
if (this._devinspectorRequestHeaders) {
|
|
@@ -2583,98 +2826,103 @@
|
|
|
2583
2826
|
};
|
|
2584
2827
|
XMLHttpRequest.prototype.send = function (body) {
|
|
2585
2828
|
var _a, _b;
|
|
2586
|
-
|
|
2829
|
+
// Uninstalled but still wrapped by someone else, or a second send() on a request
|
|
2830
|
+
// in flight (the native send() throws): pass straight through.
|
|
2831
|
+
if (!self.installed || this._devinspectorCancel)
|
|
2832
|
+
return self.originalSend.apply(this, [body]);
|
|
2833
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
2834
|
+
const xhr = this;
|
|
2835
|
+
const id = this._devinspectorId;
|
|
2836
|
+
const startTime = performance.now();
|
|
2837
|
+
this._devinspectorStartTime = startTime;
|
|
2587
2838
|
this._devinspectorRequestBody = self.sanitizeBody(body);
|
|
2588
2839
|
const request = {
|
|
2589
|
-
id
|
|
2840
|
+
id,
|
|
2590
2841
|
method: this._devinspectorMethod,
|
|
2591
2842
|
url: this._devinspectorUrl,
|
|
2592
2843
|
headers: this._devinspectorRequestHeaders || {},
|
|
2593
2844
|
body: this._devinspectorRequestBody,
|
|
2594
2845
|
timestamp: Date.now(),
|
|
2595
|
-
type: 'xhr'
|
|
2846
|
+
type: 'xhr',
|
|
2596
2847
|
};
|
|
2597
2848
|
(_b = (_a = self.handlers).onRequest) === null || _b === void 0 ? void 0 : _b.call(_a, request);
|
|
2598
|
-
//
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2849
|
+
// Listeners belong to this one request and are removed when it ends, so a
|
|
2850
|
+
// reused XHR reports every response once.
|
|
2851
|
+
const listeners = [];
|
|
2852
|
+
const listen = (target, type, handler) => {
|
|
2853
|
+
target.addEventListener(type, handler);
|
|
2854
|
+
listeners.push([target, type, handler]);
|
|
2855
|
+
};
|
|
2856
|
+
let ended = false;
|
|
2857
|
+
const detach = () => {
|
|
2858
|
+
ended = true;
|
|
2859
|
+
for (const [target, type, handler] of listeners)
|
|
2860
|
+
target.removeEventListener(type, handler);
|
|
2861
|
+
listeners.length = 0;
|
|
2862
|
+
if (xhr._devinspectorCancel === cancel)
|
|
2863
|
+
xhr._devinspectorCancel = undefined;
|
|
2864
|
+
};
|
|
2865
|
+
const fail = (message) => {
|
|
2866
|
+
var _a, _b;
|
|
2867
|
+
(_b = (_a = self.handlers).onError) === null || _b === void 0 ? void 0 : _b.call(_a, { id, message, timestamp: Date.now() });
|
|
2868
|
+
};
|
|
2869
|
+
const cancel = () => {
|
|
2870
|
+
detach();
|
|
2871
|
+
fail('Request aborted');
|
|
2872
|
+
};
|
|
2873
|
+
const onProgress = (event) => {
|
|
2874
|
+
var _a, _b;
|
|
2875
|
+
if (event.lengthComputable) {
|
|
2876
|
+
(_b = (_a = self.handlers).onProgress) === null || _b === void 0 ? void 0 : _b.call(_a, { id, loaded: event.loaded, total: event.total });
|
|
2877
|
+
}
|
|
2878
|
+
};
|
|
2611
2879
|
if (self.handlers.onProgress) {
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
loaded: event.loaded,
|
|
2617
|
-
total: event.total
|
|
2618
|
-
});
|
|
2619
|
-
}
|
|
2620
|
-
});
|
|
2880
|
+
// Track upload and download progress
|
|
2881
|
+
if (this.upload)
|
|
2882
|
+
listen(this.upload, 'progress', onProgress);
|
|
2883
|
+
listen(this, 'progress', onProgress);
|
|
2621
2884
|
}
|
|
2622
|
-
|
|
2623
|
-
this.addEventListener('load', function () {
|
|
2885
|
+
listen(this, 'load', () => {
|
|
2624
2886
|
var _a, _b;
|
|
2625
|
-
const duration = performance.now() -
|
|
2626
|
-
const responseHeaders = self.parseResponseHeaders(
|
|
2627
|
-
const responseBody = self.extractResponseBody(
|
|
2887
|
+
const duration = performance.now() - startTime;
|
|
2888
|
+
const responseHeaders = self.parseResponseHeaders(xhr.getAllResponseHeaders());
|
|
2889
|
+
const responseBody = self.extractResponseBody(xhr);
|
|
2628
2890
|
const size = self.calculateSize(responseBody, responseHeaders);
|
|
2629
2891
|
const response = {
|
|
2630
|
-
id
|
|
2631
|
-
status:
|
|
2632
|
-
statusText:
|
|
2892
|
+
id,
|
|
2893
|
+
status: xhr.status,
|
|
2894
|
+
statusText: xhr.statusText,
|
|
2633
2895
|
headers: responseHeaders,
|
|
2634
2896
|
body: responseBody,
|
|
2635
2897
|
size,
|
|
2636
2898
|
duration,
|
|
2637
2899
|
timestamp: Date.now(),
|
|
2638
|
-
fromCache: duration < 5
|
|
2900
|
+
fromCache: duration < 5,
|
|
2639
2901
|
};
|
|
2640
2902
|
(_b = (_a = self.handlers).onResponse) === null || _b === void 0 ? void 0 : _b.call(_a, response);
|
|
2641
2903
|
});
|
|
2642
|
-
|
|
2643
|
-
this
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
};
|
|
2660
|
-
(_b = (_a = self.handlers).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
2661
|
-
});
|
|
2662
|
-
// Handle abort event
|
|
2663
|
-
this.addEventListener('abort', function () {
|
|
2664
|
-
var _a, _b;
|
|
2665
|
-
const error = {
|
|
2666
|
-
id: this._devinspectorId,
|
|
2667
|
-
message: 'Request aborted',
|
|
2668
|
-
timestamp: Date.now()
|
|
2669
|
-
};
|
|
2670
|
-
(_b = (_a = self.handlers).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
2671
|
-
});
|
|
2672
|
-
return self.originalSend.apply(this, [body]);
|
|
2904
|
+
listen(this, 'error', () => fail('Network request failed'));
|
|
2905
|
+
listen(this, 'timeout', () => fail(`Request timeout after ${xhr.timeout}ms`));
|
|
2906
|
+
listen(this, 'abort', () => fail('Request aborted'));
|
|
2907
|
+
listen(this, 'loadend', detach);
|
|
2908
|
+
this._devinspectorCancel = cancel;
|
|
2909
|
+
try {
|
|
2910
|
+
return self.originalSend.apply(this, [body]);
|
|
2911
|
+
}
|
|
2912
|
+
catch (error) {
|
|
2913
|
+
// No request was started (e.g. a synchronous network error), unless its
|
|
2914
|
+
// events were already dispatched and reported.
|
|
2915
|
+
if (!ended) {
|
|
2916
|
+
detach();
|
|
2917
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
2918
|
+
}
|
|
2919
|
+
throw error;
|
|
2920
|
+
}
|
|
2673
2921
|
};
|
|
2674
2922
|
this.installed = {
|
|
2675
2923
|
open: XMLHttpRequest.prototype.open,
|
|
2676
2924
|
send: XMLHttpRequest.prototype.send,
|
|
2677
|
-
setRequestHeader: XMLHttpRequest.prototype.setRequestHeader
|
|
2925
|
+
setRequestHeader: XMLHttpRequest.prototype.setRequestHeader,
|
|
2678
2926
|
};
|
|
2679
2927
|
}
|
|
2680
2928
|
uninstall() {
|
|
@@ -2682,12 +2930,9 @@
|
|
|
2682
2930
|
return;
|
|
2683
2931
|
const proto = XMLHttpRequest.prototype;
|
|
2684
2932
|
// Only restore methods that nobody has wrapped since we installed ours.
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
proto.send = this.originalSend;
|
|
2689
|
-
if (proto.setRequestHeader === this.installed.setRequestHeader)
|
|
2690
|
-
proto.setRequestHeader = this.originalSetRequestHeader;
|
|
2933
|
+
restorePatch(proto, 'open', this.installed.open, this.originalOpen);
|
|
2934
|
+
restorePatch(proto, 'send', this.installed.send, this.originalSend);
|
|
2935
|
+
restorePatch(proto, 'setRequestHeader', this.installed.setRequestHeader, this.originalSetRequestHeader);
|
|
2691
2936
|
this.installed = null;
|
|
2692
2937
|
}
|
|
2693
2938
|
sanitizeBody(body) {
|
|
@@ -2724,7 +2969,7 @@
|
|
|
2724
2969
|
if (!headersString)
|
|
2725
2970
|
return headers;
|
|
2726
2971
|
const lines = headersString.trim().split(/[\r\n]+/);
|
|
2727
|
-
lines.forEach(line => {
|
|
2972
|
+
lines.forEach((line) => {
|
|
2728
2973
|
const parts = line.split(': ');
|
|
2729
2974
|
const key = parts.shift();
|
|
2730
2975
|
if (key) {
|
|
@@ -2801,8 +3046,14 @@
|
|
|
2801
3046
|
if (typeof OriginalWebSocket !== 'function' || this.installed)
|
|
2802
3047
|
return;
|
|
2803
3048
|
const MonitoredWebSocket = function (url, protocols) {
|
|
2804
|
-
var _a, _b;
|
|
2805
|
-
|
|
3049
|
+
var _a, _b, _c;
|
|
3050
|
+
// Construct with the caller's new.target so `class X extends WebSocket` keeps
|
|
3051
|
+
// X's prototype; argument handling stays with the native constructor.
|
|
3052
|
+
const args = protocols === undefined ? [url] : [url, protocols];
|
|
3053
|
+
const ws = Reflect.construct(OriginalWebSocket, args, (_a = new.target) !== null && _a !== void 0 ? _a : OriginalWebSocket);
|
|
3054
|
+
// Uninstalled but still wrapped by someone else: pass straight through.
|
|
3055
|
+
if (self.installed !== MonitoredWebSocket)
|
|
3056
|
+
return ws;
|
|
2806
3057
|
const connectionId = generateId();
|
|
2807
3058
|
ws._devinspectorId = connectionId;
|
|
2808
3059
|
ws._devinspectorUrl = url.toString();
|
|
@@ -2813,10 +3064,10 @@
|
|
|
2813
3064
|
protocols,
|
|
2814
3065
|
timestamp: Date.now(),
|
|
2815
3066
|
readyState: ws.readyState,
|
|
2816
|
-
status: 'connecting'
|
|
3067
|
+
status: 'connecting',
|
|
2817
3068
|
};
|
|
2818
3069
|
self.connections.set(connectionId, connection);
|
|
2819
|
-
(
|
|
3070
|
+
(_c = (_b = self.handlers).onConnection) === null || _c === void 0 ? void 0 : _c.call(_b, connection);
|
|
2820
3071
|
// Monitor open event
|
|
2821
3072
|
ws.addEventListener('open', function () {
|
|
2822
3073
|
var _a, _b;
|
|
@@ -2826,7 +3077,7 @@
|
|
|
2826
3077
|
conn.readyState = this.readyState;
|
|
2827
3078
|
(_b = (_a = self.handlers).onStatusChange) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
2828
3079
|
connectionId,
|
|
2829
|
-
status: 'open'
|
|
3080
|
+
status: 'open',
|
|
2830
3081
|
});
|
|
2831
3082
|
}
|
|
2832
3083
|
});
|
|
@@ -2840,7 +3091,7 @@
|
|
|
2840
3091
|
conn.readyState = this.readyState;
|
|
2841
3092
|
(_b = (_a = self.handlers).onStatusChange) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
2842
3093
|
connectionId,
|
|
2843
|
-
status: 'closed'
|
|
3094
|
+
status: 'closed',
|
|
2844
3095
|
});
|
|
2845
3096
|
}
|
|
2846
3097
|
self.connections.delete(connectionId);
|
|
@@ -2853,7 +3104,7 @@
|
|
|
2853
3104
|
id: generateId(),
|
|
2854
3105
|
connectionId,
|
|
2855
3106
|
message: 'WebSocket error occurred',
|
|
2856
|
-
timestamp: Date.now()
|
|
3107
|
+
timestamp: Date.now(),
|
|
2857
3108
|
};
|
|
2858
3109
|
(_b = (_a = self.handlers).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
2859
3110
|
});
|
|
@@ -2866,7 +3117,7 @@
|
|
|
2866
3117
|
type: 'received',
|
|
2867
3118
|
data: self.parseMessageData(event.data),
|
|
2868
3119
|
timestamp: Date.now(),
|
|
2869
|
-
size: self.calculateMessageSize(event.data)
|
|
3120
|
+
size: self.calculateMessageSize(event.data),
|
|
2870
3121
|
};
|
|
2871
3122
|
(_b = (_a = self.handlers).onMessage) === null || _b === void 0 ? void 0 : _b.call(_a, message);
|
|
2872
3123
|
});
|
|
@@ -2880,7 +3131,7 @@
|
|
|
2880
3131
|
type: 'sent',
|
|
2881
3132
|
data: self.parseMessageData(data),
|
|
2882
3133
|
timestamp: Date.now(),
|
|
2883
|
-
size: self.calculateMessageSize(data)
|
|
3134
|
+
size: self.calculateMessageSize(data),
|
|
2884
3135
|
};
|
|
2885
3136
|
(_b = (_a = self.handlers).onMessage) === null || _b === void 0 ? void 0 : _b.call(_a, message);
|
|
2886
3137
|
return originalSend(data);
|
|
@@ -2895,7 +3146,7 @@
|
|
|
2895
3146
|
conn.readyState = this.readyState;
|
|
2896
3147
|
(_b = (_a = self.handlers).onStatusChange) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
2897
3148
|
connectionId,
|
|
2898
|
-
status: 'closing'
|
|
3149
|
+
status: 'closing',
|
|
2899
3150
|
});
|
|
2900
3151
|
}
|
|
2901
3152
|
return originalClose(code, reason);
|
|
@@ -2911,9 +3162,8 @@
|
|
|
2911
3162
|
window.WebSocket = MonitoredWebSocket;
|
|
2912
3163
|
}
|
|
2913
3164
|
uninstall() {
|
|
2914
|
-
if (this.installed
|
|
2915
|
-
window
|
|
2916
|
-
}
|
|
3165
|
+
if (this.installed)
|
|
3166
|
+
restorePatch(window, 'WebSocket', this.installed, this.originalWebSocket);
|
|
2917
3167
|
this.installed = null;
|
|
2918
3168
|
this.connections.clear();
|
|
2919
3169
|
}
|
|
@@ -2974,19 +3224,19 @@
|
|
|
2974
3224
|
this.fetchInterceptor = new FetchInterceptor({
|
|
2975
3225
|
onRequest: this.handleRequest.bind(this, 'fetch'),
|
|
2976
3226
|
onResponse: this.handleResponse.bind(this),
|
|
2977
|
-
onError: this.handleError.bind(this)
|
|
3227
|
+
onError: this.handleError.bind(this),
|
|
2978
3228
|
});
|
|
2979
3229
|
this.xhrInterceptor = new XHRInterceptor({
|
|
2980
3230
|
onRequest: this.handleRequest.bind(this, 'xhr'),
|
|
2981
3231
|
onResponse: this.handleResponse.bind(this),
|
|
2982
3232
|
onError: this.handleError.bind(this),
|
|
2983
|
-
onProgress: this.handleProgress.bind(this)
|
|
3233
|
+
onProgress: this.handleProgress.bind(this),
|
|
2984
3234
|
});
|
|
2985
3235
|
this.websocketMonitor = new WebSocketMonitor({
|
|
2986
3236
|
onConnection: this.handleWebSocketConnection.bind(this),
|
|
2987
3237
|
onMessage: this.handleWebSocketMessage.bind(this),
|
|
2988
3238
|
onStatusChange: this.handleWebSocketStatusChange.bind(this),
|
|
2989
|
-
onError: this.handleWebSocketError.bind(this)
|
|
3239
|
+
onError: this.handleWebSocketError.bind(this),
|
|
2990
3240
|
});
|
|
2991
3241
|
}
|
|
2992
3242
|
start() {
|
|
@@ -3012,14 +3262,14 @@
|
|
|
3012
3262
|
id: request.id,
|
|
3013
3263
|
type,
|
|
3014
3264
|
request,
|
|
3015
|
-
timestamp: request.timestamp
|
|
3265
|
+
timestamp: request.timestamp,
|
|
3016
3266
|
};
|
|
3017
3267
|
this.track(request.id, entry);
|
|
3018
3268
|
const storage = this.inspector.getStorage('network');
|
|
3019
3269
|
storage.push(entry);
|
|
3020
3270
|
this.inspector.getEvents().emit('network:request', {
|
|
3021
3271
|
...request,
|
|
3022
|
-
type
|
|
3272
|
+
type,
|
|
3023
3273
|
});
|
|
3024
3274
|
}
|
|
3025
3275
|
handleResponse(response) {
|
|
@@ -3039,7 +3289,7 @@
|
|
|
3039
3289
|
type: 'slow-network',
|
|
3040
3290
|
message: `Slow network request: ${(_c = entry.request) === null || _c === void 0 ? void 0 : _c.url}`,
|
|
3041
3291
|
duration: response.duration,
|
|
3042
|
-
url: (_d = entry.request) === null || _d === void 0 ? void 0 : _d.url
|
|
3292
|
+
url: (_d = entry.request) === null || _d === void 0 ? void 0 : _d.url,
|
|
3043
3293
|
});
|
|
3044
3294
|
}
|
|
3045
3295
|
}
|
|
@@ -3060,9 +3310,9 @@
|
|
|
3060
3310
|
websocket: {
|
|
3061
3311
|
connection,
|
|
3062
3312
|
messages: [],
|
|
3063
|
-
errors: []
|
|
3313
|
+
errors: [],
|
|
3064
3314
|
},
|
|
3065
|
-
timestamp: connection.timestamp
|
|
3315
|
+
timestamp: connection.timestamp,
|
|
3066
3316
|
};
|
|
3067
3317
|
this.track(connection.id, entry);
|
|
3068
3318
|
const storage = this.inspector.getStorage('network');
|
|
@@ -3119,7 +3369,7 @@
|
|
|
3119
3369
|
headers: {},
|
|
3120
3370
|
body: self.sanitizeBeaconData(data),
|
|
3121
3371
|
timestamp: Date.now(),
|
|
3122
|
-
type: 'beacon'
|
|
3372
|
+
type: 'beacon',
|
|
3123
3373
|
};
|
|
3124
3374
|
self.handleRequest('beacon', request);
|
|
3125
3375
|
const result = originalSendBeacon(url, data);
|
|
@@ -3132,7 +3382,7 @@
|
|
|
3132
3382
|
headers: {},
|
|
3133
3383
|
size: 0,
|
|
3134
3384
|
duration: 0,
|
|
3135
|
-
timestamp: Date.now()
|
|
3385
|
+
timestamp: Date.now(),
|
|
3136
3386
|
};
|
|
3137
3387
|
self.handleResponse(response);
|
|
3138
3388
|
}, 0);
|
|
@@ -3158,9 +3408,7 @@
|
|
|
3158
3408
|
if (data instanceof FormData) {
|
|
3159
3409
|
const entries = {};
|
|
3160
3410
|
data.forEach((value, key) => {
|
|
3161
|
-
entries[key] = value instanceof File
|
|
3162
|
-
? `[File: ${value.name}]`
|
|
3163
|
-
: value;
|
|
3411
|
+
entries[key] = value instanceof File ? `[File: ${value.name}]` : value;
|
|
3164
3412
|
});
|
|
3165
3413
|
return { type: 'FormData', entries };
|
|
3166
3414
|
}
|
|
@@ -3207,14 +3455,31 @@
|
|
|
3207
3455
|
}
|
|
3208
3456
|
install() {
|
|
3209
3457
|
const methods = [
|
|
3210
|
-
'log',
|
|
3211
|
-
'
|
|
3212
|
-
'
|
|
3213
|
-
'
|
|
3458
|
+
'log',
|
|
3459
|
+
'info',
|
|
3460
|
+
'warn',
|
|
3461
|
+
'error',
|
|
3462
|
+
'debug',
|
|
3463
|
+
'trace',
|
|
3464
|
+
'table',
|
|
3465
|
+
'group',
|
|
3466
|
+
'groupCollapsed',
|
|
3467
|
+
'groupEnd',
|
|
3468
|
+
'clear',
|
|
3469
|
+
'count',
|
|
3470
|
+
'countReset',
|
|
3471
|
+
'time',
|
|
3472
|
+
'timeEnd',
|
|
3473
|
+
'timeLog',
|
|
3474
|
+
'assert',
|
|
3475
|
+
'dir',
|
|
3476
|
+
'dirxml',
|
|
3477
|
+
'profile',
|
|
3478
|
+
'profileEnd',
|
|
3214
3479
|
];
|
|
3215
3480
|
if (this.originalMethods.size > 0)
|
|
3216
3481
|
return;
|
|
3217
|
-
methods.forEach(method => {
|
|
3482
|
+
methods.forEach((method) => {
|
|
3218
3483
|
if (typeof console[method] !== 'function')
|
|
3219
3484
|
return;
|
|
3220
3485
|
this.originalMethods.set(method, console[method]);
|
|
@@ -3224,9 +3489,7 @@
|
|
|
3224
3489
|
uninstall() {
|
|
3225
3490
|
this.originalMethods.forEach((original, method) => {
|
|
3226
3491
|
// Leave methods alone that someone else has wrapped since; ours pass through once uninstalled.
|
|
3227
|
-
|
|
3228
|
-
console[method] = original;
|
|
3229
|
-
}
|
|
3492
|
+
restorePatch(console, method, this.wrappers.get(method), original);
|
|
3230
3493
|
});
|
|
3231
3494
|
this.originalMethods.clear();
|
|
3232
3495
|
this.wrappers.clear();
|
|
@@ -3300,10 +3563,11 @@
|
|
|
3300
3563
|
args: args,
|
|
3301
3564
|
formattedArgs: this.formatArgs(args),
|
|
3302
3565
|
timestamp: Date.now(),
|
|
3303
|
-
groupLevel: this.groupLevel
|
|
3566
|
+
groupLevel: this.groupLevel,
|
|
3304
3567
|
};
|
|
3305
3568
|
// Capture stack trace if enabled
|
|
3306
|
-
if (this.captureStackTraces &&
|
|
3569
|
+
if (this.captureStackTraces &&
|
|
3570
|
+
(method === 'error' || method === 'warn' || method === 'trace')) {
|
|
3307
3571
|
// Drop the getStackTrace, capture and console wrapper frames so the first frame is the caller.
|
|
3308
3572
|
const stack = getStackTrace().slice(3);
|
|
3309
3573
|
entry.stack = stack;
|
|
@@ -3322,7 +3586,7 @@
|
|
|
3322
3586
|
args: [`${key}: ${count}`],
|
|
3323
3587
|
formattedArgs: [`${key}: ${count}`],
|
|
3324
3588
|
timestamp: Date.now(),
|
|
3325
|
-
groupLevel: this.groupLevel
|
|
3589
|
+
groupLevel: this.groupLevel,
|
|
3326
3590
|
};
|
|
3327
3591
|
(_b = (_a = this.handlers).onLog) === null || _b === void 0 ? void 0 : _b.call(_a, entry);
|
|
3328
3592
|
}
|
|
@@ -3337,7 +3601,7 @@
|
|
|
3337
3601
|
args: [`Timer '${key}' does not exist`],
|
|
3338
3602
|
formattedArgs: [`Timer '${key}' does not exist`],
|
|
3339
3603
|
timestamp: Date.now(),
|
|
3340
|
-
groupLevel: this.groupLevel
|
|
3604
|
+
groupLevel: this.groupLevel,
|
|
3341
3605
|
};
|
|
3342
3606
|
(_b = (_a = this.handlers).onLog) === null || _b === void 0 ? void 0 : _b.call(_a, entry);
|
|
3343
3607
|
return;
|
|
@@ -3352,12 +3616,12 @@
|
|
|
3352
3616
|
args: [`${key}: ${duration.toFixed(3)}ms`],
|
|
3353
3617
|
formattedArgs: [`${key}: ${duration.toFixed(3)}ms`],
|
|
3354
3618
|
timestamp: Date.now(),
|
|
3355
|
-
groupLevel: this.groupLevel
|
|
3619
|
+
groupLevel: this.groupLevel,
|
|
3356
3620
|
};
|
|
3357
3621
|
(_d = (_c = this.handlers).onLog) === null || _d === void 0 ? void 0 : _d.call(_c, entry);
|
|
3358
3622
|
}
|
|
3359
3623
|
formatArgs(args) {
|
|
3360
|
-
return args.map(arg => this.formatValue(arg));
|
|
3624
|
+
return args.map((arg) => this.formatValue(arg));
|
|
3361
3625
|
}
|
|
3362
3626
|
formatValue(value) {
|
|
3363
3627
|
if (value === null)
|
|
@@ -3373,33 +3637,33 @@
|
|
|
3373
3637
|
type: 'error',
|
|
3374
3638
|
name: value.name,
|
|
3375
3639
|
message: value.message,
|
|
3376
|
-
stack: value.stack
|
|
3640
|
+
stack: value.stack,
|
|
3377
3641
|
};
|
|
3378
3642
|
}
|
|
3379
3643
|
if (value instanceof Date) {
|
|
3380
3644
|
return {
|
|
3381
3645
|
type: 'date',
|
|
3382
|
-
value: value.toISOString()
|
|
3646
|
+
value: value.toISOString(),
|
|
3383
3647
|
};
|
|
3384
3648
|
}
|
|
3385
3649
|
if (value instanceof RegExp) {
|
|
3386
3650
|
return {
|
|
3387
3651
|
type: 'regexp',
|
|
3388
|
-
value: value.toString()
|
|
3652
|
+
value: value.toString(),
|
|
3389
3653
|
};
|
|
3390
3654
|
}
|
|
3391
3655
|
if (typeof value === 'function') {
|
|
3392
3656
|
return {
|
|
3393
3657
|
type: 'function',
|
|
3394
3658
|
name: value.name || '<anonymous>',
|
|
3395
|
-
value: value.toString().substring(0, 100)
|
|
3659
|
+
value: value.toString().substring(0, 100),
|
|
3396
3660
|
};
|
|
3397
3661
|
}
|
|
3398
3662
|
if (Array.isArray(value)) {
|
|
3399
3663
|
return {
|
|
3400
3664
|
type: 'array',
|
|
3401
3665
|
length: value.length,
|
|
3402
|
-
value: value.slice(0, 100).map(v => this.formatValue(v))
|
|
3666
|
+
value: value.slice(0, 100).map((v) => this.formatValue(v)),
|
|
3403
3667
|
};
|
|
3404
3668
|
}
|
|
3405
3669
|
if (type === 'object') {
|
|
@@ -3408,13 +3672,13 @@
|
|
|
3408
3672
|
const stringified = safeStringify(value, 2);
|
|
3409
3673
|
return {
|
|
3410
3674
|
type: 'object',
|
|
3411
|
-
value: JSON.parse(stringified)
|
|
3675
|
+
value: JSON.parse(stringified),
|
|
3412
3676
|
};
|
|
3413
3677
|
}
|
|
3414
3678
|
catch (error) {
|
|
3415
3679
|
return {
|
|
3416
3680
|
type: 'object',
|
|
3417
|
-
value: '[Complex Object]'
|
|
3681
|
+
value: '[Complex Object]',
|
|
3418
3682
|
};
|
|
3419
3683
|
}
|
|
3420
3684
|
}
|
|
@@ -3431,17 +3695,17 @@
|
|
|
3431
3695
|
return {
|
|
3432
3696
|
file: file.replace(/^.*\//, ''), // Get just filename
|
|
3433
3697
|
line: parseInt(line, 10),
|
|
3434
|
-
column: parseInt(column, 10)
|
|
3698
|
+
column: parseInt(column, 10),
|
|
3435
3699
|
};
|
|
3436
3700
|
}
|
|
3437
3701
|
}
|
|
3438
3702
|
|
|
3439
3703
|
class LogFormatter {
|
|
3440
3704
|
formatArgs(args) {
|
|
3441
|
-
return args.map(arg => this.formatValue(arg));
|
|
3705
|
+
return args.map((arg) => this.formatValue(arg));
|
|
3442
3706
|
}
|
|
3443
3707
|
formatArgsAsText(args) {
|
|
3444
|
-
return args.map(arg => this.formatValueAsText(arg)).join(' ');
|
|
3708
|
+
return args.map((arg) => this.formatValueAsText(arg)).join(' ');
|
|
3445
3709
|
}
|
|
3446
3710
|
formatValue(value) {
|
|
3447
3711
|
var _a;
|
|
@@ -3458,59 +3722,59 @@
|
|
|
3458
3722
|
type: 'error',
|
|
3459
3723
|
name: value.name,
|
|
3460
3724
|
message: value.message,
|
|
3461
|
-
stack: value.stack
|
|
3725
|
+
stack: value.stack,
|
|
3462
3726
|
};
|
|
3463
3727
|
}
|
|
3464
3728
|
if (value instanceof Date) {
|
|
3465
3729
|
return {
|
|
3466
3730
|
type: 'date',
|
|
3467
|
-
value: value.toISOString()
|
|
3731
|
+
value: value.toISOString(),
|
|
3468
3732
|
};
|
|
3469
3733
|
}
|
|
3470
3734
|
if (value instanceof RegExp) {
|
|
3471
3735
|
return {
|
|
3472
3736
|
type: 'regexp',
|
|
3473
|
-
value: value.toString()
|
|
3737
|
+
value: value.toString(),
|
|
3474
3738
|
};
|
|
3475
3739
|
}
|
|
3476
3740
|
if (value instanceof Set) {
|
|
3477
3741
|
return {
|
|
3478
3742
|
type: 'set',
|
|
3479
3743
|
size: value.size,
|
|
3480
|
-
values: Array.from(value).slice(0, 100)
|
|
3744
|
+
values: Array.from(value).slice(0, 100),
|
|
3481
3745
|
};
|
|
3482
3746
|
}
|
|
3483
3747
|
if (value instanceof Map) {
|
|
3484
3748
|
return {
|
|
3485
3749
|
type: 'map',
|
|
3486
3750
|
size: value.size,
|
|
3487
|
-
entries: Array.from(value.entries()).slice(0, 100)
|
|
3751
|
+
entries: Array.from(value.entries()).slice(0, 100),
|
|
3488
3752
|
};
|
|
3489
3753
|
}
|
|
3490
3754
|
if (value instanceof WeakSet || value instanceof WeakMap) {
|
|
3491
3755
|
return {
|
|
3492
3756
|
type: value instanceof WeakSet ? 'weakset' : 'weakmap',
|
|
3493
|
-
value: '[WeakCollection]'
|
|
3757
|
+
value: '[WeakCollection]',
|
|
3494
3758
|
};
|
|
3495
3759
|
}
|
|
3496
3760
|
if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
|
|
3497
3761
|
return {
|
|
3498
3762
|
type: 'arraybuffer',
|
|
3499
|
-
byteLength: value.byteLength
|
|
3763
|
+
byteLength: value.byteLength,
|
|
3500
3764
|
};
|
|
3501
3765
|
}
|
|
3502
3766
|
if (typeof value === 'function') {
|
|
3503
3767
|
return {
|
|
3504
3768
|
type: 'function',
|
|
3505
3769
|
name: value.name || '<anonymous>',
|
|
3506
|
-
value: value.toString().substring(0, 100)
|
|
3770
|
+
value: value.toString().substring(0, 100),
|
|
3507
3771
|
};
|
|
3508
3772
|
}
|
|
3509
3773
|
if (Array.isArray(value)) {
|
|
3510
3774
|
return {
|
|
3511
3775
|
type: 'array',
|
|
3512
3776
|
length: value.length,
|
|
3513
|
-
value: value.slice(0, 100).map(v => this.formatValue(v))
|
|
3777
|
+
value: value.slice(0, 100).map((v) => this.formatValue(v)),
|
|
3514
3778
|
};
|
|
3515
3779
|
}
|
|
3516
3780
|
if (type === 'object') {
|
|
@@ -3525,7 +3789,7 @@
|
|
|
3525
3789
|
const formatted = {
|
|
3526
3790
|
type: 'object',
|
|
3527
3791
|
constructor: constructorName,
|
|
3528
|
-
value: {}
|
|
3792
|
+
value: {},
|
|
3529
3793
|
};
|
|
3530
3794
|
for (const [key, val] of entries) {
|
|
3531
3795
|
formatted.value[key] = this.formatValue(val);
|
|
@@ -3539,7 +3803,7 @@
|
|
|
3539
3803
|
catch (error) {
|
|
3540
3804
|
return {
|
|
3541
3805
|
type: 'object',
|
|
3542
|
-
value: '[Complex Object]'
|
|
3806
|
+
value: '[Complex Object]',
|
|
3543
3807
|
};
|
|
3544
3808
|
}
|
|
3545
3809
|
}
|
|
@@ -3580,21 +3844,43 @@
|
|
|
3580
3844
|
return JSON.stringify(value);
|
|
3581
3845
|
}
|
|
3582
3846
|
formatStackTrace(stack) {
|
|
3583
|
-
return stack
|
|
3847
|
+
return stack
|
|
3848
|
+
.map((frame, index) => {
|
|
3584
3849
|
// Remove leading "at " if present
|
|
3585
3850
|
const cleanFrame = frame.replace(/^\s*at\s+/, '');
|
|
3586
3851
|
// Add indentation
|
|
3587
3852
|
return ' '.repeat(index) + cleanFrame;
|
|
3588
|
-
})
|
|
3853
|
+
})
|
|
3854
|
+
.join('\n');
|
|
3589
3855
|
}
|
|
3590
3856
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3591
3857
|
highlightSyntax(code, language = 'javascript') {
|
|
3592
3858
|
// Simple syntax highlighting for console display
|
|
3593
3859
|
// In a real implementation, you might use a proper syntax highlighter
|
|
3594
3860
|
const keywords = [
|
|
3595
|
-
'const',
|
|
3596
|
-
'
|
|
3597
|
-
'
|
|
3861
|
+
'const',
|
|
3862
|
+
'let',
|
|
3863
|
+
'var',
|
|
3864
|
+
'function',
|
|
3865
|
+
'class',
|
|
3866
|
+
'if',
|
|
3867
|
+
'else',
|
|
3868
|
+
'for',
|
|
3869
|
+
'while',
|
|
3870
|
+
'return',
|
|
3871
|
+
'new',
|
|
3872
|
+
'this',
|
|
3873
|
+
'typeof',
|
|
3874
|
+
'instanceof',
|
|
3875
|
+
'try',
|
|
3876
|
+
'catch',
|
|
3877
|
+
'finally',
|
|
3878
|
+
'throw',
|
|
3879
|
+
'async',
|
|
3880
|
+
'await',
|
|
3881
|
+
'import',
|
|
3882
|
+
'export',
|
|
3883
|
+
'default',
|
|
3598
3884
|
];
|
|
3599
3885
|
let highlighted = code;
|
|
3600
3886
|
// Highlight strings
|
|
@@ -3602,7 +3888,7 @@
|
|
|
3602
3888
|
// Highlight numbers
|
|
3603
3889
|
highlighted = highlighted.replace(/\b(\d+)\b/g, '<span class="number">$1</span>');
|
|
3604
3890
|
// Highlight keywords
|
|
3605
|
-
keywords.forEach(keyword => {
|
|
3891
|
+
keywords.forEach((keyword) => {
|
|
3606
3892
|
const regex = new RegExp(`\\b${keyword}\\b`, 'g');
|
|
3607
3893
|
highlighted = highlighted.replace(regex, `<span class="keyword">${keyword}</span>`);
|
|
3608
3894
|
});
|
|
@@ -3622,7 +3908,7 @@
|
|
|
3622
3908
|
this.formatter = new LogFormatter();
|
|
3623
3909
|
this.interceptor = new ConsoleInterceptor({
|
|
3624
3910
|
onLog: this.handleLog.bind(this),
|
|
3625
|
-
onClear: this.handleClear.bind(this)
|
|
3911
|
+
onClear: this.handleClear.bind(this),
|
|
3626
3912
|
}, inspector.getConfig().captureStackTraces);
|
|
3627
3913
|
}
|
|
3628
3914
|
start() {
|
|
@@ -3648,7 +3934,7 @@
|
|
|
3648
3934
|
message: this.formatter.formatArgs(entry.args),
|
|
3649
3935
|
stack: entry.stack,
|
|
3650
3936
|
timestamp: entry.timestamp,
|
|
3651
|
-
source: 'console'
|
|
3937
|
+
source: 'console',
|
|
3652
3938
|
});
|
|
3653
3939
|
}
|
|
3654
3940
|
}
|
|
@@ -3675,7 +3961,7 @@
|
|
|
3675
3961
|
args: [`> ${command}`],
|
|
3676
3962
|
formattedArgs: [`> ${command}`],
|
|
3677
3963
|
timestamp: Date.now(),
|
|
3678
|
-
groupLevel: 0
|
|
3964
|
+
groupLevel: 0,
|
|
3679
3965
|
};
|
|
3680
3966
|
this.handleLog(commandEntry);
|
|
3681
3967
|
// Execute the command
|
|
@@ -3693,7 +3979,7 @@
|
|
|
3693
3979
|
args: [result],
|
|
3694
3980
|
formattedArgs: this.formatter.formatArgs([result]),
|
|
3695
3981
|
timestamp: Date.now(),
|
|
3696
|
-
groupLevel: 0
|
|
3982
|
+
groupLevel: 0,
|
|
3697
3983
|
};
|
|
3698
3984
|
this.handleLog(resultEntry);
|
|
3699
3985
|
}
|
|
@@ -3706,7 +3992,7 @@
|
|
|
3706
3992
|
formattedArgs: this.formatter.formatArgs([error]),
|
|
3707
3993
|
timestamp: Date.now(),
|
|
3708
3994
|
groupLevel: 0,
|
|
3709
|
-
stack: (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n')
|
|
3995
|
+
stack: (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n'),
|
|
3710
3996
|
};
|
|
3711
3997
|
this.handleLog(errorEntry);
|
|
3712
3998
|
}
|
|
@@ -3728,7 +4014,7 @@
|
|
|
3728
4014
|
filterLogs(filter) {
|
|
3729
4015
|
const storage = this.inspector.getStorage('console');
|
|
3730
4016
|
const logs = storage.getAll();
|
|
3731
|
-
return logs.filter(log => {
|
|
4017
|
+
return logs.filter((log) => {
|
|
3732
4018
|
var _a;
|
|
3733
4019
|
// Filter by level
|
|
3734
4020
|
if (filter.levels && filter.levels.length > 0) {
|
|
@@ -3759,13 +4045,15 @@
|
|
|
3759
4045
|
return JSON.stringify(logs, null, 2);
|
|
3760
4046
|
}
|
|
3761
4047
|
// Text format
|
|
3762
|
-
return logs
|
|
4048
|
+
return logs
|
|
4049
|
+
.map((log) => {
|
|
3763
4050
|
const timestamp = new Date(log.timestamp).toISOString();
|
|
3764
4051
|
const level = log.level.toUpperCase().padEnd(5);
|
|
3765
4052
|
const args = this.formatter.formatArgsAsText(log.formattedArgs);
|
|
3766
4053
|
const source = log.source ? ` [${log.source.file}:${log.source.line}]` : '';
|
|
3767
4054
|
return `[${timestamp}] ${level} ${args}${source}`;
|
|
3768
|
-
})
|
|
4055
|
+
})
|
|
4056
|
+
.join('\n');
|
|
3769
4057
|
}
|
|
3770
4058
|
}
|
|
3771
4059
|
|
|
@@ -3805,7 +4093,7 @@
|
|
|
3805
4093
|
fps: Math.round(this.fps),
|
|
3806
4094
|
timestamp: Date.now(),
|
|
3807
4095
|
frameTime: avgFrameTime,
|
|
3808
|
-
droppedFrames: this.droppedFrames
|
|
4096
|
+
droppedFrames: this.droppedFrames,
|
|
3809
4097
|
});
|
|
3810
4098
|
// Reset counters
|
|
3811
4099
|
this.frameCount = 0;
|
|
@@ -3884,7 +4172,7 @@
|
|
|
3884
4172
|
totalJSHeapSize,
|
|
3885
4173
|
jsHeapSizeLimit,
|
|
3886
4174
|
timestamp: Date.now(),
|
|
3887
|
-
percentUsed
|
|
4175
|
+
percentUsed,
|
|
3888
4176
|
};
|
|
3889
4177
|
this.callback(data);
|
|
3890
4178
|
}
|
|
@@ -3897,7 +4185,7 @@
|
|
|
3897
4185
|
totalJSHeapSize,
|
|
3898
4186
|
jsHeapSizeLimit,
|
|
3899
4187
|
timestamp: Date.now(),
|
|
3900
|
-
percentUsed: (usedJSHeapSize / jsHeapSizeLimit) * 100
|
|
4188
|
+
percentUsed: (usedJSHeapSize / jsHeapSizeLimit) * 100,
|
|
3901
4189
|
};
|
|
3902
4190
|
}
|
|
3903
4191
|
isMemorySupported() {
|
|
@@ -4038,7 +4326,7 @@
|
|
|
4038
4326
|
domProcessingTime: timing.domComplete - timing.domLoading,
|
|
4039
4327
|
domContentLoadedTime: timing.domContentLoadedEventEnd - navigationStart,
|
|
4040
4328
|
loadTime: timing.loadEventEnd - navigationStart,
|
|
4041
|
-
totalTime: timing.loadEventEnd - navigationStart
|
|
4329
|
+
totalTime: timing.loadEventEnd - navigationStart,
|
|
4042
4330
|
});
|
|
4043
4331
|
this.reportMetrics();
|
|
4044
4332
|
}
|
|
@@ -4117,14 +4405,15 @@
|
|
|
4117
4405
|
duration: Math.round(entry.duration),
|
|
4118
4406
|
startTime: Math.round(entry.startTime),
|
|
4119
4407
|
timestamp: Date.now(),
|
|
4120
|
-
attribution: longTaskEntry.attribution
|
|
4121
|
-
longTaskEntry.attribution.map((attr) => ({
|
|
4408
|
+
attribution: longTaskEntry.attribution
|
|
4409
|
+
? longTaskEntry.attribution.map((attr) => ({
|
|
4122
4410
|
name: attr.name,
|
|
4123
4411
|
containerType: attr.containerType,
|
|
4124
4412
|
containerSrc: attr.containerSrc,
|
|
4125
4413
|
containerId: attr.containerId,
|
|
4126
|
-
containerName: attr.containerName
|
|
4127
|
-
}))
|
|
4414
|
+
containerName: attr.containerName,
|
|
4415
|
+
}))
|
|
4416
|
+
: [],
|
|
4128
4417
|
};
|
|
4129
4418
|
this.callback(task);
|
|
4130
4419
|
}
|
|
@@ -4141,10 +4430,12 @@
|
|
|
4141
4430
|
duration: Math.round(deltaTime),
|
|
4142
4431
|
startTime: Math.round(lastTime),
|
|
4143
4432
|
timestamp: Date.now(),
|
|
4144
|
-
attribution: [
|
|
4433
|
+
attribution: [
|
|
4434
|
+
{
|
|
4145
4435
|
name: 'unknown',
|
|
4146
|
-
containerType: 'window'
|
|
4147
|
-
}
|
|
4436
|
+
containerType: 'window',
|
|
4437
|
+
},
|
|
4438
|
+
],
|
|
4148
4439
|
};
|
|
4149
4440
|
this.callback(task);
|
|
4150
4441
|
}
|
|
@@ -4201,7 +4492,7 @@
|
|
|
4201
4492
|
type: 'low-fps',
|
|
4202
4493
|
message: `Low FPS detected: ${data.fps}`,
|
|
4203
4494
|
fps: data.fps,
|
|
4204
|
-
droppedFrames: data.droppedFrames
|
|
4495
|
+
droppedFrames: data.droppedFrames,
|
|
4205
4496
|
});
|
|
4206
4497
|
}
|
|
4207
4498
|
this.emitPerformanceData();
|
|
@@ -4217,7 +4508,7 @@
|
|
|
4217
4508
|
type: 'high-memory',
|
|
4218
4509
|
message: `High memory usage: ${data.percentUsed.toFixed(1)}%`,
|
|
4219
4510
|
percentUsed: data.percentUsed,
|
|
4220
|
-
usedBytes: data.usedJSHeapSize
|
|
4511
|
+
usedBytes: data.usedJSHeapSize,
|
|
4221
4512
|
});
|
|
4222
4513
|
}
|
|
4223
4514
|
this.emitPerformanceData();
|
|
@@ -4232,21 +4523,21 @@
|
|
|
4232
4523
|
(_b = (_a = this.inspector.getConfig()).onPerformanceIssue) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
4233
4524
|
type: 'poor-lcp',
|
|
4234
4525
|
message: `Poor LCP: ${metrics.LCP}ms`,
|
|
4235
|
-
value: metrics.LCP
|
|
4526
|
+
value: metrics.LCP,
|
|
4236
4527
|
});
|
|
4237
4528
|
}
|
|
4238
4529
|
if (metrics.FID && metrics.FID > 100) {
|
|
4239
4530
|
(_d = (_c = this.inspector.getConfig()).onPerformanceIssue) === null || _d === void 0 ? void 0 : _d.call(_c, {
|
|
4240
4531
|
type: 'poor-fid',
|
|
4241
4532
|
message: `Poor FID: ${metrics.FID}ms`,
|
|
4242
|
-
value: metrics.FID
|
|
4533
|
+
value: metrics.FID,
|
|
4243
4534
|
});
|
|
4244
4535
|
}
|
|
4245
4536
|
if (metrics.CLS && metrics.CLS > 0.1) {
|
|
4246
4537
|
(_f = (_e = this.inspector.getConfig()).onPerformanceIssue) === null || _f === void 0 ? void 0 : _f.call(_e, {
|
|
4247
4538
|
type: 'poor-cls',
|
|
4248
4539
|
message: `Poor CLS: ${metrics.CLS}`,
|
|
4249
|
-
value: metrics.CLS
|
|
4540
|
+
value: metrics.CLS,
|
|
4250
4541
|
});
|
|
4251
4542
|
}
|
|
4252
4543
|
this.inspector.getEvents().emit('performance:metrics', metrics);
|
|
@@ -4268,7 +4559,7 @@
|
|
|
4268
4559
|
type: 'long-task',
|
|
4269
4560
|
message: `Long task detected: ${task.duration}ms`,
|
|
4270
4561
|
duration: task.duration,
|
|
4271
|
-
attribution: task.attribution
|
|
4562
|
+
attribution: task.attribution,
|
|
4272
4563
|
});
|
|
4273
4564
|
}
|
|
4274
4565
|
}
|
|
@@ -4286,7 +4577,7 @@
|
|
|
4286
4577
|
name: entry.name,
|
|
4287
4578
|
duration: entry.duration,
|
|
4288
4579
|
startTime: entry.startTime,
|
|
4289
|
-
timestamp: Date.now()
|
|
4580
|
+
timestamp: Date.now(),
|
|
4290
4581
|
});
|
|
4291
4582
|
}
|
|
4292
4583
|
});
|
|
@@ -4311,7 +4602,7 @@
|
|
|
4311
4602
|
type: 'slow-resource',
|
|
4312
4603
|
message: `Slow resource: ${resourceEntry.name}`,
|
|
4313
4604
|
duration: resourceEntry.duration,
|
|
4314
|
-
url: resourceEntry.name
|
|
4605
|
+
url: resourceEntry.name,
|
|
4315
4606
|
});
|
|
4316
4607
|
}
|
|
4317
4608
|
}
|
|
@@ -4332,7 +4623,7 @@
|
|
|
4332
4623
|
this.inspector.getEvents().emit('performance:mark', {
|
|
4333
4624
|
name,
|
|
4334
4625
|
duration,
|
|
4335
|
-
timestamp: Date.now()
|
|
4626
|
+
timestamp: Date.now(),
|
|
4336
4627
|
});
|
|
4337
4628
|
}
|
|
4338
4629
|
}
|
|
@@ -4342,7 +4633,7 @@
|
|
|
4342
4633
|
memory: this.memoryMonitor.getCurrentMemory() || undefined,
|
|
4343
4634
|
metrics: this.metricsCollector.getMetrics(),
|
|
4344
4635
|
longTasks: this.inspector.getStorage('performance').get('longTasks') || [],
|
|
4345
|
-
timestamp: Date.now()
|
|
4636
|
+
timestamp: Date.now(),
|
|
4346
4637
|
};
|
|
4347
4638
|
}
|
|
4348
4639
|
}
|
|
@@ -4352,6 +4643,15 @@
|
|
|
4352
4643
|
PerformanceMonitor: PerformanceMonitor
|
|
4353
4644
|
});
|
|
4354
4645
|
|
|
4646
|
+
/**
|
|
4647
|
+
* `value instanceof globalThis[name]`, without a ReferenceError in runtimes that do
|
|
4648
|
+
* not define that event class (jsdom has no PromiseRejectionEvent, for example);
|
|
4649
|
+
* there the shape check done by the caller (`'reason' in event`) decides.
|
|
4650
|
+
*/
|
|
4651
|
+
function isInstance(value, name) {
|
|
4652
|
+
const ctor = globalThis[name];
|
|
4653
|
+
return typeof ctor !== 'function' || value instanceof ctor;
|
|
4654
|
+
}
|
|
4355
4655
|
class ErrorTracker {
|
|
4356
4656
|
constructor(callback) {
|
|
4357
4657
|
this.groups = new Map();
|
|
@@ -4368,7 +4668,7 @@
|
|
|
4368
4668
|
/Network request failed/,
|
|
4369
4669
|
/Failed to fetch/,
|
|
4370
4670
|
/Load failed/,
|
|
4371
|
-
/Script error
|
|
4671
|
+
/Script error/,
|
|
4372
4672
|
];
|
|
4373
4673
|
}
|
|
4374
4674
|
addIgnorePattern(pattern) {
|
|
@@ -4402,28 +4702,30 @@
|
|
|
4402
4702
|
let errorObject;
|
|
4403
4703
|
if (error instanceof Error) {
|
|
4404
4704
|
message = error.message || error.toString();
|
|
4405
|
-
stack = error.stack ? error.stack.split('\n').map(line => line.trim()) : [];
|
|
4705
|
+
stack = error.stack ? error.stack.split('\n').map((line) => line.trim()) : [];
|
|
4406
4706
|
errorObject = {
|
|
4407
4707
|
name: error.name,
|
|
4408
4708
|
message: error.message,
|
|
4409
|
-
stack: error.stack
|
|
4709
|
+
stack: error.stack,
|
|
4410
4710
|
};
|
|
4411
4711
|
}
|
|
4412
|
-
else if ('message' in error && error
|
|
4712
|
+
else if ('message' in error && isInstance(error, 'ErrorEvent')) {
|
|
4413
4713
|
message = error.message;
|
|
4414
4714
|
source = error.filename;
|
|
4415
4715
|
lineno = error.lineno;
|
|
4416
4716
|
colno = error.colno;
|
|
4417
4717
|
if (error.error) {
|
|
4418
|
-
stack = error.error.stack
|
|
4718
|
+
stack = error.error.stack
|
|
4719
|
+
? error.error.stack.split('\n').map((line) => line.trim())
|
|
4720
|
+
: [];
|
|
4419
4721
|
errorObject = error.error;
|
|
4420
4722
|
}
|
|
4421
4723
|
}
|
|
4422
|
-
else if ('reason' in error && error
|
|
4724
|
+
else if ('reason' in error && isInstance(error, 'PromiseRejectionEvent')) {
|
|
4423
4725
|
const reason = error.reason;
|
|
4424
4726
|
if (reason instanceof Error) {
|
|
4425
4727
|
message = reason.message || reason.toString();
|
|
4426
|
-
stack = reason.stack ? reason.stack.split('\n').map(line => line.trim()) : [];
|
|
4728
|
+
stack = reason.stack ? reason.stack.split('\n').map((line) => line.trim()) : [];
|
|
4427
4729
|
errorObject = reason;
|
|
4428
4730
|
}
|
|
4429
4731
|
else {
|
|
@@ -4433,8 +4735,8 @@
|
|
|
4433
4735
|
}
|
|
4434
4736
|
// Parse stack frames
|
|
4435
4737
|
const stackFrames = stack
|
|
4436
|
-
.map(frame => parseStackFrame(frame))
|
|
4437
|
-
.filter(frame => frame !== null);
|
|
4738
|
+
.map((frame) => parseStackFrame(frame))
|
|
4739
|
+
.filter((frame) => frame !== null);
|
|
4438
4740
|
const errorInfo = {
|
|
4439
4741
|
id: generateId(),
|
|
4440
4742
|
type,
|
|
@@ -4448,7 +4750,7 @@
|
|
|
4448
4750
|
userAgent: navigator.userAgent,
|
|
4449
4751
|
url: window.location.href,
|
|
4450
4752
|
errorObject,
|
|
4451
|
-
count: 1
|
|
4753
|
+
count: 1,
|
|
4452
4754
|
};
|
|
4453
4755
|
return errorInfo;
|
|
4454
4756
|
}
|
|
@@ -4465,9 +4767,10 @@
|
|
|
4465
4767
|
return true;
|
|
4466
4768
|
}
|
|
4467
4769
|
// Ignore errors from browser extensions
|
|
4468
|
-
if (errorInfo.source &&
|
|
4469
|
-
errorInfo.source.includes('
|
|
4470
|
-
|
|
4770
|
+
if (errorInfo.source &&
|
|
4771
|
+
(errorInfo.source.includes('extension://') ||
|
|
4772
|
+
errorInfo.source.includes('chrome-extension://') ||
|
|
4773
|
+
errorInfo.source.includes('moz-extension://'))) {
|
|
4471
4774
|
return true;
|
|
4472
4775
|
}
|
|
4473
4776
|
return false;
|
|
@@ -4483,7 +4786,7 @@
|
|
|
4483
4786
|
count: 0,
|
|
4484
4787
|
firstSeen: errorInfo.timestamp,
|
|
4485
4788
|
lastSeen: errorInfo.timestamp,
|
|
4486
|
-
errors: []
|
|
4789
|
+
errors: [],
|
|
4487
4790
|
};
|
|
4488
4791
|
this.groups.set(fingerprint, group);
|
|
4489
4792
|
}
|
|
@@ -4498,10 +4801,7 @@
|
|
|
4498
4801
|
}
|
|
4499
4802
|
generateFingerprint(errorInfo) {
|
|
4500
4803
|
// Create a fingerprint based on error characteristics
|
|
4501
|
-
const parts = [
|
|
4502
|
-
errorInfo.type,
|
|
4503
|
-
this.normalizeMessage(errorInfo.message)
|
|
4504
|
-
];
|
|
4804
|
+
const parts = [errorInfo.type, this.normalizeMessage(errorInfo.message)];
|
|
4505
4805
|
// Add top stack frame if available
|
|
4506
4806
|
if (errorInfo.stackFrames && errorInfo.stackFrames.length > 0) {
|
|
4507
4807
|
const topFrame = errorInfo.stackFrames[0];
|
|
@@ -4519,7 +4819,7 @@
|
|
|
4519
4819
|
}
|
|
4520
4820
|
normalizeMessage(message) {
|
|
4521
4821
|
// Remove dynamic parts from error messages for better grouping
|
|
4522
|
-
return message
|
|
4822
|
+
return (message
|
|
4523
4823
|
// Remove URLs
|
|
4524
4824
|
.replace(/https?:\/\/[^\s]+/g, '<URL>')
|
|
4525
4825
|
// Remove numbers
|
|
@@ -4531,11 +4831,10 @@
|
|
|
4531
4831
|
.replace(/'[^']*'/g, "'<STRING>'")
|
|
4532
4832
|
// Normalize whitespace
|
|
4533
4833
|
.replace(/\s+/g, ' ')
|
|
4534
|
-
.trim();
|
|
4834
|
+
.trim());
|
|
4535
4835
|
}
|
|
4536
4836
|
getGroups() {
|
|
4537
|
-
return Array.from(this.groups.values())
|
|
4538
|
-
.sort((a, b) => b.lastSeen - a.lastSeen);
|
|
4837
|
+
return Array.from(this.groups.values()).sort((a, b) => b.lastSeen - a.lastSeen);
|
|
4539
4838
|
}
|
|
4540
4839
|
getGroup(groupId) {
|
|
4541
4840
|
for (const group of this.groups.values()) {
|
|
@@ -4565,7 +4864,7 @@
|
|
|
4565
4864
|
totalErrors,
|
|
4566
4865
|
totalGroups: this.groups.size,
|
|
4567
4866
|
errorsByType,
|
|
4568
|
-
recentErrors: recentErrors.slice(0, 10)
|
|
4867
|
+
recentErrors: recentErrors.slice(0, 10),
|
|
4569
4868
|
};
|
|
4570
4869
|
}
|
|
4571
4870
|
}
|
|
@@ -4636,7 +4935,7 @@
|
|
|
4636
4935
|
const response = await fetch(fileUrl, {
|
|
4637
4936
|
method: 'GET',
|
|
4638
4937
|
mode: 'cors',
|
|
4639
|
-
credentials: 'omit'
|
|
4938
|
+
credentials: 'omit',
|
|
4640
4939
|
});
|
|
4641
4940
|
if (!response.ok)
|
|
4642
4941
|
return null;
|
|
@@ -4675,7 +4974,7 @@
|
|
|
4675
4974
|
const response = await fetch(sourceMapUrl, {
|
|
4676
4975
|
method: 'GET',
|
|
4677
4976
|
mode: 'cors',
|
|
4678
|
-
credentials: 'omit'
|
|
4977
|
+
credentials: 'omit',
|
|
4679
4978
|
});
|
|
4680
4979
|
if (!response.ok)
|
|
4681
4980
|
return null;
|
|
@@ -4685,7 +4984,7 @@
|
|
|
4685
4984
|
// Cache it
|
|
4686
4985
|
this.cache[fileUrl] = {
|
|
4687
4986
|
sourceMapUrl,
|
|
4688
|
-
sourceMap
|
|
4987
|
+
sourceMap,
|
|
4689
4988
|
};
|
|
4690
4989
|
return sourceMap;
|
|
4691
4990
|
}
|
|
@@ -4706,7 +5005,7 @@
|
|
|
4706
5005
|
source: sourceMap.sources[0] || 'unknown',
|
|
4707
5006
|
line: line,
|
|
4708
5007
|
column: column,
|
|
4709
|
-
name: (_a = sourceMap.names) === null || _a === void 0 ? void 0 : _a[0]
|
|
5008
|
+
name: (_a = sourceMap.names) === null || _a === void 0 ? void 0 : _a[0],
|
|
4710
5009
|
};
|
|
4711
5010
|
}
|
|
4712
5011
|
clearCache() {
|
|
@@ -4723,15 +5022,13 @@
|
|
|
4723
5022
|
class ErrorMonitor {
|
|
4724
5023
|
constructor(inspector) {
|
|
4725
5024
|
this.isActive = false;
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
unhandledrejection: null
|
|
4729
|
-
};
|
|
5025
|
+
/** Set while a window error/rejection event is being tracked (vs. trackError()). */
|
|
5026
|
+
this.trackingUncaught = false;
|
|
4730
5027
|
this.handleErrorEvent = (event) => {
|
|
4731
|
-
this.errorTracker.trackError(event, 'error');
|
|
5028
|
+
this.trackUncaught(() => this.errorTracker.trackError(event, 'error'));
|
|
4732
5029
|
};
|
|
4733
5030
|
this.handleRejectionEvent = (event) => {
|
|
4734
|
-
this.errorTracker.trackError(event, 'unhandledRejection');
|
|
5031
|
+
this.trackUncaught(() => this.errorTracker.trackError(event, 'unhandledRejection'));
|
|
4735
5032
|
};
|
|
4736
5033
|
this.inspector = inspector;
|
|
4737
5034
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises -- 1.x behaviour: the tracker does not await the handler
|
|
@@ -4750,50 +5047,30 @@
|
|
|
4750
5047
|
this.uninstallErrorHandlers();
|
|
4751
5048
|
this.isActive = false;
|
|
4752
5049
|
}
|
|
5050
|
+
// One subscription per event type: window.onerror / onunhandledrejection are left
|
|
5051
|
+
// to the page (setting them as well reported every error twice and returning true
|
|
5052
|
+
// from onerror hid the error from the browser console).
|
|
4753
5053
|
installErrorHandlers() {
|
|
4754
|
-
// Save original handlers
|
|
4755
|
-
this.originalHandlers.error = window.onerror;
|
|
4756
|
-
this.originalHandlers.unhandledrejection = window.onunhandledrejection;
|
|
4757
|
-
// Install error handler
|
|
4758
|
-
window.onerror = (message, source, lineno, colno, error) => {
|
|
4759
|
-
const errorEvent = new ErrorEvent('error', {
|
|
4760
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string -- onerror passes a string or an Event
|
|
4761
|
-
message: String(message),
|
|
4762
|
-
filename: source,
|
|
4763
|
-
lineno,
|
|
4764
|
-
colno,
|
|
4765
|
-
error
|
|
4766
|
-
});
|
|
4767
|
-
this.errorTracker.trackError(errorEvent, 'error');
|
|
4768
|
-
// Call original handler if exists
|
|
4769
|
-
if (this.originalHandlers.error) {
|
|
4770
|
-
return this.originalHandlers.error(message, source, lineno, colno, error);
|
|
4771
|
-
}
|
|
4772
|
-
return true; // Prevent default browser error handling
|
|
4773
|
-
};
|
|
4774
|
-
// Install unhandled rejection handler
|
|
4775
|
-
window.onunhandledrejection = (event) => {
|
|
4776
|
-
this.errorTracker.trackError(event, 'unhandledRejection');
|
|
4777
|
-
// Call original handler if exists
|
|
4778
|
-
if (this.originalHandlers.unhandledrejection) {
|
|
4779
|
-
return this.originalHandlers.unhandledrejection(event);
|
|
4780
|
-
}
|
|
4781
|
-
return true; // Prevent default browser error handling
|
|
4782
|
-
};
|
|
4783
|
-
// Also use addEventListener for better coverage
|
|
4784
5054
|
window.addEventListener('error', this.handleErrorEvent);
|
|
4785
5055
|
window.addEventListener('unhandledrejection', this.handleRejectionEvent);
|
|
4786
5056
|
}
|
|
4787
5057
|
uninstallErrorHandlers() {
|
|
4788
|
-
// Restore original handlers
|
|
4789
|
-
window.onerror = this.originalHandlers.error;
|
|
4790
|
-
window.onunhandledrejection = this.originalHandlers.unhandledrejection;
|
|
4791
|
-
// Remove event listeners
|
|
4792
5058
|
window.removeEventListener('error', this.handleErrorEvent);
|
|
4793
5059
|
window.removeEventListener('unhandledrejection', this.handleRejectionEvent);
|
|
4794
5060
|
}
|
|
5061
|
+
trackUncaught(track) {
|
|
5062
|
+
this.trackingUncaught = true;
|
|
5063
|
+
try {
|
|
5064
|
+
track();
|
|
5065
|
+
}
|
|
5066
|
+
finally {
|
|
5067
|
+
this.trackingUncaught = false;
|
|
5068
|
+
}
|
|
5069
|
+
}
|
|
4795
5070
|
async handleError(errorInfo) {
|
|
4796
5071
|
var _a, _b;
|
|
5072
|
+
// Window errors and rejections are uncaught; errors passed to trackError() are caught.
|
|
5073
|
+
const uncaught = this.trackingUncaught;
|
|
4797
5074
|
// Enhance stack trace with source maps if available
|
|
4798
5075
|
if (errorInfo.stack && this.sourceMapSupport.isEnabled()) {
|
|
4799
5076
|
try {
|
|
@@ -4807,13 +5084,9 @@
|
|
|
4807
5084
|
const storage = this.inspector.getStorage('error');
|
|
4808
5085
|
storage.push(errorInfo);
|
|
4809
5086
|
// Emit events
|
|
4810
|
-
this.inspector.getEvents().emit(
|
|
5087
|
+
this.inspector.getEvents().emit(uncaught ? 'error:uncaught' : 'error:caught', errorInfo);
|
|
4811
5088
|
// Call error callback
|
|
4812
5089
|
(_b = (_a = this.inspector.getConfig()).onError) === null || _b === void 0 ? void 0 : _b.call(_a, new Error(errorInfo.message));
|
|
4813
|
-
// Log to console in development
|
|
4814
|
-
if (this.inspector.getConfig().enabled) {
|
|
4815
|
-
console.error('[DevInspector] Error captured:', errorInfo);
|
|
4816
|
-
}
|
|
4817
5090
|
}
|
|
4818
5091
|
// Public API
|
|
4819
5092
|
trackError(error) {
|
|
@@ -4972,7 +5245,7 @@
|
|
|
4972
5245
|
const rect = this.element.getBoundingClientRect();
|
|
4973
5246
|
this.dragOffset = {
|
|
4974
5247
|
x: e.clientX - rect.left,
|
|
4975
|
-
y: e.clientY - rect.top
|
|
5248
|
+
y: e.clientY - rect.top,
|
|
4976
5249
|
};
|
|
4977
5250
|
this.element.style.cursor = 'grabbing';
|
|
4978
5251
|
this.element.style.zIndex = '1000000';
|
|
@@ -5013,11 +5286,10 @@
|
|
|
5013
5286
|
left: centerX,
|
|
5014
5287
|
right: windowWidth - centerX,
|
|
5015
5288
|
top: centerY,
|
|
5016
|
-
bottom: windowHeight - centerY
|
|
5289
|
+
bottom: windowHeight - centerY,
|
|
5017
5290
|
};
|
|
5018
5291
|
// Find closest edge using type-safe approach
|
|
5019
|
-
const closestEdge = Object.entries(distances)
|
|
5020
|
-
.reduce((a, b) => a[1] < b[1] ? a : b)[0];
|
|
5292
|
+
const closestEdge = Object.entries(distances).reduce((a, b) => (a[1] < b[1] ? a : b))[0];
|
|
5021
5293
|
// Animate to edge
|
|
5022
5294
|
const margin = 20;
|
|
5023
5295
|
switch (closestEdge) {
|
|
@@ -5091,7 +5363,7 @@
|
|
|
5091
5363
|
document.removeEventListener('mousemove', this.boundMouseMove);
|
|
5092
5364
|
document.removeEventListener('mouseup', this.boundMouseUp);
|
|
5093
5365
|
// Unsubscribe from all inspector events
|
|
5094
|
-
this.eventUnsubscribers.forEach(unsubscribe => unsubscribe());
|
|
5366
|
+
this.eventUnsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
5095
5367
|
this.eventUnsubscribers = [];
|
|
5096
5368
|
if (this.element.parentNode) {
|
|
5097
5369
|
this.element.parentNode.removeChild(this.element);
|
|
@@ -5152,7 +5424,7 @@
|
|
|
5152
5424
|
setupEventListeners() {
|
|
5153
5425
|
// Header controls
|
|
5154
5426
|
const controls = this.headerElement.querySelectorAll('.devinspector-control');
|
|
5155
|
-
controls.forEach(control => {
|
|
5427
|
+
controls.forEach((control) => {
|
|
5156
5428
|
control.addEventListener('click', (e) => {
|
|
5157
5429
|
e.stopPropagation();
|
|
5158
5430
|
const className = control.className;
|
|
@@ -5195,7 +5467,7 @@
|
|
|
5195
5467
|
const rect = this.element.getBoundingClientRect();
|
|
5196
5468
|
this.dragOffset = {
|
|
5197
5469
|
x: e.clientX - rect.left,
|
|
5198
|
-
y: e.clientY - rect.top
|
|
5470
|
+
y: e.clientY - rect.top,
|
|
5199
5471
|
};
|
|
5200
5472
|
this.headerElement.style.cursor = 'grabbing';
|
|
5201
5473
|
this.element.style.zIndex = '1000000';
|
|
@@ -5293,12 +5565,12 @@
|
|
|
5293
5565
|
return;
|
|
5294
5566
|
this.tabs.delete(tabId);
|
|
5295
5567
|
// Remove tab element
|
|
5296
|
-
const tab = Array.from(this.tabsElement.querySelectorAll('.devinspector-tab')).find(el => el.dataset.tabId === tabId);
|
|
5568
|
+
const tab = Array.from(this.tabsElement.querySelectorAll('.devinspector-tab')).find((el) => el.dataset.tabId === tabId);
|
|
5297
5569
|
if (tab) {
|
|
5298
5570
|
tab.remove();
|
|
5299
5571
|
}
|
|
5300
5572
|
// Remove panel element
|
|
5301
|
-
const panel = Array.from(this.bodyElement.querySelectorAll('.devinspector-panel')).find(el => el.dataset.panelId === tabId);
|
|
5573
|
+
const panel = Array.from(this.bodyElement.querySelectorAll('.devinspector-panel')).find((el) => el.dataset.panelId === tabId);
|
|
5302
5574
|
if (panel) {
|
|
5303
5575
|
panel.remove();
|
|
5304
5576
|
}
|
|
@@ -5318,12 +5590,12 @@
|
|
|
5318
5590
|
return;
|
|
5319
5591
|
this.activeTab = tabId;
|
|
5320
5592
|
// Update tab states
|
|
5321
|
-
this.tabsElement.querySelectorAll('.devinspector-tab').forEach(tab => {
|
|
5593
|
+
this.tabsElement.querySelectorAll('.devinspector-tab').forEach((tab) => {
|
|
5322
5594
|
const htmlTab = tab;
|
|
5323
5595
|
tab.classList.toggle('active', htmlTab.dataset.tabId === tabId);
|
|
5324
5596
|
});
|
|
5325
5597
|
// Update panel states
|
|
5326
|
-
this.bodyElement.querySelectorAll('.devinspector-panel').forEach(panel => {
|
|
5598
|
+
this.bodyElement.querySelectorAll('.devinspector-panel').forEach((panel) => {
|
|
5327
5599
|
const htmlPanel = panel;
|
|
5328
5600
|
panel.classList.toggle('active', htmlPanel.dataset.panelId === tabId);
|
|
5329
5601
|
});
|
|
@@ -5332,7 +5604,7 @@
|
|
|
5332
5604
|
this.tabs.forEach((config, tabId) => {
|
|
5333
5605
|
if (config.badge) {
|
|
5334
5606
|
const count = config.badge();
|
|
5335
|
-
const tab = Array.from(this.tabsElement.querySelectorAll('.devinspector-tab')).find(el => el.dataset.tabId === tabId);
|
|
5607
|
+
const tab = Array.from(this.tabsElement.querySelectorAll('.devinspector-tab')).find((el) => el.dataset.tabId === tabId);
|
|
5336
5608
|
const badge = tab === null || tab === void 0 ? void 0 : tab.querySelector('.devinspector-tab-badge');
|
|
5337
5609
|
if (badge) {
|
|
5338
5610
|
badge.textContent = count.toString();
|
|
@@ -5375,31 +5647,33 @@
|
|
|
5375
5647
|
}
|
|
5376
5648
|
|
|
5377
5649
|
const createStyles = (theme = 'dark') => {
|
|
5378
|
-
const colors = theme === 'dark'
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5650
|
+
const colors = theme === 'dark'
|
|
5651
|
+
? {
|
|
5652
|
+
primary: '#1e1e1e',
|
|
5653
|
+
secondary: '#2d2d30',
|
|
5654
|
+
tertiary: '#3e3e42',
|
|
5655
|
+
accent: '#007acc',
|
|
5656
|
+
text: '#cccccc',
|
|
5657
|
+
textSecondary: '#9d9d9d',
|
|
5658
|
+
border: '#3e3e42',
|
|
5659
|
+
success: '#4caf50',
|
|
5660
|
+
warning: '#ff9800',
|
|
5661
|
+
error: '#f44336',
|
|
5662
|
+
info: '#2196f3',
|
|
5663
|
+
}
|
|
5664
|
+
: {
|
|
5665
|
+
primary: '#ffffff',
|
|
5666
|
+
secondary: '#f5f5f5',
|
|
5667
|
+
tertiary: '#e0e0e0',
|
|
5668
|
+
accent: '#1976d2',
|
|
5669
|
+
text: '#333333',
|
|
5670
|
+
textSecondary: '#666666',
|
|
5671
|
+
border: '#ddd',
|
|
5672
|
+
success: '#4caf50',
|
|
5673
|
+
warning: '#ff9800',
|
|
5674
|
+
error: '#f44336',
|
|
5675
|
+
info: '#2196f3',
|
|
5676
|
+
};
|
|
5403
5677
|
return `
|
|
5404
5678
|
.devinspector {
|
|
5405
5679
|
position: fixed;
|
|
@@ -5944,7 +6218,8 @@
|
|
|
5944
6218
|
injectStyles() {
|
|
5945
6219
|
this.styleElement = document.createElement('style');
|
|
5946
6220
|
const theme = this.inspector.getConfig().theme;
|
|
5947
|
-
const prefersDark = typeof window.matchMedia === 'function' &&
|
|
6221
|
+
const prefersDark = typeof window.matchMedia === 'function' &&
|
|
6222
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
5948
6223
|
const resolvedTheme = theme === 'auto' ? (prefersDark ? 'dark' : 'light') : theme;
|
|
5949
6224
|
this.styleElement.textContent = createStyles(resolvedTheme);
|
|
5950
6225
|
document.head.appendChild(this.styleElement);
|
|
@@ -5955,27 +6230,27 @@
|
|
|
5955
6230
|
id: 'network',
|
|
5956
6231
|
label: 'Network',
|
|
5957
6232
|
badge: () => this.inspector.getStorage('network').getSize(),
|
|
5958
|
-
content: this.createNetworkPanel()
|
|
6233
|
+
content: this.createNetworkPanel(),
|
|
5959
6234
|
};
|
|
5960
6235
|
// Console tab
|
|
5961
6236
|
const consoleTab = {
|
|
5962
6237
|
id: 'console',
|
|
5963
6238
|
label: 'Console',
|
|
5964
6239
|
badge: () => this.inspector.getStorage('console').getSize(),
|
|
5965
|
-
content: this.createConsolePanel()
|
|
6240
|
+
content: this.createConsolePanel(),
|
|
5966
6241
|
};
|
|
5967
6242
|
// Performance tab
|
|
5968
6243
|
const performanceTab = {
|
|
5969
6244
|
id: 'performance',
|
|
5970
6245
|
label: 'Performance',
|
|
5971
|
-
content: this.createPerformancePanel()
|
|
6246
|
+
content: this.createPerformancePanel(),
|
|
5972
6247
|
};
|
|
5973
6248
|
// Errors tab
|
|
5974
6249
|
const errorsTab = {
|
|
5975
6250
|
id: 'errors',
|
|
5976
6251
|
label: 'Errors',
|
|
5977
6252
|
badge: () => this.inspector.getStorage('error').getSize(),
|
|
5978
|
-
content: this.createErrorsPanel()
|
|
6253
|
+
content: this.createErrorsPanel(),
|
|
5979
6254
|
};
|
|
5980
6255
|
this.mainPanel.addTab(networkTab);
|
|
5981
6256
|
this.mainPanel.addTab(consoleTab);
|
|
@@ -6112,7 +6387,7 @@
|
|
|
6112
6387
|
list.appendChild(entry);
|
|
6113
6388
|
}
|
|
6114
6389
|
updateNetworkEntry(panel, response) {
|
|
6115
|
-
const entry = Array.from(panel.querySelectorAll('[data-request-id]')).find(el => el.dataset.requestId === String(response.id));
|
|
6390
|
+
const entry = Array.from(panel.querySelectorAll('[data-request-id]')).find((el) => el.dataset.requestId === String(response.id));
|
|
6116
6391
|
if (!entry)
|
|
6117
6392
|
return;
|
|
6118
6393
|
const status = entry.querySelector('.devinspector-status');
|
|
@@ -6170,7 +6445,8 @@
|
|
|
6170
6445
|
}
|
|
6171
6446
|
}
|
|
6172
6447
|
formatConsoleArgs(args) {
|
|
6173
|
-
return args
|
|
6448
|
+
return args
|
|
6449
|
+
.map((arg) => {
|
|
6174
6450
|
if (typeof arg === 'string') {
|
|
6175
6451
|
return arg;
|
|
6176
6452
|
}
|
|
@@ -6180,7 +6456,8 @@
|
|
|
6180
6456
|
else {
|
|
6181
6457
|
return String(arg);
|
|
6182
6458
|
}
|
|
6183
|
-
})
|
|
6459
|
+
})
|
|
6460
|
+
.join(' ');
|
|
6184
6461
|
}
|
|
6185
6462
|
show() {
|
|
6186
6463
|
this.mainPanel.show();
|