playwright-performance-regression 0.1.0-next.3 → 1.0.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +388 -0
  2. package/README.md +53 -41
  3. package/dist/{chunk-MUZFQKGQ.js → chunk-4WX3Z5MJ.js} +321 -30
  4. package/dist/{chunk-AQ2XKYNV.js → chunk-5Y34Q4DR.js} +37 -9
  5. package/dist/chunk-B4XTLSRN.js +1788 -0
  6. package/dist/{chunk-44ASXVQN.cjs → chunk-PWK5XSP2.cjs} +337 -45
  7. package/dist/{chunk-DYLCGMI2.js → chunk-S6UH6QPK.js} +6 -1
  8. package/dist/{chunk-BAOTUUTV.cjs → chunk-VREOANPX.cjs} +75 -28
  9. package/dist/{chunk-2JO5HVPC.cjs → chunk-W7NEFS5V.cjs} +37 -9
  10. package/dist/{chunk-DX36GFOZ.js → chunk-YKBX6SAT.js} +94 -57
  11. package/dist/cli.js +1922 -3307
  12. package/dist/config.cjs +58 -120
  13. package/dist/config.d.cts +2 -3
  14. package/dist/config.d.ts +2 -3
  15. package/dist/config.js +48 -110
  16. package/dist/fixture.cjs +9 -5
  17. package/dist/fixture.d.cts +10 -4
  18. package/dist/fixture.d.ts +10 -4
  19. package/dist/fixture.js +4 -4
  20. package/dist/index.cjs +3 -3
  21. package/dist/index.d.cts +22 -10
  22. package/dist/index.d.ts +22 -10
  23. package/dist/index.js +1 -1
  24. package/dist/perf-api-2DH_keLh.d.cts +17 -0
  25. package/dist/perf-api-2DH_keLh.d.ts +17 -0
  26. package/dist/reporter.cjs +2046 -835
  27. package/dist/reporter.js +6741 -1737
  28. package/dist/test.cjs +4 -4
  29. package/dist/test.js +4 -4
  30. package/package.json +17 -3
  31. package/schemas/config.schema.json +29 -14
  32. package/schemas/outcome.schema.json +1 -1
  33. package/schemas/run-report.schema.json +16 -2
  34. package/schemas/samples.schema.json +48 -2
  35. package/dist/chunk-LTRHMBVY.js +0 -5592
  36. package/dist/perf-api-Rm1h1O_-.d.cts +0 -12
  37. package/dist/perf-api-Rm1h1O_-.d.ts +0 -12
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var chunkBAOTUUTV_cjs = require('./chunk-BAOTUUTV.cjs');
4
- var chunk2JO5HVPC_cjs = require('./chunk-2JO5HVPC.cjs');
3
+ var chunkVREOANPX_cjs = require('./chunk-VREOANPX.cjs');
4
+ var chunkW7NEFS5V_cjs = require('./chunk-W7NEFS5V.cjs');
5
5
  var fs = require('fs');
6
6
  var os = require('os');
7
7
  var path = require('path');
8
8
 
9
9
  var memory = { files: [], ran: 0 };
10
10
  function checkStatePath(runId) {
11
- return path.join(os.tmpdir(), chunkBAOTUUTV_cjs.checkStateFileName(runId));
11
+ return path.join(os.tmpdir(), chunkVREOANPX_cjs.checkStateFileName(runId));
12
12
  }
13
13
  function load(path) {
14
14
  if (path === null) return memory;
@@ -32,9 +32,93 @@ function checkRunsTest(runId, maxTests, project, file) {
32
32
  return true;
33
33
  }
34
34
 
35
+ // src/collector/api-requests.ts
36
+ var API_METHODS = ["fetch", "get", "post", "put", "patch", "delete", "head"];
37
+ var METHOD = /^[A-Z]+$/u;
38
+ var depth = 0;
39
+ function call(target, name) {
40
+ if (typeof target !== "object" || target === null) return void 0;
41
+ const fn = target[name];
42
+ if (typeof fn !== "function") return void 0;
43
+ const value = fn.call(target);
44
+ return typeof value === "string" ? value : void 0;
45
+ }
46
+ function resolveUrl(raw, baseURL) {
47
+ try {
48
+ return new URL(raw).toString();
49
+ } catch {
50
+ }
51
+ if (baseURL === void 0 || baseURL === "") return null;
52
+ try {
53
+ return new URL(raw, baseURL).toString();
54
+ } catch {
55
+ return null;
56
+ }
57
+ }
58
+ function describeCall(name, args, baseURL) {
59
+ const [target, options] = args;
60
+ const rawUrl = typeof target === "string" ? target : call(target, "url") ?? String(target);
61
+ let method = name;
62
+ if (name === "fetch") {
63
+ const fromOptions = typeof options === "object" && options !== null ? options.method : void 0;
64
+ method = (typeof fromOptions === "string" ? fromOptions : void 0) ?? call(target, "method") ?? "GET";
65
+ }
66
+ method = method.toUpperCase();
67
+ if (!METHOD.test(method)) return void 0;
68
+ return { method, rawUrl, url: resolveUrl(rawUrl, baseURL) };
69
+ }
70
+ function isApiRequestContext(value) {
71
+ if (typeof value !== "object" || value === null) return false;
72
+ const target = value;
73
+ return ["fetch", "get", "post", "dispose", "storageState"].every(
74
+ (name) => typeof target[name] === "function"
75
+ );
76
+ }
77
+ function isPromise(value) {
78
+ return typeof value === "object" && value !== null && typeof value.then === "function";
79
+ }
80
+ function wrapRequestContext(context, source, baseURL, recorder) {
81
+ const wrapped = chunkVREOANPX_cjs.wrappedRequestContexts();
82
+ if (wrapped.has(context)) return false;
83
+ wrapped.add(context);
84
+ const target = context;
85
+ for (const name of API_METHODS) {
86
+ const original = target[name];
87
+ if (typeof original !== "function") continue;
88
+ const fn = original;
89
+ const wrapper = function(...args) {
90
+ const active = depth === 0 ? recorder() : void 0;
91
+ if (active === void 0) return fn.apply(this, args);
92
+ let described;
93
+ try {
94
+ described = describeCall(name, args, baseURL);
95
+ } catch {
96
+ described = void 0;
97
+ }
98
+ depth += 1;
99
+ let result;
100
+ try {
101
+ result = fn.apply(this, args);
102
+ } finally {
103
+ depth -= 1;
104
+ }
105
+ if (described === void 0 || !isPromise(result)) return result;
106
+ return active.observeApiCall(described, source, result);
107
+ };
108
+ Object.defineProperty(target, name, {
109
+ value: wrapper,
110
+ configurable: true,
111
+ enumerable: false,
112
+ writable: true
113
+ });
114
+ }
115
+ return true;
116
+ }
117
+
35
118
  // src/collector/perf-api.ts
36
- function createPerfApi(track) {
37
- return Object.freeze({ track });
119
+ function createPerfApi(track, trackRequestContext2 = () => {
120
+ }) {
121
+ return Object.freeze({ track, trackRequestContext: trackRequestContext2 });
38
122
  }
39
123
 
40
124
  // src/collector/constants.ts
@@ -122,13 +206,26 @@ function shouldTrack(req, measure) {
122
206
  if (req.resourceType !== "document" && hasIgnoredExtension(url, measure.ignoreExtensions)) {
123
207
  return false;
124
208
  }
125
- if (measure.include.length > 0 && !measure.include.some((pattern) => matchesUrlPattern(req.url, pattern))) {
209
+ return passesUrlFilters(req.url, url, measure);
210
+ }
211
+ function passesUrlFilters(text, url, measure) {
212
+ if (measure.include.length > 0 && !measure.include.some((pattern) => matchesUrlPattern(text, pattern))) {
126
213
  return false;
127
214
  }
128
- if (measure.exclude.some((pattern) => matchesUrlPattern(req.url, pattern))) return false;
215
+ if (measure.exclude.some((pattern) => matchesUrlPattern(text, pattern))) return false;
129
216
  if (measure.excludeKnownThirdParty && isKnownThirdPartyHost(url.hostname)) return false;
130
217
  return true;
131
218
  }
219
+ function shouldTrackApiCall(text, measure) {
220
+ let url;
221
+ try {
222
+ url = new URL(text);
223
+ } catch {
224
+ return false;
225
+ }
226
+ if (url.protocol !== "http:" && url.protocol !== "https:") return false;
227
+ return passesUrlFilters(text, url, measure);
228
+ }
132
229
 
133
230
  // src/collector/timing.ts
134
231
  function roundMs(x) {
@@ -167,6 +264,10 @@ var NO_TIMING = {
167
264
  responseStart: -1,
168
265
  responseEnd: -1
169
266
  };
267
+ var BODYLESS = /* @__PURE__ */ new Set([204, 205, 304]);
268
+ var ABORTED_AFTER_RESPONSE = new Set(
269
+ chunkVREOANPX_cjs.ABORT_FAILURE_TEXTS.filter((text) => text !== chunkVREOANPX_cjs.CONTEXT_CLOSED_FAILURE_TEXT)
270
+ );
170
271
  var RequestTracker = class {
171
272
  context;
172
273
  #opts;
@@ -270,11 +371,13 @@ var RequestTracker = class {
270
371
  (error) => this.#timingFailed(request, entry, error)
271
372
  );
272
373
  }
273
- #complete(request, entry, response, finishedAtNode) {
374
+ #complete(request, entry, response, finishedAtNode, headersEnd = false) {
274
375
  if (this.#inflight.get(request) !== entry) return;
275
376
  try {
276
377
  if (response === null) throw new Error("the request finished without a response");
277
- const timing = computeTiming(request.timing(), {
378
+ const raw = request.timing();
379
+ const ended = headersEnd && raw.responseEnd < 0 ? { ...raw, responseEnd: raw.responseStart } : raw;
380
+ const timing = computeTiming(ended, {
278
381
  startedAtNode: entry.startedAtNode,
279
382
  finishedAtNode
280
383
  });
@@ -303,6 +406,11 @@ var RequestTracker = class {
303
406
  const entry = this.#inflight.get(request);
304
407
  if (entry === void 0) return;
305
408
  const text = request.failure()?.errorText ?? "";
409
+ if (entry.response !== null && !entry.settling && (BODYLESS.has(entry.response.status()) || ABORTED_AFTER_RESPONSE.has(text))) {
410
+ entry.settling = true;
411
+ this.#complete(request, entry, entry.response, this.#opts.now(), true);
412
+ return;
413
+ }
306
414
  this.#settle(request);
307
415
  this.#sink.finished(
308
416
  failed(request, entry, text === "" ? "unknown" : text, safeTiming(request))
@@ -328,7 +436,7 @@ var RequestTracker = class {
328
436
  }
329
437
  #closedByClient(request, entry) {
330
438
  this.#settle(request);
331
- this.#sink.finished(failed(request, entry, chunkBAOTUUTV_cjs.CONTEXT_CLOSED_FAILURE_TEXT, safeTiming(request)));
439
+ this.#sink.finished(failed(request, entry, chunkVREOANPX_cjs.CONTEXT_CLOSED_FAILURE_TEXT, safeTiming(request)));
332
440
  }
333
441
  /** A request still in flight after the wait (05-REQ-13 step 4, 05-REQ-31). */
334
442
  #leftover(request, entry) {
@@ -420,6 +528,13 @@ function pageOf(request) {
420
528
  }
421
529
 
422
530
  // src/collector/test-collector.ts
531
+ function currentRecorder() {
532
+ return chunkVREOANPX_cjs.activeCollector();
533
+ }
534
+ function firstLine(error) {
535
+ const line = errorText(error).split("\n", 1)[0]?.trim() ?? "";
536
+ return line === "" ? "unknown" : line;
537
+ }
423
538
  var TestCollector = class {
424
539
  api;
425
540
  #opts;
@@ -427,6 +542,9 @@ var TestCollector = class {
427
542
  #trackers = /* @__PURE__ */ new Map();
428
543
  #requests = [];
429
544
  #pending = [];
545
+ #apiRequests = [];
546
+ #apiPending = [];
547
+ #apiInFlight = /* @__PURE__ */ new Set();
430
548
  #sink;
431
549
  #dropped = 0;
432
550
  #browserName;
@@ -435,24 +553,151 @@ var TestCollector = class {
435
553
  #draining;
436
554
  constructor(opts) {
437
555
  this.#opts = opts;
438
- this.api = createPerfApi((context) => {
439
- this.track(context);
556
+ this.api = createPerfApi(
557
+ (context) => {
558
+ this.track(context);
559
+ },
560
+ (requestContext) => {
561
+ this.trackRequestContext(requestContext);
562
+ }
563
+ );
564
+ this.#sink = {
565
+ finished: (sample) => this.#keep(this.#requests, sample),
566
+ pending: (sample) => this.#keep(this.#pending, sample)
567
+ };
568
+ }
569
+ /** The sample limit counts browser samples and API calls together (05-REQ-16, 15-REQ-09). */
570
+ #keep(list, sample) {
571
+ const count = this.#requests.length + this.#pending.length + this.#apiRequests.length + this.#apiPending.length;
572
+ if (count < SAMPLE_LIMIT_PER_TEST) list.push(sample);
573
+ else this.#dropped += 1;
574
+ }
575
+ /**
576
+ * Wraps an APIRequestContext of this test (15-REQ-03): the request fixture or context.request.
577
+ * Relative URLs resolve against the test's baseURL only for the request fixture and the context
578
+ * of the context fixture, which Playwright creates with that baseURL; any other context may have
579
+ * its own baseURL, so its calls take response.url() (15-REQ-05).
580
+ */
581
+ wrapRequest(requestContext, source, testBaseURL = source === "request") {
582
+ try {
583
+ wrapRequestContext(
584
+ requestContext,
585
+ source,
586
+ testBaseURL ? this.#opts.baseURL : void 0,
587
+ currentRecorder
588
+ );
589
+ } catch (error) {
590
+ this.#diag.add({
591
+ code: "COLLECTOR_LISTENER_ERROR",
592
+ message: `collector: wrapping an APIRequestContext failed, so its calls are not measured: ${errorText(error)}`,
593
+ hint: "Report this as a bug of the package; the test result is not affected."
594
+ });
595
+ }
596
+ }
597
+ /** perf.trackRequestContext() (15-REQ-03, 15-AC-07). */
598
+ trackRequestContext(requestContext) {
599
+ if (!isApiRequestContext(requestContext)) {
600
+ this.requestContextNotTracked();
601
+ return;
602
+ }
603
+ this.wrapRequest(requestContext, "tracked");
604
+ }
605
+ requestContextNotTracked() {
606
+ this.#diag.add({
607
+ code: "COLLECTOR_REQUEST_CONTEXT_NOT_TRACKED",
608
+ message: "collector: trackRequestContext() got an object that is not an APIRequestContext, so it is not measured",
609
+ hint: "Pass the object returned by playwright.request.newContext()."
440
610
  });
441
- const keep = (list, sample) => {
442
- if (this.#requests.length + this.#pending.length < SAMPLE_LIMIT_PER_TEST) list.push(sample);
443
- else this.#dropped += 1;
611
+ }
612
+ /**
613
+ * Records one APIRequestContext call (15-REQ-05): the returned promise settles like `result`
614
+ * (same value, same error); the sample is made when it settles or at the end-of-test wait.
615
+ */
616
+ observeApiCall(call2, source, result) {
617
+ if (this.#draining !== void 0) return result;
618
+ const startedAt = this.#opts.now();
619
+ const entry = {
620
+ call: call2,
621
+ source,
622
+ startTime: Math.round(this.#opts.wallNow()),
623
+ settled: Promise.resolve(),
624
+ done: false
444
625
  };
445
- this.#sink = {
446
- finished: (sample) => keep(this.#requests, sample),
447
- pending: (sample) => keep(this.#pending, sample)
626
+ const finish = (status, extra, responseUrl) => {
627
+ try {
628
+ if (entry.done) return;
629
+ entry.done = true;
630
+ this.#apiInFlight.delete(entry);
631
+ const sample = this.#apiSample(entry, status, responseUrl, extra);
632
+ if (sample !== null) this.#keep(this.#apiRequests, sample);
633
+ } catch (error) {
634
+ this.#diag.add({
635
+ code: "COLLECTOR_LISTENER_ERROR",
636
+ message: `collector: recording an APIRequestContext call failed: ${errorText(error)}`,
637
+ hint: "Report this as a bug of the package; the test result is not affected."
638
+ });
639
+ }
640
+ };
641
+ const out = result.then(
642
+ (response) => {
643
+ const duration = roundMs(this.#opts.now() - startedAt);
644
+ let status;
645
+ let url;
646
+ try {
647
+ const r = response;
648
+ const s = typeof r.status === "function" ? r.status() : void 0;
649
+ status = typeof s === "number" && Number.isInteger(s) && s >= 100 && s <= 599 ? s : void 0;
650
+ const u = typeof r.url === "function" ? r.url() : void 0;
651
+ url = typeof u === "string" && u !== "" ? u : void 0;
652
+ } catch {
653
+ status = void 0;
654
+ }
655
+ if (status === void 0) finish("FAILED", { failureText: "unknown", duration: null }, url);
656
+ else finish(status, { duration }, url);
657
+ return response;
658
+ },
659
+ (error) => {
660
+ finish("FAILED", { failureText: firstLine(error), duration: null });
661
+ throw error;
662
+ }
663
+ );
664
+ entry.settled = out.then(
665
+ () => void 0,
666
+ () => void 0
667
+ );
668
+ this.#apiInFlight.add(entry);
669
+ return out;
670
+ }
671
+ /** The sample of a call, or null when the filters skip its URL (15-REQ-06). */
672
+ #apiSample(entry, status, responseUrl, extra) {
673
+ const url = entry.call.url ?? responseUrl ?? entry.call.rawUrl;
674
+ if (url === "" || !shouldTrackApiCall(url, this.#opts.measure)) return null;
675
+ return {
676
+ method: entry.call.method,
677
+ url,
678
+ status,
679
+ ...status === "FAILED" ? { failureText: extra.failureText ?? "unknown" } : {},
680
+ startTime: entry.startTime,
681
+ duration: extra.duration ?? null,
682
+ source: entry.source
448
683
  };
449
684
  }
450
685
  /**
451
686
  * Attaches a tracker to `context` unless it already has one in this test (05-REQ-04) or the
452
- * test is draining. Returns true when a tracker was attached.
687
+ * test is draining. Returns true when a tracker was attached. `contextFixture`: the context of
688
+ * the context fixture, whose request calls resolve against the test's baseURL (15-REQ-05).
453
689
  */
454
- track(context) {
690
+ track(context, contextFixture = false) {
455
691
  if (this.#draining !== void 0 || this.#trackers.has(context)) return false;
692
+ let requestContext;
693
+ try {
694
+ requestContext = context.request;
695
+ } catch {
696
+ requestContext = void 0;
697
+ }
698
+ if (typeof requestContext === "object" && requestContext !== null) {
699
+ this.wrapRequest(requestContext, "context", contextFixture);
700
+ }
456
701
  try {
457
702
  this.#trackers.set(
458
703
  context,
@@ -506,8 +751,9 @@ var TestCollector = class {
506
751
  testTimeoutMs: this.#opts.testTimeout(),
507
752
  sinceTeardownStartMs: this.#opts.now() - (this.#teardownStart ?? this.#opts.now())
508
753
  });
509
- await Promise.all(
510
- [...this.#trackers.values()].map(async (tracker) => {
754
+ await Promise.all([
755
+ this.#drainApiCalls(budget),
756
+ ...[...this.#trackers.values()].map(async (tracker) => {
511
757
  try {
512
758
  await tracker.drain(budget);
513
759
  } catch (error) {
@@ -518,7 +764,35 @@ var TestCollector = class {
518
764
  });
519
765
  }
520
766
  })
521
- );
767
+ ]);
768
+ }
769
+ /** Waits for running API calls within the budget; the rest become PENDING (15-REQ-08). */
770
+ async #drainApiCalls(budget) {
771
+ if (this.#apiInFlight.size > 0) {
772
+ let timer;
773
+ const timeout = new Promise((resolve) => {
774
+ timer = setTimeout(resolve, Math.max(0, budget));
775
+ });
776
+ await Promise.race([
777
+ Promise.all([...this.#apiInFlight].map((entry) => entry.settled)),
778
+ timeout
779
+ ]);
780
+ clearTimeout(timer);
781
+ }
782
+ for (const entry of [...this.#apiInFlight]) {
783
+ entry.done = true;
784
+ this.#apiInFlight.delete(entry);
785
+ try {
786
+ const sample = this.#apiSample(entry, "PENDING", void 0, { duration: null });
787
+ if (sample !== null) this.#keep(this.#apiPending, sample);
788
+ } catch (error) {
789
+ this.#diag.add({
790
+ code: "COLLECTOR_LISTENER_ERROR",
791
+ message: `collector: recording an APIRequestContext call failed: ${errorText(error)}`,
792
+ hint: "Report this as a bug of the package; the test result is not affected."
793
+ });
794
+ }
795
+ }
522
796
  }
523
797
  /** The sample batch of the test (05-REQ-15); call after drain(). */
524
798
  batch() {
@@ -532,13 +806,14 @@ var TestCollector = class {
532
806
  this.#dropped = 0;
533
807
  }
534
808
  return {
535
- schemaVersion: 2,
809
+ schemaVersion: 3,
536
810
  collector: {
537
811
  name: COLLECTOR_NAME,
538
812
  version: this.#opts.version,
539
813
  browserName: this.#browserName ?? null
540
814
  },
541
815
  requests: [...this.#requests, ...this.#pending],
816
+ apiRequests: [...this.#apiRequests, ...this.#apiPending],
542
817
  diagnostics: this.#diag.list()
543
818
  };
544
819
  }
@@ -547,10 +822,10 @@ var TestCollector = class {
547
822
  try {
548
823
  await this.drain();
549
824
  const body = JSON.stringify(this.batch());
550
- await testInfo.attach(chunkBAOTUUTV_cjs.SAMPLES_ATTACHMENT_NAME, { body, contentType: "application/json" });
825
+ await testInfo.attach(chunkVREOANPX_cjs.SAMPLES_ATTACHMENT_NAME, { body, contentType: "application/json" });
551
826
  } catch (error) {
552
827
  process.stderr.write(
553
- `COLLECTOR_ATTACH_FAILED: ${chunkBAOTUUTV_cjs.SAMPLES_ATTACHMENT_NAME} could not be attached to the test result: ${errorText(error)}
828
+ `COLLECTOR_ATTACH_FAILED: ${chunkVREOANPX_cjs.SAMPLES_ATTACHMENT_NAME} could not be attached to the test result: ${errorText(error)}
554
829
  `
555
830
  );
556
831
  }
@@ -568,35 +843,36 @@ function engineOf(context) {
568
843
  var now = () => performance.now();
569
844
  var wallNow = () => Date.now();
570
845
  function perfModeOn() {
571
- const mode = chunkBAOTUUTV_cjs.readModeState(process.env);
572
- if (!mode.ok) throw new chunkBAOTUUTV_cjs.ConfigError(mode.issues);
846
+ const mode = chunkVREOANPX_cjs.readModeState(process.env);
847
+ if (!mode.ok) throw new chunkVREOANPX_cjs.ConfigError(mode.issues);
573
848
  return mode.value !== null;
574
849
  }
575
850
  var PASSIVE_API = createPerfApi(() => {
576
851
  });
577
- function openBuffer(browserName, testInfo) {
578
- const state = chunkBAOTUUTV_cjs.getRegistered();
579
- if (state !== void 0 && !state.measuredProjects.includes(testInfo.project.name)) {
852
+ function openBuffer(browserName, baseURL, testInfo) {
853
+ const state = chunkVREOANPX_cjs.getRegistered();
854
+ if (state !== void 0 && (!state.config.measure.api || !state.measuredProjects.includes(testInfo.project.name))) {
580
855
  return { collector: null, api: PASSIVE_API };
581
856
  }
582
857
  const collector = new TestCollector({
583
- measure: (state?.config ?? chunk2JO5HVPC_cjs.perfDefaults).measure,
584
- version: chunkBAOTUUTV_cjs.version,
858
+ measure: (state?.config ?? chunkW7NEFS5V_cjs.perfDefaults).measure,
859
+ version: chunkVREOANPX_cjs.version,
585
860
  browserName,
586
861
  testTimeout: () => testInfo.timeout,
862
+ baseURL,
587
863
  now,
588
864
  wallNow
589
865
  });
590
- for (const context of chunkBAOTUUTV_cjs.trackedContexts()) collector.track(context);
866
+ for (const context of chunkVREOANPX_cjs.trackedContexts()) collector.track(context);
591
867
  return { collector, api: collector.api };
592
868
  }
593
869
  function skipInCheck(testInfo) {
594
- const state = chunkBAOTUUTV_cjs.getRegistered();
870
+ const state = chunkVREOANPX_cjs.getRegistered();
595
871
  if (state === void 0 || state.mode.mode !== "check") return;
596
872
  if (!state.measuredProjects.includes(testInfo.project.name)) return;
597
- const max = state.mode.maxTests ?? chunkBAOTUUTV_cjs.DEFAULT_MAX_TESTS;
873
+ const max = state.mode.maxTests ?? chunkVREOANPX_cjs.DEFAULT_MAX_TESTS;
598
874
  if (!checkRunsTest(state.mode.runId, max, testInfo.project.name, testInfo.file)) {
599
- testInfo.skip(true, "pw-perf check: only the first test of each file runs");
875
+ testInfo.skip(true, "PW_PERF_MODE=check: only the first test of each file runs");
600
876
  }
601
877
  }
602
878
  var passiveFixtures = {
@@ -606,21 +882,21 @@ var passiveFixtures = {
606
882
  };
607
883
  var perfFixtures = {
608
884
  _perfBuffer: [
609
- async ({ browserName }, use, testInfo) => {
885
+ async ({ browserName, baseURL }, use, testInfo) => {
610
886
  skipInCheck(testInfo);
611
- const buffer = openBuffer(browserName ?? null, testInfo);
887
+ const buffer = openBuffer(browserName ?? null, baseURL, testInfo);
612
888
  const { collector } = buffer;
613
- if (collector !== null) chunkBAOTUUTV_cjs.setActiveCollector(collector);
889
+ if (collector !== null) chunkVREOANPX_cjs.setActiveCollector(collector);
614
890
  await use(buffer);
615
891
  if (collector === null) return;
616
- if (chunkBAOTUUTV_cjs.activeCollector() === collector) chunkBAOTUUTV_cjs.setActiveCollector(void 0);
892
+ if (chunkVREOANPX_cjs.activeCollector() === collector) chunkVREOANPX_cjs.setActiveCollector(void 0);
617
893
  collector.markTeardownStart();
618
894
  await collector.attach(testInfo);
619
895
  },
620
896
  { auto: true, box: true }
621
897
  ],
622
898
  context: async ({ context, _perfBuffer }, use) => {
623
- _perfBuffer.collector?.track(context);
899
+ _perfBuffer.collector?.track(context, true);
624
900
  await use(context);
625
901
  await _perfBuffer.collector?.drain();
626
902
  },
@@ -629,13 +905,18 @@ var perfFixtures = {
629
905
  await use(page);
630
906
  await _perfBuffer.collector?.drain();
631
907
  },
908
+ // The same object with its request methods measured (15-REQ-03); untouched without a collector.
909
+ request: async ({ request, _perfBuffer }, use) => {
910
+ _perfBuffer.collector?.wrapRequest(request, "request");
911
+ await use(request);
912
+ },
632
913
  perf: async ({ _perfBuffer }, use) => {
633
914
  await use(_perfBuffer.api);
634
915
  _perfBuffer.collector?.markTeardownStart();
635
916
  }
636
917
  };
637
918
  function withPerfFixtures(base2) {
638
- const wrapped = chunkBAOTUUTV_cjs.wrappedTests();
919
+ const wrapped = chunkVREOANPX_cjs.wrappedTests();
639
920
  if (wrapped.has(base2)) return base2;
640
921
  const extend = base2.extend;
641
922
  const result = extend.call(base2, perfModeOn() ? perfFixtures : passiveFixtures);
@@ -644,13 +925,24 @@ function withPerfFixtures(base2) {
644
925
  }
645
926
  function trackContext(context) {
646
927
  if (!perfModeOn()) return;
647
- const contexts = chunkBAOTUUTV_cjs.trackedContexts();
928
+ const contexts = chunkVREOANPX_cjs.trackedContexts();
648
929
  if (!contexts.has(context)) {
649
930
  contexts.add(context);
650
931
  context.once("close", () => contexts.delete(context));
651
932
  }
652
- chunkBAOTUUTV_cjs.activeCollector()?.track(context);
933
+ chunkVREOANPX_cjs.activeCollector()?.track(context);
934
+ }
935
+ function trackRequestContext(requestContext) {
936
+ if (!perfModeOn()) return;
937
+ const state = chunkVREOANPX_cjs.getRegistered();
938
+ if (state !== void 0 && !state.config.measure.api) return;
939
+ if (!isApiRequestContext(requestContext)) {
940
+ chunkVREOANPX_cjs.activeCollector()?.requestContextNotTracked();
941
+ return;
942
+ }
943
+ wrapRequestContext(requestContext, "tracked", void 0, chunkVREOANPX_cjs.activeCollector);
653
944
  }
654
945
 
655
946
  exports.trackContext = trackContext;
947
+ exports.trackRequestContext = trackRequestContext;
656
948
  exports.withPerfFixtures = withPerfFixtures;
@@ -53,6 +53,11 @@ function wrappedTests() {
53
53
  function trackedContexts() {
54
54
  return slot().trackedContexts;
55
55
  }
56
+ function wrappedRequestContexts() {
57
+ const registry = slot();
58
+ registry.wrappedRequestContexts ??= /* @__PURE__ */ new WeakSet();
59
+ return registry.wrappedRequestContexts;
60
+ }
56
61
  function activeCollector() {
57
62
  return slot().activeCollector;
58
63
  }
@@ -60,4 +65,4 @@ function setActiveCollector(collector) {
60
65
  slot().activeCollector = collector;
61
66
  }
62
67
 
63
- export { activeCollector, getRegistered, notWrappedWarning, setActiveCollector, setRegistered, trackedContexts, wrappedTests };
68
+ export { activeCollector, getRegistered, notWrappedWarning, setActiveCollector, setRegistered, trackedContexts, wrappedRequestContexts, wrappedTests };