@capybara-devtools/core 0.8.0 → 0.9.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/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +5 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +4 -0
- package/dist/init.js.map +1 -1
- package/dist/plugins/network/fetch.d.ts.map +1 -1
- package/dist/plugins/network/fetch.js +1 -0
- package/dist/plugins/network/fetch.js.map +1 -1
- package/dist/plugins/network/settings.d.ts +4 -0
- package/dist/plugins/network/settings.d.ts.map +1 -1
- package/dist/plugins/network/settings.js.map +1 -1
- package/dist/plugins/network/timing.d.ts +9 -0
- package/dist/plugins/network/timing.d.ts.map +1 -0
- package/dist/plugins/network/timing.js +79 -0
- package/dist/plugins/network/timing.js.map +1 -0
- package/dist/plugins/network/xhr.d.ts.map +1 -1
- package/dist/plugins/network/xhr.js +1 -0
- package/dist/plugins/network/xhr.js.map +1 -1
- package/dist/plugins/network.d.ts.map +1 -1
- package/dist/plugins/network.js +4 -1
- package/dist/plugins/network.js.map +1 -1
- package/dist/plugins/performance/index.d.ts +41 -0
- package/dist/plugins/performance/index.d.ts.map +1 -0
- package/dist/plugins/performance/index.js +215 -0
- package/dist/plugins/performance/index.js.map +1 -0
- package/dist/plugins/performance/observe.d.ts +42 -0
- package/dist/plugins/performance/observe.d.ts.map +1 -0
- package/dist/plugins/performance/observe.js +1280 -0
- package/dist/plugins/performance/observe.js.map +1 -0
- package/dist/plugins/performance/profile.d.ts +50 -0
- package/dist/plugins/performance/profile.d.ts.map +1 -0
- package/dist/plugins/performance/profile.js +196 -0
- package/dist/plugins/performance/profile.js.map +1 -0
- package/dist/plugins/performance/renders.d.ts +13 -0
- package/dist/plugins/performance/renders.d.ts.map +1 -0
- package/dist/plugins/performance/renders.js +144 -0
- package/dist/plugins/performance/renders.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/init.ts +8 -0
- package/src/plugins/network/fetch.ts +1 -0
- package/src/plugins/network/settings.ts +4 -0
- package/src/plugins/network/timing.ts +82 -0
- package/src/plugins/network/xhr.ts +1 -0
- package/src/plugins/network.ts +3 -1
- package/src/plugins/performance/index.ts +243 -0
- package/src/plugins/performance/observe.ts +1291 -0
- package/src/plugins/performance/profile.ts +232 -0
- package/src/plugins/performance/renders.ts +152 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { PERF_MAX_MONITOR_MS } from '@capybara-devtools/protocol';
|
|
2
|
+
import { getActiveClient } from '../../client.js';
|
|
3
|
+
import { watchRenders } from './renders.js';
|
|
4
|
+
export { observePerformance } from './observe.js';
|
|
5
|
+
export { sampleStacks } from './profile.js';
|
|
6
|
+
/** React commits sent per batch, the slowest; the rest are counted as skipped. */
|
|
7
|
+
const COMMITS_PER_BATCH = 20;
|
|
8
|
+
/** Commits held while Capybara is not connected. */
|
|
9
|
+
const COMMITS_WAITING = 200;
|
|
10
|
+
const BATCH_MS = 1_000;
|
|
11
|
+
const SAMPLE_MS = 1_000;
|
|
12
|
+
/** Interactions and frames at least this long get a profile: under 10 samples say too little. */
|
|
13
|
+
const PROFILE_FROM_MS = 100;
|
|
14
|
+
/** A profile starts this much before what it is about and ends as much after, for what led to it. */
|
|
15
|
+
const PROFILE_MARGIN_MS = 20;
|
|
16
|
+
const PROFILES_PER_BATCH = 3;
|
|
17
|
+
const PROFILES_PER_MINUTE = 30;
|
|
18
|
+
/** How often sampling is stopped while no one is connected, and started again once someone is. */
|
|
19
|
+
const PROFILE_CHECK_MS = 5_000;
|
|
20
|
+
export function performancePlugin(options, platform) {
|
|
21
|
+
let ctx;
|
|
22
|
+
let env = { source: 'sdk', build: platform.build };
|
|
23
|
+
let until = 0;
|
|
24
|
+
let sampler;
|
|
25
|
+
let monitorSampler;
|
|
26
|
+
let sampleTimer;
|
|
27
|
+
let collector;
|
|
28
|
+
const isConnected = () => getActiveClient()?.connected === true;
|
|
29
|
+
const announce = (change) => {
|
|
30
|
+
env = { ...env, ...change };
|
|
31
|
+
ctx?.emit('perf.env', env);
|
|
32
|
+
};
|
|
33
|
+
const stopSampling = () => {
|
|
34
|
+
if (sampleTimer !== undefined)
|
|
35
|
+
clearInterval(sampleTimer);
|
|
36
|
+
sampleTimer = undefined;
|
|
37
|
+
monitorSampler?.stop();
|
|
38
|
+
monitorSampler = undefined;
|
|
39
|
+
};
|
|
40
|
+
const sample = () => {
|
|
41
|
+
if (!monitorSampler || Date.now() > until)
|
|
42
|
+
return stopSampling();
|
|
43
|
+
try {
|
|
44
|
+
ctx?.emit('perf.samples', { source: 'page', samples: [{ t: Date.now(), values: monitorSampler.read() }] });
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
stopSampling();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const announceProfiler = () => {
|
|
51
|
+
if (sampler && env.profiler?.state !== sampler.state())
|
|
52
|
+
announce({ profiler: { state: sampler.state() } });
|
|
53
|
+
};
|
|
54
|
+
const commands = {
|
|
55
|
+
status: () => ({ env, monitoring: monitorSampler !== undefined && Date.now() <= until }),
|
|
56
|
+
// Viewers cannot be told apart, so the latest end of all their leases wins.
|
|
57
|
+
monitor: (params) => {
|
|
58
|
+
const ttl = Math.min(Math.max(Number(params?.ttl) || 0, 0), PERF_MAX_MONITOR_MS);
|
|
59
|
+
until = Math.max(until, Date.now() + ttl);
|
|
60
|
+
if (!monitorSampler && platform.monitor && ttl > 0) {
|
|
61
|
+
monitorSampler = platform.monitor();
|
|
62
|
+
sampleTimer = setInterval(sample, SAMPLE_MS);
|
|
63
|
+
}
|
|
64
|
+
return { until };
|
|
65
|
+
},
|
|
66
|
+
highlight: (params) => ({ found: typeof params?.selector === 'string' && platform.highlight?.(params.selector) === true }),
|
|
67
|
+
inspect: () => ({ sent: collector?.inspect?.() === true }),
|
|
68
|
+
profile: (params) => {
|
|
69
|
+
sampler?.hold(params?.hold === true);
|
|
70
|
+
announceProfiler();
|
|
71
|
+
return { state: sampler?.state() ?? 'off' };
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
name: 'performance',
|
|
76
|
+
commands,
|
|
77
|
+
setup(context) {
|
|
78
|
+
ctx = context;
|
|
79
|
+
const teardowns = [stopSampling];
|
|
80
|
+
announce({
|
|
81
|
+
...(platform.timeOrigin?.() !== undefined && { timeOrigin: platform.timeOrigin?.() }),
|
|
82
|
+
...(platform.entryTypes && { entryTypes: platform.entryTypes() }),
|
|
83
|
+
...(platform.background?.() && { background: true }),
|
|
84
|
+
});
|
|
85
|
+
let emit = context.emit;
|
|
86
|
+
if (options.profile !== false && platform.profile) {
|
|
87
|
+
const stacks = platform.profile(isConnected);
|
|
88
|
+
sampler = stacks;
|
|
89
|
+
announceProfiler();
|
|
90
|
+
let spans = [];
|
|
91
|
+
let cutting;
|
|
92
|
+
const sent = [];
|
|
93
|
+
let dropped = 0;
|
|
94
|
+
const cut = async () => {
|
|
95
|
+
cutting = undefined;
|
|
96
|
+
// Spans that overlap are one moment: a slow click and the long frame it ran in.
|
|
97
|
+
const merged = [];
|
|
98
|
+
for (const span of spans.splice(0).sort((a, b) => a[0] - b[0])) {
|
|
99
|
+
const last = merged.at(-1);
|
|
100
|
+
if (last && span[0] <= last[1])
|
|
101
|
+
last[1] = Math.max(last[1], span[1]);
|
|
102
|
+
else
|
|
103
|
+
merged.push([...span]);
|
|
104
|
+
}
|
|
105
|
+
const time = Date.now();
|
|
106
|
+
while (sent.length > 0 && time - sent[0] > 60_000)
|
|
107
|
+
sent.shift();
|
|
108
|
+
const room = Math.max(0, Math.min(PROFILES_PER_BATCH, PROFILES_PER_MINUTE - sent.length));
|
|
109
|
+
const chosen = merged.sort((a, b) => b[1] - b[0] - (a[1] - a[0])).slice(0, room);
|
|
110
|
+
dropped += merged.length - chosen.length;
|
|
111
|
+
if (chosen.length === 0)
|
|
112
|
+
return;
|
|
113
|
+
try {
|
|
114
|
+
for (const profile of await stacks.cut(chosen.sort((a, b) => a[0] - b[0]))) {
|
|
115
|
+
sent.push(Date.now());
|
|
116
|
+
ctx?.emit('perf.profile', dropped > 0 ? { ...profile, skipped: dropped } : profile);
|
|
117
|
+
dropped = 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// A profile lost is a section missing, not a page broken.
|
|
122
|
+
}
|
|
123
|
+
announceProfiler();
|
|
124
|
+
};
|
|
125
|
+
emit = (kind, payload) => {
|
|
126
|
+
context.emit(kind, payload);
|
|
127
|
+
// The collector sends only once connected: the first thing it sends starts the sampling the plugin could
|
|
128
|
+
// not start before.
|
|
129
|
+
if (stacks.state() === 'paused') {
|
|
130
|
+
stacks.check();
|
|
131
|
+
announceProfiler();
|
|
132
|
+
}
|
|
133
|
+
if (kind !== 'perf.interaction' && kind !== 'perf.frame')
|
|
134
|
+
return;
|
|
135
|
+
const { start, duration } = payload;
|
|
136
|
+
if (!(duration >= PROFILE_FROM_MS))
|
|
137
|
+
return;
|
|
138
|
+
spans.push([start - PROFILE_MARGIN_MS, start + duration + PROFILE_MARGIN_MS]);
|
|
139
|
+
cutting ??= setTimeout(() => void cut(), 0);
|
|
140
|
+
};
|
|
141
|
+
const checking = setInterval(() => {
|
|
142
|
+
stacks.check();
|
|
143
|
+
announceProfiler();
|
|
144
|
+
}, PROFILE_CHECK_MS);
|
|
145
|
+
teardowns.push(() => {
|
|
146
|
+
clearInterval(checking);
|
|
147
|
+
if (cutting !== undefined)
|
|
148
|
+
clearTimeout(cutting);
|
|
149
|
+
spans = [];
|
|
150
|
+
stacks.stop();
|
|
151
|
+
sampler = undefined;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (platform.observe) {
|
|
155
|
+
const observed = platform.observe(emit, isConnected, {
|
|
156
|
+
threshold: options.interactionThreshold ?? 16,
|
|
157
|
+
resources: options.resources !== false,
|
|
158
|
+
serialize: context.serialize,
|
|
159
|
+
});
|
|
160
|
+
collector = observed;
|
|
161
|
+
teardowns.push(() => {
|
|
162
|
+
observed();
|
|
163
|
+
collector = undefined;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (options.renders !== false) {
|
|
167
|
+
let commits = [];
|
|
168
|
+
let skipped = 0;
|
|
169
|
+
let timer;
|
|
170
|
+
const flush = () => {
|
|
171
|
+
timer = undefined;
|
|
172
|
+
if (!isConnected()) {
|
|
173
|
+
if (commits.length > 0)
|
|
174
|
+
timer = setTimeout(flush, BATCH_MS);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const batch = commits.splice(0).sort((a, b) => b.duration - a.duration);
|
|
178
|
+
skipped += Math.max(0, batch.length - COMMITS_PER_BATCH);
|
|
179
|
+
const sent = batch.slice(0, COMMITS_PER_BATCH).sort((a, b) => a.start - b.start);
|
|
180
|
+
if (sent.length > 0)
|
|
181
|
+
context.emit('perf.render', skipped > 0 ? { commits: sent, skipped } : { commits: sent });
|
|
182
|
+
skipped = 0;
|
|
183
|
+
};
|
|
184
|
+
const stop = watchRenders((commit) => {
|
|
185
|
+
commits.push(commit);
|
|
186
|
+
if (commits.length > COMMITS_WAITING) {
|
|
187
|
+
skipped += commits.length - COMMITS_WAITING;
|
|
188
|
+
commits = commits.slice(-COMMITS_WAITING);
|
|
189
|
+
}
|
|
190
|
+
timer ??= setTimeout(flush, BATCH_MS);
|
|
191
|
+
}, (react) => {
|
|
192
|
+
const notes = (env.notes ?? []).filter((note) => !note.startsWith('React reports render times'));
|
|
193
|
+
if (react.note)
|
|
194
|
+
notes.push(react.note);
|
|
195
|
+
announce({ react: { version: react.version, profiling: react.profiling }, notes: notes.length > 0 ? notes : undefined });
|
|
196
|
+
}, (error) => {
|
|
197
|
+
const note = `Stopped timing React renders: ${error instanceof Error ? error.message : String(error)}`;
|
|
198
|
+
context.console.warn(`[capybara] ${note}`);
|
|
199
|
+
announce({ notes: [...(env.notes ?? []), note] });
|
|
200
|
+
});
|
|
201
|
+
teardowns.push(() => {
|
|
202
|
+
stop();
|
|
203
|
+
if (timer !== undefined)
|
|
204
|
+
clearTimeout(timer);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return () => {
|
|
208
|
+
for (const teardown of teardowns)
|
|
209
|
+
teardown();
|
|
210
|
+
ctx = undefined;
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/performance/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAkE,MAAM,6BAA6B,CAAC;AAClI,OAAO,EAAE,eAAe,EAAmC,MAAM,iBAAiB,CAAC;AAGnF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAA8E,MAAM,cAAc,CAAC;AAC9H,OAAO,EAAE,YAAY,EAA0C,MAAM,cAAc,CAAC;AA+BpF,kFAAkF;AAClF,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,oDAAoD;AACpD,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,QAAQ,GAAG,KAAK,CAAC;AACvB,MAAM,SAAS,GAAG,KAAK,CAAC;AACxB,iGAAiG;AACjG,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,qGAAqG;AACrG,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,kGAAkG;AAClG,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,MAAM,UAAU,iBAAiB,CAAC,OAAiC,EAAE,QAA6B;IAChG,IAAI,GAA8B,CAAC;IACnC,IAAI,GAAG,GAAmB,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QA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,KAAK,MAAM,QAAQ,IAAI,SAAS;oBAAE,QAAQ,EAAE,CAAC;gBAC7C,GAAG,GAAG,SAAS,CAAC;YAClB,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { EventPayloads } from '@capybara-devtools/protocol';
|
|
2
|
+
export type PerfCollectorKind = 'perf.navigation' | 'perf.metric' | 'perf.interaction' | 'perf.shift' | 'perf.frame' | 'perf.resources' | 'perf.timing' | 'perf.page' | 'perf.presses';
|
|
3
|
+
export type PerfEmit = <K extends PerfCollectorKind>(kind: K, payload: EventPayloads[K]) => void;
|
|
4
|
+
/** Stops the collector; `inspect` reads what the page is made of again, at most once every 10 s. */
|
|
5
|
+
export type PerfCollector = (() => void) & {
|
|
6
|
+
inspect?: () => boolean;
|
|
7
|
+
};
|
|
8
|
+
type Report = (metric: any) => void;
|
|
9
|
+
/** The attribution build of web-vitals, imported by the SDK or loaded beside an injected collector. */
|
|
10
|
+
export interface WebVitalsLike {
|
|
11
|
+
onLCP(report: Report, options?: object): void;
|
|
12
|
+
onINP(report: Report, options?: object): void;
|
|
13
|
+
onCLS(report: Report, options?: object): void;
|
|
14
|
+
onFCP(report: Report, options?: object): void;
|
|
15
|
+
onTTFB(report: Report, options?: object): void;
|
|
16
|
+
}
|
|
17
|
+
export interface ObserveOptions {
|
|
18
|
+
/** Interactions shorter than this many ms are not sent. Event Timing reports none under 16. */
|
|
19
|
+
threshold: number;
|
|
20
|
+
/** URLs left out of resources: dev tools' own traffic, as patterns. */
|
|
21
|
+
ignore: Array<{
|
|
22
|
+
source: string;
|
|
23
|
+
flags: string;
|
|
24
|
+
}>;
|
|
25
|
+
resources: boolean;
|
|
26
|
+
/** Marks the modules a dev server serves one by one (Vite), so the UI can hide them. */
|
|
27
|
+
devModules: boolean;
|
|
28
|
+
vitals?: WebVitalsLike;
|
|
29
|
+
/** For a mark's or measure's `detail`; a JSON round trip without it. */
|
|
30
|
+
serialize?: (value: unknown) => unknown;
|
|
31
|
+
/** Read React's fiber of an interaction's target for its component and handler. */
|
|
32
|
+
react: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Observes the page's performance entries and Web Vitals and emits them as `perf.*` events, in batches once a
|
|
36
|
+
* second. Callbacks only file entries; what costs (selectors, payloads) waits for the batch, so measuring adds as
|
|
37
|
+
* little as it can to the interactions it measures. Self-contained: Capybara also injects it into pages without the
|
|
38
|
+
* SDK through `toString()`, so it must not reference anything outside its own body.
|
|
39
|
+
*/
|
|
40
|
+
export declare function observePerformance(emit: PerfEmit, isConnected: () => boolean, options: ObserveOptions): PerfCollector;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=observe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../../../src/plugins/performance/observe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,aAAa,EAA6D,MAAM,6BAA6B,CAAC;AAEvI,MAAM,MAAM,iBAAiB,GACzB,iBAAiB,GACjB,aAAa,GACb,kBAAkB,GAClB,YAAY,GACZ,YAAY,GACZ,gBAAgB,GAChB,aAAa,GACb,WAAW,GACX,cAAc,CAAC;AAEnB,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,SAAS,iBAAiB,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEjG,oGAAoG;AACpG,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,OAAO,CAAA;CAAE,CAAC;AAEvE,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;AAEpC,uGAAuG;AACvG,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,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