@presto1314w/vite-devtools-browser 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -14
- package/dist/browser-collector.d.ts +3 -0
- package/dist/browser-collector.js +256 -0
- package/dist/browser-frameworks.d.ts +11 -0
- package/dist/browser-frameworks.js +72 -0
- package/dist/browser-session.d.ts +27 -0
- package/dist/browser-session.js +113 -0
- package/dist/browser-vite.d.ts +25 -0
- package/dist/browser-vite.js +181 -0
- package/dist/browser.d.ts +4 -28
- package/dist/browser.js +70 -444
- package/dist/cli.js +13 -0
- package/dist/correlate.d.ts +2 -1
- package/dist/correlate.js +11 -42
- package/dist/daemon.js +12 -0
- package/dist/diagnose-propagation.d.ts +10 -0
- package/dist/diagnose-propagation.js +58 -0
- package/dist/event-analysis.d.ts +32 -0
- package/dist/event-analysis.js +75 -0
- package/dist/event-queue.d.ts +70 -5
- package/dist/trace.d.ts +15 -0
- package/dist/trace.js +75 -0
- package/package.json +1 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
export function normalizeLimit(limit, fallback, max) {
|
|
2
|
+
if (!Number.isFinite(limit) || limit <= 0)
|
|
3
|
+
return fallback;
|
|
4
|
+
return Math.min(limit, max);
|
|
5
|
+
}
|
|
6
|
+
export function formatRuntimeStatus(runtime, currentFramework, events) {
|
|
7
|
+
const output = [];
|
|
8
|
+
output.push("# Vite Runtime");
|
|
9
|
+
output.push(`URL: ${runtime.url}`);
|
|
10
|
+
output.push(`Framework: ${currentFramework}`);
|
|
11
|
+
output.push(`Vite Client: ${runtime.hasViteClient ? "loaded" : "not detected"}`);
|
|
12
|
+
output.push(`HMR Socket: ${runtime.wsState}`);
|
|
13
|
+
output.push(`Error Overlay: ${runtime.hasErrorOverlay ? "present" : "none"}`);
|
|
14
|
+
output.push(`Tracked HMR Events: ${events.length}`);
|
|
15
|
+
const last = events[events.length - 1];
|
|
16
|
+
if (last) {
|
|
17
|
+
output.push(`Last HMR Event: ${new Date(last.timestamp).toLocaleTimeString()} [${last.type}] ${last.message}`);
|
|
18
|
+
}
|
|
19
|
+
return output.join("\n");
|
|
20
|
+
}
|
|
21
|
+
export function formatHmrTrace(mode, events, limit) {
|
|
22
|
+
if (events.length === 0)
|
|
23
|
+
return "No HMR updates";
|
|
24
|
+
const safeLimit = normalizeLimit(limit, 20, 200);
|
|
25
|
+
const recent = events.slice(-safeLimit);
|
|
26
|
+
if (mode === "summary") {
|
|
27
|
+
const counts = recent.reduce((acc, event) => {
|
|
28
|
+
acc[event.type] = (acc[event.type] ?? 0) + 1;
|
|
29
|
+
return acc;
|
|
30
|
+
}, {});
|
|
31
|
+
const lines = ["# HMR Summary"];
|
|
32
|
+
lines.push(`Events considered: ${recent.length}`);
|
|
33
|
+
lines.push(`Counts: ${Object.entries(counts)
|
|
34
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
35
|
+
.join(", ")}`);
|
|
36
|
+
const last = recent[recent.length - 1];
|
|
37
|
+
lines.push(`Last: ${new Date(last.timestamp).toLocaleTimeString()} [${last.type}] ${last.path ?? last.message}`);
|
|
38
|
+
lines.push("\nUse `vite-browser vite hmr trace --limit <n>` for timeline details.");
|
|
39
|
+
return lines.join("\n");
|
|
40
|
+
}
|
|
41
|
+
return [
|
|
42
|
+
"# HMR Trace",
|
|
43
|
+
...recent.map((event) => {
|
|
44
|
+
const detail = event.path ? `${event.path}` : event.message;
|
|
45
|
+
return `[${new Date(event.timestamp).toLocaleTimeString()}] ${event.type} ${detail}`;
|
|
46
|
+
}),
|
|
47
|
+
].join("\n");
|
|
48
|
+
}
|
|
49
|
+
export function formatModuleGraphSnapshot(rows, filter, limit = 200) {
|
|
50
|
+
const normalizedFilter = filter?.trim().toLowerCase();
|
|
51
|
+
const safeLimit = normalizeLimit(limit, 200, 500);
|
|
52
|
+
const filtered = rows.filter((row) => normalizedFilter ? row.url.toLowerCase().includes(normalizedFilter) : true);
|
|
53
|
+
const limited = filtered.slice(0, safeLimit);
|
|
54
|
+
if (limited.length === 0)
|
|
55
|
+
return "No module resources found";
|
|
56
|
+
const lines = [];
|
|
57
|
+
lines.push("# Vite Module Graph (loaded resources)");
|
|
58
|
+
lines.push(`Total: ${filtered.length}${filtered.length > limited.length ? ` (showing ${limited.length})` : ""}`);
|
|
59
|
+
lines.push("# idx initiator ms url");
|
|
60
|
+
lines.push("");
|
|
61
|
+
limited.forEach((row, idx) => {
|
|
62
|
+
lines.push(`${idx} ${row.initiator} ${row.durationMs}ms ${row.url}`);
|
|
63
|
+
});
|
|
64
|
+
return lines.join("\n");
|
|
65
|
+
}
|
|
66
|
+
export function formatModuleGraphTrace(currentUrls, previousUrls, filter, limit = 200) {
|
|
67
|
+
if (!previousUrls) {
|
|
68
|
+
return "No module-graph baseline. Captured current snapshot; run `vite module-graph trace` again.";
|
|
69
|
+
}
|
|
70
|
+
const currentSet = new Set(currentUrls);
|
|
71
|
+
const added = currentUrls.filter((url) => !previousUrls.has(url));
|
|
72
|
+
const removed = [...previousUrls].filter((url) => !currentSet.has(url));
|
|
73
|
+
const normalizedFilter = filter?.trim().toLowerCase();
|
|
74
|
+
const safeLimit = normalizeLimit(limit, 200, 500);
|
|
75
|
+
const addedFiltered = normalizedFilter
|
|
76
|
+
? added.filter((url) => url.toLowerCase().includes(normalizedFilter))
|
|
77
|
+
: added;
|
|
78
|
+
const removedFiltered = normalizedFilter
|
|
79
|
+
? removed.filter((url) => url.toLowerCase().includes(normalizedFilter))
|
|
80
|
+
: removed;
|
|
81
|
+
const lines = [];
|
|
82
|
+
lines.push("# Vite Module Graph Trace");
|
|
83
|
+
lines.push(`Added: ${addedFiltered.length}, Removed: ${removedFiltered.length}`);
|
|
84
|
+
lines.push("");
|
|
85
|
+
lines.push("## Added");
|
|
86
|
+
if (addedFiltered.length === 0)
|
|
87
|
+
lines.push("(none)");
|
|
88
|
+
else
|
|
89
|
+
addedFiltered.slice(0, safeLimit).forEach((url) => lines.push(`+ ${url}`));
|
|
90
|
+
lines.push("");
|
|
91
|
+
lines.push("## Removed");
|
|
92
|
+
if (removedFiltered.length === 0)
|
|
93
|
+
lines.push("(none)");
|
|
94
|
+
else
|
|
95
|
+
removedFiltered.slice(0, safeLimit).forEach((url) => lines.push(`- ${url}`));
|
|
96
|
+
return lines.join("\n");
|
|
97
|
+
}
|
|
98
|
+
export async function readRuntimeSnapshot(page) {
|
|
99
|
+
return page.evaluate(() => {
|
|
100
|
+
const findViteClient = () => {
|
|
101
|
+
const scripts = Array.from(document.querySelectorAll("script[src]"));
|
|
102
|
+
return scripts.some((script) => script.getAttribute("src")?.includes("/@vite/client"));
|
|
103
|
+
};
|
|
104
|
+
const wsStateName = (wsState) => {
|
|
105
|
+
if (wsState == null)
|
|
106
|
+
return "unknown";
|
|
107
|
+
if (wsState === 0)
|
|
108
|
+
return "connecting";
|
|
109
|
+
if (wsState === 1)
|
|
110
|
+
return "open";
|
|
111
|
+
if (wsState === 2)
|
|
112
|
+
return "closing";
|
|
113
|
+
if (wsState === 3)
|
|
114
|
+
return "closed";
|
|
115
|
+
return "unknown";
|
|
116
|
+
};
|
|
117
|
+
const hot = window.__vite_hot;
|
|
118
|
+
const ws = hot?.ws || hot?.socket;
|
|
119
|
+
return {
|
|
120
|
+
url: location.href,
|
|
121
|
+
hasViteClient: findViteClient(),
|
|
122
|
+
wsState: wsStateName(ws?.readyState),
|
|
123
|
+
hasErrorOverlay: Boolean(document.querySelector("vite-error-overlay")),
|
|
124
|
+
timestamp: Date.now(),
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
export async function collectModuleRows(page) {
|
|
129
|
+
return page.evaluate(() => {
|
|
130
|
+
const isLikelyModuleUrl = (url) => {
|
|
131
|
+
if (!url)
|
|
132
|
+
return false;
|
|
133
|
+
if (url.includes("/@vite/"))
|
|
134
|
+
return true;
|
|
135
|
+
if (url.includes("/@id/"))
|
|
136
|
+
return true;
|
|
137
|
+
if (url.includes("/src/"))
|
|
138
|
+
return true;
|
|
139
|
+
if (url.includes("/node_modules/"))
|
|
140
|
+
return true;
|
|
141
|
+
return /\.(mjs|cjs|js|jsx|ts|tsx|vue|css)(\?|$)/.test(url);
|
|
142
|
+
};
|
|
143
|
+
const scripts = Array.from(document.querySelectorAll("script[src]")).map((node) => node.src);
|
|
144
|
+
const resources = performance
|
|
145
|
+
.getEntriesByType("resource")
|
|
146
|
+
.map((entry) => {
|
|
147
|
+
const item = entry;
|
|
148
|
+
return {
|
|
149
|
+
url: item.name,
|
|
150
|
+
initiator: item.initiatorType || "unknown",
|
|
151
|
+
durationMs: Number(item.duration.toFixed(1)),
|
|
152
|
+
};
|
|
153
|
+
})
|
|
154
|
+
.filter((entry) => isLikelyModuleUrl(entry.url));
|
|
155
|
+
const all = [
|
|
156
|
+
...scripts
|
|
157
|
+
.filter((url) => isLikelyModuleUrl(url))
|
|
158
|
+
.map((url) => ({ url, initiator: "script-tag", durationMs: 0 })),
|
|
159
|
+
...resources,
|
|
160
|
+
];
|
|
161
|
+
const seen = new Set();
|
|
162
|
+
const unique = [];
|
|
163
|
+
for (const row of all) {
|
|
164
|
+
if (seen.has(row.url))
|
|
165
|
+
continue;
|
|
166
|
+
seen.add(row.url);
|
|
167
|
+
unique.push(row);
|
|
168
|
+
}
|
|
169
|
+
return unique;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
export async function readOverlayError(page) {
|
|
173
|
+
return page.evaluate(() => {
|
|
174
|
+
const overlay = document.querySelector("vite-error-overlay");
|
|
175
|
+
if (!overlay || !overlay.shadowRoot)
|
|
176
|
+
return null;
|
|
177
|
+
const message = overlay.shadowRoot.querySelector(".message")?.textContent?.trim();
|
|
178
|
+
const stack = overlay.shadowRoot.querySelector(".stack")?.textContent?.trim();
|
|
179
|
+
return { message, stack };
|
|
180
|
+
});
|
|
181
|
+
}
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Page } from "playwright";
|
|
2
|
+
import { type HmrEvent } from "./browser-session.js";
|
|
2
3
|
import { resolveViaSourceMap } from "./sourcemap.js";
|
|
3
4
|
import { EventQueue } from "./event-queue.js";
|
|
4
|
-
|
|
5
|
-
export type
|
|
6
|
-
timestamp: number;
|
|
7
|
-
type: HmrEventType;
|
|
8
|
-
message: string;
|
|
9
|
-
path?: string;
|
|
10
|
-
};
|
|
11
|
-
export type RuntimeSnapshot = {
|
|
12
|
-
url: string;
|
|
13
|
-
hasViteClient: boolean;
|
|
14
|
-
wsState: string;
|
|
15
|
-
hasErrorOverlay: boolean;
|
|
16
|
-
timestamp: number;
|
|
17
|
-
};
|
|
18
|
-
export type ModuleRow = {
|
|
19
|
-
url: string;
|
|
20
|
-
initiator: string;
|
|
21
|
-
durationMs: number;
|
|
22
|
-
};
|
|
5
|
+
export { contextUsable, isClosedTargetError, type HmrEvent } from "./browser-session.js";
|
|
6
|
+
export { formatHmrTrace, formatModuleGraphSnapshot, formatModuleGraphTrace, formatRuntimeStatus, normalizeLimit, type ModuleRow, type RuntimeSnapshot, } from "./browser-vite.js";
|
|
23
7
|
export type ModuleGraphMode = "snapshot" | "trace" | "clear";
|
|
24
8
|
export declare function setEventQueue(queue: EventQueue): void;
|
|
25
9
|
export declare function getEventQueue(): EventQueue | null;
|
|
@@ -34,15 +18,8 @@ export declare function cookies(cookies: {
|
|
|
34
18
|
value: string;
|
|
35
19
|
}[], domain: string): Promise<number>;
|
|
36
20
|
export declare function close(): Promise<void>;
|
|
37
|
-
export declare function contextUsable(current: Pick<BrowserContext, "pages"> | null): current is Pick<BrowserContext, "pages">;
|
|
38
|
-
export declare function isClosedTargetError(error: unknown): boolean;
|
|
39
21
|
export declare function recordConsoleMessage(logs: string[], events: HmrEvent[], type: string, message: string, maxLogs?: number, maxEvents?: number): void;
|
|
40
22
|
export declare function parseViteLog(message: string): HmrEvent;
|
|
41
|
-
export declare function normalizeLimit(limit: number, fallback: number, max: number): number;
|
|
42
|
-
export declare function formatRuntimeStatus(runtime: RuntimeSnapshot, currentFramework: string, events: HmrEvent[]): string;
|
|
43
|
-
export declare function formatHmrTrace(mode: "summary" | "trace", events: HmrEvent[], limit: number): string;
|
|
44
|
-
export declare function formatModuleGraphSnapshot(rows: ModuleRow[], filter?: string, limit?: number): string;
|
|
45
|
-
export declare function formatModuleGraphTrace(currentUrls: string[], previousUrls: Set<string> | null, filter?: string, limit?: number): string;
|
|
46
23
|
export declare function goto(url: string): Promise<string>;
|
|
47
24
|
export declare function back(): Promise<void>;
|
|
48
25
|
export declare function reload(): Promise<string>;
|
|
@@ -63,4 +40,3 @@ export declare function screenshot(): Promise<string>;
|
|
|
63
40
|
export declare function evaluate(script: string): Promise<string>;
|
|
64
41
|
export declare function network(idx?: number): Promise<string>;
|
|
65
42
|
export declare function mapStackTrace(stack: string, origin: string, inlineSource?: boolean, resolver?: typeof resolveViaSourceMap): Promise<string>;
|
|
66
|
-
export {};
|