@visual-check/cli 0.1.2 → 0.2.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 (211) hide show
  1. package/dist/addon-child/image-files.js +1 -1
  2. package/dist/addon-child/image-files.js.map +1 -1
  3. package/dist/agent-skill/skill-files.d.ts +4 -0
  4. package/dist/agent-skill/skill-files.d.ts.map +1 -1
  5. package/dist/agent-skill/skill-files.js +4 -0
  6. package/dist/agent-skill/skill-files.js.map +1 -1
  7. package/dist/baselines/baseline-error.d.ts +15 -2
  8. package/dist/baselines/baseline-error.d.ts.map +1 -1
  9. package/dist/baselines/baseline-error.js +32 -2
  10. package/dist/baselines/baseline-error.js.map +1 -1
  11. package/dist/capture/capture-session.d.ts +161 -30
  12. package/dist/capture/capture-session.d.ts.map +1 -1
  13. package/dist/capture/capture-session.js +263 -70
  14. package/dist/capture/capture-session.js.map +1 -1
  15. package/dist/capture/driver/cdp/cdp-page.d.ts.map +1 -1
  16. package/dist/capture/driver/cdp/cdp-page.js +120 -31
  17. package/dist/capture/driver/cdp/cdp-page.js.map +1 -1
  18. package/dist/capture/driver/cdp/failed-loads.d.ts +16 -0
  19. package/dist/capture/driver/cdp/failed-loads.d.ts.map +1 -0
  20. package/dist/capture/driver/cdp/failed-loads.js +71 -0
  21. package/dist/capture/driver/cdp/failed-loads.js.map +1 -0
  22. package/dist/capture/driver/cdp/launch-arguments.d.ts +7 -1
  23. package/dist/capture/driver/cdp/launch-arguments.d.ts.map +1 -1
  24. package/dist/capture/driver/cdp/launch-arguments.js +8 -1
  25. package/dist/capture/driver/cdp/launch-arguments.js.map +1 -1
  26. package/dist/capture/driver/driver.d.ts +88 -4
  27. package/dist/capture/driver/driver.d.ts.map +1 -1
  28. package/dist/capture/driver/driver.js +33 -0
  29. package/dist/capture/driver/driver.js.map +1 -1
  30. package/dist/capture/page-script.d.ts +7 -6
  31. package/dist/capture/page-script.d.ts.map +1 -1
  32. package/dist/capture/page-script.js +10 -9
  33. package/dist/capture/page-script.js.map +1 -1
  34. package/dist/capture/prepare-capture.d.ts +50 -3
  35. package/dist/capture/prepare-capture.d.ts.map +1 -1
  36. package/dist/capture/prepare-capture.js +157 -16
  37. package/dist/capture/prepare-capture.js.map +1 -1
  38. package/dist/commands/check-storybooks.d.ts +5 -4
  39. package/dist/commands/check-storybooks.d.ts.map +1 -1
  40. package/dist/commands/check-storybooks.js +11 -8
  41. package/dist/commands/check-storybooks.js.map +1 -1
  42. package/dist/commands/consistency-output.d.ts.map +1 -1
  43. package/dist/commands/consistency-output.js +3 -3
  44. package/dist/commands/consistency-output.js.map +1 -1
  45. package/dist/commands/failed-loads-hint.d.ts +7 -0
  46. package/dist/commands/failed-loads-hint.d.ts.map +1 -0
  47. package/dist/commands/failed-loads-hint.js +16 -0
  48. package/dist/commands/failed-loads-hint.js.map +1 -0
  49. package/dist/commands/local-update.d.ts +22 -0
  50. package/dist/commands/local-update.d.ts.map +1 -0
  51. package/dist/commands/local-update.js +39 -0
  52. package/dist/commands/local-update.js.map +1 -0
  53. package/dist/commands/network-warning.d.ts.map +1 -1
  54. package/dist/commands/network-warning.js +2 -18
  55. package/dist/commands/network-warning.js.map +1 -1
  56. package/dist/commands/plan-snapshots.d.ts +23 -8
  57. package/dist/commands/plan-snapshots.d.ts.map +1 -1
  58. package/dist/commands/plan-snapshots.js +15 -9
  59. package/dist/commands/plan-snapshots.js.map +1 -1
  60. package/dist/commands/report-entries.d.ts +5 -2
  61. package/dist/commands/report-entries.d.ts.map +1 -1
  62. package/dist/commands/report-entries.js +63 -15
  63. package/dist/commands/report-entries.js.map +1 -1
  64. package/dist/commands/run-browser.d.ts +5 -5
  65. package/dist/commands/run-browser.d.ts.map +1 -1
  66. package/dist/commands/run-browser.js +1 -0
  67. package/dist/commands/run-browser.js.map +1 -1
  68. package/dist/commands/run-cli.d.ts +16 -5
  69. package/dist/commands/run-cli.d.ts.map +1 -1
  70. package/dist/commands/run-cli.js +74 -54
  71. package/dist/commands/run-cli.js.map +1 -1
  72. package/dist/commands/run-report.d.ts +3 -3
  73. package/dist/commands/run-report.d.ts.map +1 -1
  74. package/dist/commands/run-report.js +4 -2
  75. package/dist/commands/run-report.js.map +1 -1
  76. package/dist/commands/run-snapshots.d.ts +7 -4
  77. package/dist/commands/run-snapshots.d.ts.map +1 -1
  78. package/dist/commands/run-snapshots.js +49 -17
  79. package/dist/commands/run-snapshots.js.map +1 -1
  80. package/dist/commands/snapshot-result.d.ts +66 -9
  81. package/dist/commands/snapshot-result.d.ts.map +1 -1
  82. package/dist/commands/snapshot-result.js +46 -6
  83. package/dist/commands/snapshot-result.js.map +1 -1
  84. package/dist/commands/stop-message.d.ts.map +1 -1
  85. package/dist/commands/stop-message.js +6 -1
  86. package/dist/commands/stop-message.js.map +1 -1
  87. package/dist/commands/stopped-run.d.ts +10 -5
  88. package/dist/commands/stopped-run.d.ts.map +1 -1
  89. package/dist/commands/stopped-run.js +35 -22
  90. package/dist/commands/stopped-run.js.map +1 -1
  91. package/dist/commands/take-snapshot.d.ts +9 -6
  92. package/dist/commands/take-snapshot.d.ts.map +1 -1
  93. package/dist/commands/take-snapshot.js +16 -7
  94. package/dist/commands/take-snapshot.js.map +1 -1
  95. package/dist/commands/test-snapshot.d.ts +2 -2
  96. package/dist/commands/test-snapshot.d.ts.map +1 -1
  97. package/dist/commands/test-snapshot.js.map +1 -1
  98. package/dist/commands/update-baselines.d.ts.map +1 -1
  99. package/dist/commands/update-baselines.js +3 -2
  100. package/dist/commands/update-baselines.js.map +1 -1
  101. package/dist/commands/update-snapshot.d.ts +22 -4
  102. package/dist/commands/update-snapshot.d.ts.map +1 -1
  103. package/dist/commands/update-snapshot.js +79 -18
  104. package/dist/commands/update-snapshot.js.map +1 -1
  105. package/dist/config/checks.d.ts +26 -0
  106. package/dist/config/checks.d.ts.map +1 -1
  107. package/dist/config/checks.js +68 -6
  108. package/dist/config/checks.js.map +1 -1
  109. package/dist/config/define-config.d.ts +38 -2
  110. package/dist/config/define-config.d.ts.map +1 -1
  111. package/dist/config/define-config.js.map +1 -1
  112. package/dist/config/resolve-config.d.ts +15 -2
  113. package/dist/config/resolve-config.d.ts.map +1 -1
  114. package/dist/config/resolve-config.js +6 -0
  115. package/dist/config/resolve-config.js.map +1 -1
  116. package/dist/config/story-options.d.ts +32 -4
  117. package/dist/config/story-options.d.ts.map +1 -1
  118. package/dist/config/story-options.js +38 -7
  119. package/dist/config/story-options.js.map +1 -1
  120. package/dist/config/unrunnable-regexp.d.ts +22 -0
  121. package/dist/config/unrunnable-regexp.d.ts.map +1 -0
  122. package/dist/config/unrunnable-regexp.js +25 -0
  123. package/dist/config/unrunnable-regexp.js.map +1 -0
  124. package/dist/config/validate-config.d.ts.map +1 -1
  125. package/dist/config/validate-config.js +6 -21
  126. package/dist/config/validate-config.js.map +1 -1
  127. package/dist/index.d.ts +3 -3
  128. package/dist/index.d.ts.map +1 -1
  129. package/dist/index.js.map +1 -1
  130. package/dist/init/find-storybooks.d.ts +5 -0
  131. package/dist/init/find-storybooks.d.ts.map +1 -1
  132. package/dist/init/find-storybooks.js +8 -1
  133. package/dist/init/find-storybooks.js.map +1 -1
  134. package/dist/init/ignored-skill.d.ts +50 -0
  135. package/dist/init/ignored-skill.d.ts.map +1 -0
  136. package/dist/init/ignored-skill.js +61 -0
  137. package/dist/init/ignored-skill.js.map +1 -0
  138. package/dist/init/install.d.ts +24 -9
  139. package/dist/init/install.d.ts.map +1 -1
  140. package/dist/init/install.js +66 -26
  141. package/dist/init/install.js.map +1 -1
  142. package/dist/init/package-manager.d.ts +6 -0
  143. package/dist/init/package-manager.d.ts.map +1 -1
  144. package/dist/init/package-manager.js +4 -0
  145. package/dist/init/package-manager.js.map +1 -1
  146. package/dist/init/run-init.d.ts +17 -4
  147. package/dist/init/run-init.d.ts.map +1 -1
  148. package/dist/init/run-init.js +31 -11
  149. package/dist/init/run-init.js.map +1 -1
  150. package/dist/init/workspace.d.ts +2 -0
  151. package/dist/init/workspace.d.ts.map +1 -1
  152. package/dist/init/workspace.js +2 -0
  153. package/dist/init/workspace.js.map +1 -1
  154. package/dist/page-errors/judge-page-errors.d.ts +50 -0
  155. package/dist/page-errors/judge-page-errors.d.ts.map +1 -0
  156. package/dist/page-errors/judge-page-errors.js +39 -0
  157. package/dist/page-errors/judge-page-errors.js.map +1 -0
  158. package/dist/page-errors/page-error-policy.d.ts +36 -0
  159. package/dist/page-errors/page-error-policy.d.ts.map +1 -0
  160. package/dist/page-errors/page-error-policy.js +15 -0
  161. package/dist/page-errors/page-error-policy.js.map +1 -0
  162. package/dist/real-network-requests/judge-real-requests.d.ts +26 -0
  163. package/dist/real-network-requests/judge-real-requests.d.ts.map +1 -0
  164. package/dist/real-network-requests/judge-real-requests.js +17 -0
  165. package/dist/real-network-requests/judge-real-requests.js.map +1 -0
  166. package/dist/real-network-requests/real-request-policy.d.ts +29 -0
  167. package/dist/real-network-requests/real-request-policy.d.ts.map +1 -0
  168. package/dist/real-network-requests/real-request-policy.js +10 -0
  169. package/dist/real-network-requests/real-request-policy.js.map +1 -0
  170. package/dist/real-network-requests/silenced-hosts.d.ts +9 -0
  171. package/dist/real-network-requests/silenced-hosts.d.ts.map +1 -0
  172. package/dist/real-network-requests/silenced-hosts.js +28 -0
  173. package/dist/real-network-requests/silenced-hosts.js.map +1 -0
  174. package/dist/report/report-document.d.ts +154 -9
  175. package/dist/report/report-document.d.ts.map +1 -1
  176. package/dist/report/report-document.js +1 -1
  177. package/dist/report/report-document.js.map +1 -1
  178. package/dist/report/report-folder.d.ts +7 -3
  179. package/dist/report/report-folder.d.ts.map +1 -1
  180. package/dist/report/report-folder.js +5 -5
  181. package/dist/report/report-folder.js.map +1 -1
  182. package/dist/reporter/end-block.d.ts +32 -3
  183. package/dist/reporter/end-block.d.ts.map +1 -1
  184. package/dist/reporter/end-block.js +55 -3
  185. package/dist/reporter/end-block.js.map +1 -1
  186. package/dist/reporter/page-errors-block.d.ts +52 -0
  187. package/dist/reporter/page-errors-block.d.ts.map +1 -0
  188. package/dist/reporter/page-errors-block.js +98 -0
  189. package/dist/reporter/page-errors-block.js.map +1 -0
  190. package/dist/reporter/real-requests-block.d.ts +33 -0
  191. package/dist/reporter/real-requests-block.d.ts.map +1 -0
  192. package/dist/reporter/real-requests-block.js +53 -0
  193. package/dist/reporter/real-requests-block.js.map +1 -0
  194. package/dist/step-summary/step-summary.d.ts +27 -7
  195. package/dist/step-summary/step-summary.d.ts.map +1 -1
  196. package/dist/step-summary/step-summary.js +107 -15
  197. package/dist/step-summary/step-summary.js.map +1 -1
  198. package/dist/storybook/options-encoding.d.ts +18 -5
  199. package/dist/storybook/options-encoding.d.ts.map +1 -1
  200. package/dist/storybook/options-encoding.js +12 -4
  201. package/dist/storybook/options-encoding.js.map +1 -1
  202. package/dist/storybook/options-read.d.ts +3 -2
  203. package/dist/storybook/options-read.d.ts.map +1 -1
  204. package/dist/storybook/options-read.js +17 -0
  205. package/dist/storybook/options-read.js.map +1 -1
  206. package/dist/storybook/read-stories.d.ts +15 -0
  207. package/dist/storybook/read-stories.d.ts.map +1 -1
  208. package/dist/storybook/read-stories.js +60 -14
  209. package/dist/storybook/read-stories.js.map +1 -1
  210. package/package.json +2 -1
  211. package/skill/SKILL.md +25 -7
@@ -1,7 +1,7 @@
1
1
  import { readStoryWait, storyWaitExpression } from '../storybook/preview-script.js';
2
2
  import { testPathUserAgentSuffix } from '../storybook/test-path.js';
3
3
  import { readWaitHookRun, waitHookExpression } from '../storybook/wait-hook.js';
4
- import { BrowserExitedError, CaptureTooLargeError, maxCaptureSide, PageCrashedError, PageNavigatedAwayError, PageTimeoutError, } from './driver/driver.js';
4
+ import { BrowserExitedError, CaptureTooLargeError, eachPageErrorOnce, maxCaptureSide, PageCrashedError, PageNavigatedAwayError, PageTimeoutError, } from './driver/driver.js';
5
5
  import { readEndState } from './end-state.js';
6
6
  import { assetsReadyExpression, endStateExpression, framesAfterGrowthExpression, pageInitScript, prepareCaptureExpression, readAssetsReadiness, readFramesPassed, } from './page-script.js';
7
7
  import { readCapturePrep, } from './prepare-capture.js';
@@ -16,6 +16,13 @@ export const waitMarginMs = 1_000;
16
16
  * @public
17
17
  */
18
18
  export const brokenImageTimeLimitMs = 5_000;
19
+ /**
20
+ * What the page reacts to in each wait for frames, as the messages name it.
21
+ */
22
+ const framesTargets = {
23
+ 'frames-after-grow': 'the grown viewport',
24
+ 'frames-after-regrow': 'the viewport set again after its wait hook',
25
+ };
19
26
  /**
20
27
  * What each step does, as a phrase that follows "while".
21
28
  */
@@ -29,6 +36,9 @@ const stepNames = {
29
36
  'assets-after-grow': 'waiting for images and fonts after growing the viewport',
30
37
  wait: "running the story's wait hook",
31
38
  'assets-after-wait': 'waiting for images and fonts after its wait hook',
39
+ 'regrow-viewport': 'growing the viewport to the page again after its wait hook',
40
+ 'frames-after-regrow': 'letting the page react to the viewport set again after its wait hook',
41
+ 'assets-after-regrow': 'waiting for images and fonts once the viewport was set again after its wait hook',
32
42
  'end-state': 'bringing the story to its end state',
33
43
  'assets-after-end-state': 'waiting for images and fonts after its end state',
34
44
  masks: 'painting its masks and hiding the caret',
@@ -46,6 +56,8 @@ const stepTimeouts = {
46
56
  'assets-after-grow': 'its page stopped answering while visual-check waited for its images and fonts after growing the viewport',
47
57
  wait: 'its page stopped answering while its wait hook ran',
48
58
  'assets-after-wait': 'its page stopped answering while visual-check waited for its images and fonts after its wait hook',
59
+ 'frames-after-regrow': 'its page stopped answering while visual-check let it react to the viewport set again after its wait hook',
60
+ 'assets-after-regrow': 'its page stopped answering while visual-check waited for its images and fonts once the viewport was set again after its wait hook',
49
61
  'end-state': 'its page stopped answering while visual-check brought it to its end state',
50
62
  'assets-after-end-state': 'its page stopped answering while visual-check waited for its images and fonts after its end state',
51
63
  masks: 'its page stopped answering while visual-check painted its masks and hid the caret',
@@ -57,6 +69,7 @@ const assetsCheckSuffixes = {
57
69
  assets: '',
58
70
  'assets-after-grow': ' after growing the viewport',
59
71
  'assets-after-wait': ' after its wait hook',
72
+ 'assets-after-regrow': ' once the viewport was set again after its wait hook',
60
73
  'assets-after-end-state': ' after its end state',
61
74
  };
62
75
  /**
@@ -67,13 +80,52 @@ const endStateTimeouts = {
67
80
  media: 'visual-check was still putting its media on their first frame',
68
81
  };
69
82
  /**
70
- * Gives a story that wasn't ready within readyTimeout, saying what it was doing.
83
+ * Gives the broken story with the loads of Storybook's own files that failed at the network level on its page, and a
84
+ * sentence at the end of its message naming the first, its path shown against the story's URL, and how many there were
85
+ * when more than one. A `play-threw` story whose error Storybook described as nothing keeps the message without that
86
+ * sentence as its error text, for the report's play details. Gives it as it is when none failed.
87
+ */
88
+ function withFailedLoads(broken, failedLoads, storyUrl) {
89
+ const [first] = failedLoads;
90
+ if (first === undefined) {
91
+ return broken;
92
+ }
93
+ const path = displayUrlOf(first.url, storyUrl);
94
+ const files = failedLoads.length === 1
95
+ ? `${path} from Storybook`
96
+ : `${failedLoads.length} files from Storybook, the first ${path}`;
97
+ return {
98
+ ...broken,
99
+ ...(broken.reason === 'play-threw' && broken.errorText === '' ? { errorText: broken.message } : {}),
100
+ message: `${broken.message} Its page couldn't load ${files}: ${first.error}.`,
101
+ failedLoads,
102
+ };
103
+ }
104
+ /**
105
+ * Gives the readyTimeout a story's capture runs under: the story's own when it sets one, else the settings'.
106
+ */
107
+ function readyTimeoutOf(story, settings) {
108
+ if (story.readyTimeoutMs === undefined) {
109
+ return { ms: settings.readyTimeoutMs, setIn: 'config' };
110
+ }
111
+ return { ms: story.readyTimeoutMs, setIn: 'story' };
112
+ }
113
+ /**
114
+ * Names a readyTimeout in a message: how long it is and where it was set.
115
+ */
116
+ function readyTimeoutText({ ms, setIn }) {
117
+ const where = setIn === 'story' ? "the story's parameters.visualCheck" : 'the config';
118
+ return `readyTimeout (${ms} ms, from ${where})`;
119
+ }
120
+ /**
121
+ * Gives a story that wasn't ready within its readyTimeout, saying what it was doing.
71
122
  */
72
- function notReady(readyTimeoutMs, doing) {
123
+ function notReady(readyTimeout, doing) {
73
124
  return {
74
125
  reason: 'timeout',
75
- message: `The story wasn't ready within readyTimeout (${readyTimeoutMs} ms): ${doing}.`,
76
- readyTimeoutMs,
126
+ message: `The story wasn't ready within ${readyTimeoutText(readyTimeout)}: ${doing}.`,
127
+ readyTimeoutMs: readyTimeout.ms,
128
+ readyTimeoutSetIn: readyTimeout.setIn,
77
129
  };
78
130
  }
79
131
  /**
@@ -118,14 +170,14 @@ function stillWaitingFor(wait) {
118
170
  /**
119
171
  * Says why a story isn't ready to capture, from what the story wait found.
120
172
  */
121
- function describeStoryWait(wait, readyTimeoutMs) {
173
+ function describeStoryWait(wait, readyTimeout) {
122
174
  switch (wait.outcome) {
123
175
  case 'play-threw':
124
176
  return { reason: 'play-threw', message: wait.message, errorText: wait.errorText, stack: wait.stack };
125
177
  case 'errored':
126
178
  return { reason: 'error', message: wait.message };
127
179
  case 'timed-out':
128
- return notReady(readyTimeoutMs, stillWaitingFor(wait));
180
+ return notReady(readyTimeout, stillWaitingFor(wait));
129
181
  case 'script-missing':
130
182
  return {
131
183
  reason: 'error',
@@ -146,7 +198,7 @@ function imagesStillLoading(pending) {
146
198
  * Says why a story isn't ready to capture, from what a check of its images and fonts found. `suffix` follows what the
147
199
  * message says the story was doing, so it names the check.
148
200
  */
149
- function describeAssetsWait(assets, readyTimeoutMs, suffix) {
201
+ function describeAssetsWait(assets, readyTimeout, suffix) {
150
202
  if (assets.outcome === 'script-missing') {
151
203
  return {
152
204
  reason: 'error',
@@ -154,47 +206,49 @@ function describeAssetsWait(assets, readyTimeoutMs, suffix) {
154
206
  };
155
207
  }
156
208
  if (assets.step === 'images') {
157
- return notReady(readyTimeoutMs, `${imagesStillLoading(assets.pending)}${suffix}`);
209
+ return notReady(readyTimeout, `${imagesStillLoading(assets.pending)}${suffix}`);
158
210
  }
159
211
  const faces = assets.pendingFaces;
160
212
  if (faces.length === 0) {
161
- return notReady(readyTimeoutMs, `document.fonts.ready hadn't resolved${suffix}`);
213
+ return notReady(readyTimeout, `document.fonts.ready hadn't resolved${suffix}`);
162
214
  }
163
215
  return {
164
216
  reason: 'fonts-not-loaded',
165
- message: `The story's fonts hadn't loaded within readyTimeout (${readyTimeoutMs} ms)${suffix}. Still loading: ${faces.join(', ')}.`,
217
+ message: `The story's fonts hadn't loaded within ${readyTimeoutText(readyTimeout)}${suffix}. Still loading: ${faces.join(', ')}.`,
166
218
  faces,
167
- readyTimeoutMs,
219
+ readyTimeoutMs: readyTimeout.ms,
220
+ readyTimeoutSetIn: readyTimeout.setIn,
168
221
  };
169
222
  }
170
223
  /**
171
- * Says why a story isn't ready to capture, from what letting frames pass once the viewport grew found.
224
+ * Says why a story isn't ready to capture, from what letting frames pass found in the wait `framesStep` names: once the
225
+ * viewport grew, or once it was set again after the wait hook.
172
226
  */
173
- function describeFramesAfterGrowth(frames, readyTimeoutMs) {
227
+ function describeFrames(frames, readyTimeout, framesStep) {
174
228
  if (frames.outcome === 'script-missing') {
175
229
  return {
176
230
  reason: 'error',
177
- message: "visual-check's page script didn't run in the story's page, so it couldn't let the page react to the grown viewport.",
231
+ message: `visual-check's page script didn't run in the story's page, so it couldn't let the page react to ${framesTargets[framesStep]}.`,
178
232
  };
179
233
  }
180
- return notReady(readyTimeoutMs, 'visual-check was still letting the page react to the grown viewport');
234
+ return notReady(readyTimeout, `visual-check was still letting the page react to ${framesTargets[framesStep]}`);
181
235
  }
182
236
  /**
183
237
  * Says why a story isn't ready to capture, from what bringing it to its end state found.
184
238
  */
185
- function describeEndState(endState, readyTimeoutMs) {
239
+ function describeEndState(endState, readyTimeout) {
186
240
  if (endState.outcome === 'script-missing') {
187
241
  return {
188
242
  reason: 'error',
189
243
  message: "visual-check's page script didn't run in the story's page, so it couldn't bring it to its end state.",
190
244
  };
191
245
  }
192
- return notReady(readyTimeoutMs, endStateTimeouts[endState.step]);
246
+ return notReady(readyTimeout, endStateTimeouts[endState.step]);
193
247
  }
194
248
  /**
195
249
  * Says why a story can't be captured, from what preparing its capture found. `element` is the story's element selector.
196
250
  */
197
- function describeCapturePrep(prep, element, readyTimeoutMs) {
251
+ function describeCapturePrep(prep, element, readyTimeout) {
198
252
  switch (prep.outcome) {
199
253
  case 'element-missing':
200
254
  return {
@@ -211,7 +265,7 @@ function describeCapturePrep(prep, element, readyTimeoutMs) {
211
265
  : `The selector of mask ${JSON.stringify(prep.name)} isn't valid CSS: ${failureReasonOf(prep.message)}`,
212
266
  };
213
267
  case 'timed-out':
214
- return notReady(readyTimeoutMs, 'visual-check was still looking for remote content to mask');
268
+ return notReady(readyTimeout, 'visual-check was still looking for remote content to mask');
215
269
  case 'script-missing':
216
270
  return {
217
271
  reason: 'error',
@@ -227,14 +281,14 @@ function describeCapturePrep(prep, element, readyTimeoutMs) {
227
281
  /**
228
282
  * Says why a story isn't ready to capture, from what running its wait hook found.
229
283
  */
230
- function describeWaitHookRun(run, readyTimeoutMs) {
284
+ function describeWaitHookRun(run, readyTimeout) {
231
285
  switch (run.outcome) {
232
286
  case 'threw':
233
287
  return { reason: 'wait-threw', message: run.message };
234
288
  case 'context-failed':
235
289
  return { reason: 'error', message: run.message };
236
290
  case 'timed-out':
237
- return notReady(readyTimeoutMs, "its wait hook hadn't finished");
291
+ return notReady(readyTimeout, "its wait hook hadn't finished");
238
292
  case 'no-render':
239
293
  return {
240
294
  reason: 'error',
@@ -253,7 +307,7 @@ function describeWaitHookRun(run, readyTimeoutMs) {
253
307
  * capture: the hint says to set `element` for the full page, or to capture a smaller element. `story` shows a URL on
254
308
  * the story's own origin as a path.
255
309
  */
256
- function describeFailure(error, step, story, readyTimeoutMs) {
310
+ function describeFailure(error, step, story, readyTimeout) {
257
311
  if (error instanceof PageCrashedError) {
258
312
  return {
259
313
  reason: 'crashed',
@@ -277,7 +331,7 @@ function describeFailure(error, step, story, readyTimeoutMs) {
277
331
  }
278
332
  const doing = stepTimeouts[step];
279
333
  if (error instanceof PageTimeoutError && doing !== undefined) {
280
- return notReady(readyTimeoutMs, doing);
334
+ return notReady(readyTimeout, doing);
281
335
  }
282
336
  const name = stepNames[step];
283
337
  return {
@@ -356,6 +410,63 @@ export function gridProblemOf(grid, viewport) {
356
410
  size: { width: deviceWidth, height: deviceHeight },
357
411
  };
358
412
  }
413
+ /**
414
+ * Says how far content reaches past each edge that counts, such as `12 px past the page's top edge`, from pairs of a
415
+ * distance in CSS pixels and an edge. An edge whose distance is 0 doesn't count.
416
+ */
417
+ function edgePhrasesOf(edges) {
418
+ return edges.filter(([distance]) => distance > 0).map(([distance, edge]) => `${distance} px past ${edge}`);
419
+ }
420
+ /**
421
+ * Says how far an element's capture would cut content, as a sentence of at most two clauses: first the element past
422
+ * the page's top and left edges, then its content past its right and bottom edges, each clause naming only the sides
423
+ * that count. The content's clause names the element when it comes first. Two clauses are joined with `, and` when
424
+ * either names two sides, and with `and` otherwise.
425
+ */
426
+ function elementOverflowSentenceOf({ top, right, bottom, left }) {
427
+ const pageEdges = edgePhrasesOf([
428
+ [top, "the page's top edge"],
429
+ [left, top > 0 ? 'its left edge' : "the page's left edge"],
430
+ ]);
431
+ const contentEdges = edgePhrasesOf([
432
+ [right, 'its right edge'],
433
+ [bottom, 'its bottom edge'],
434
+ ]);
435
+ const contentSubject = pageEdges.length > 0 ? 'its content' : "the element's content";
436
+ const clauses = [
437
+ { subject: 'the element', edges: pageEdges },
438
+ { subject: contentSubject, edges: contentEdges },
439
+ ]
440
+ .filter(({ edges }) => edges.length > 0)
441
+ .map(({ subject, edges }) => `${subject} reaches ${edges.join(' and ')}`);
442
+ const sentence = clauses.join(pageEdges.length > 1 || contentEdges.length > 1 ? ', and ' : ' and ');
443
+ return `${sentence.charAt(0).toUpperCase()}${sentence.slice(1)}`;
444
+ }
445
+ /**
446
+ * Says why a story whose capture would cut content its page shows can't be captured, or gives nothing when it would cut
447
+ * nothing or the story sets `allowOverflow: true`. For the full page, it names how far content reaches past the
448
+ * viewport's right edge; for an element's box, each side that counts. `area` is what the capture takes, and the
449
+ * story's viewport is the snapshot's: its mode's when it has one.
450
+ */
451
+ export function overflowProblemOf(overflow, area, story) {
452
+ if (overflow === undefined || story.allowOverflow === true) {
453
+ return undefined;
454
+ }
455
+ const viewportWidth = story.viewport.width;
456
+ const { top, right, bottom, left } = overflow;
457
+ if (area === 'full-page') {
458
+ return {
459
+ reason: 'overflows',
460
+ message: `Content reaches ${right} px past the right edge of the ${viewportWidth} px viewport, so the capture would cut it. Fix the layout, give the story a wider viewport or list modes without the narrow ones, or set allowOverflow when the cut is intended.`,
461
+ overflow: { area: 'full-page', top, right, bottom, left, viewportWidth },
462
+ };
463
+ }
464
+ return {
465
+ reason: 'overflows',
466
+ message: `${elementOverflowSentenceOf(overflow)}, so the capture would cut it. Fix the layout, capture an element that holds the content, or set allowOverflow when the cut is intended.`,
467
+ overflow: { area: 'element', top, right, bottom, left, viewportWidth },
468
+ };
469
+ }
359
470
  /**
360
471
  * What a snapshot comes with besides its bytes, read right after the capture: the remote content it shows, in pixels
361
472
  * of its image, when the story asked for it with `findRemoteContent` and the page gave it, and the hosts the story
@@ -373,33 +484,50 @@ function capturedExtrasOf(page, story, settings, prepared) {
373
484
  ...(hosts === undefined ? {} : { hosts }),
374
485
  };
375
486
  }
487
+ /**
488
+ * What an attempt reads of its page's loads once it's done: the page errors, and the hosts of the real network requests
489
+ * when the story asks for them with `watchRequests`.
490
+ */
491
+ function loadsReadOf(page, story) {
492
+ return {
493
+ pageErrors: page.pageErrors(),
494
+ ...(story.watchRequests === true ? { requestHosts: page.requestHosts() } : {}),
495
+ };
496
+ }
376
497
  /**
377
498
  * Captures a story on an open page: sets the story's viewport, loads the story, waits until Storybook reports it
378
499
  * finished with nothing gone wrong, waits for its images and fonts, grows the viewport to the page for a full-page
379
- * capture, runs its wait hook, brings it to its end state, measures its element, paints its masks, hides the caret and
380
- * captures the element's box, or the full page when the story has no element. When the viewport grew, two frames pass
381
- * so the page reacts to the new size, then its images and fonts are checked again, when the story has a wait hook,
382
- * they're checked again after it, and when the end state changed anything, they're checked again before the masks.
383
- * Loading, the waits, the frames, the hook, the end state, those checks and the masks share readyTimeout, each getting
384
- * only what's left of it. When the story asks for it with `findRemoteContent`, the snapshot comes with the remote content it shows, unless the search didn't answer in time.
500
+ * capture, runs its wait hook, measures the page again for a full-page capture once its wait hook ran, brings it to its
501
+ * end state, measures its element, paints its masks, hides the caret and captures the element's box, or the full page
502
+ * when the story has no element. When the viewport grew, two frames pass so the page reacts to the new size, then its
503
+ * images and fonts are checked again. When the story's wait hook ran, they're checked again after it, then, for a
504
+ * full-page capture, the story's viewport is set again and grows to the page, two frames pass whether it grew or not,
505
+ * and they're checked again. When the end state changed anything, they're checked again before the masks.
506
+ * Loading, the waits, the frames, the hook, the end state, those checks and the masks share readyTimeout, the story's
507
+ * own when it sets `readyTimeoutMs` and the settings' otherwise, each getting only what's left of it. When the story asks for it with `findRemoteContent`, the snapshot comes with the remote content it shows, unless the search didn't answer in time.
385
508
  * When the settings ask to list hosts, it also gives the hosts the page sent requests to, read once the capture is
386
509
  * done, and the hosts of the remote content the story shows, from the same search as the host masks. A story whose page
387
510
  * shows a grid wider than the viewport, or too tall to capture, is broken before anything is captured, as
388
- * `gridProblemOf` says. Gives the area the snapshot was captured from beside it, and leaves the story's
389
- * `captureAgainIf` to the caller. A story that can't be captured comes back as a broken story. Either way it comes with
511
+ * `gridProblemOf` says. Then one whose capture would cut content its page shows is broken, as `overflowProblemOf` says,
512
+ * unless it sets `allowOverflow: true`; a capture too tall is only found as it's taken, after that. Gives the area the
513
+ * snapshot was captured from beside it, and leaves the story's `captureAgainIf` to the caller. A story that can't be captured comes back as a broken story. Either way it comes with
390
514
  * the console messages and errors the page sent, read once the capture is done or the story broke, while the page is
391
- * still open. Rejects only with a `BrowserExitedError`.
515
+ * still open, and a broken story with the loads of Storybook's files that failed on the page and its page errors. A
516
+ * snapshot's page errors are left to the caller, read once `captureAgainIf` ran. Rejects only with a
517
+ * `BrowserExitedError`.
392
518
  */
393
519
  async function captureOnPage(page, story, settings) {
394
- const deadline = performance.now() + settings.readyTimeoutMs;
520
+ const readyTimeout = readyTimeoutOf(story, settings);
521
+ const deadline = performance.now() + readyTimeout.ms;
395
522
  const timeLeft = () => Math.max(0, Math.ceil(deadline - performance.now()));
396
523
  let step = 'viewport';
397
524
  /**
398
- * Gives the broken story with the messages the page sent.
525
+ * Gives the broken story with the messages the page sent and the loads of Storybook's files that failed on it.
399
526
  */
400
527
  const brokenBy = (broken) => ({
401
- broken,
528
+ broken: withFailedLoads(broken, page.failedLoads(), story.url),
402
529
  console: page.consoleMessages(),
530
+ ...loadsReadOf(page, story),
403
531
  });
404
532
  /**
405
533
  * Evaluates a wait in the page, built by `expressionFor` for what's left of readyTimeout, and gives the page's
@@ -419,16 +547,22 @@ async function captureOnPage(page, story, settings) {
419
547
  if (assets.outcome === 'ready') {
420
548
  return undefined;
421
549
  }
422
- return describeAssetsWait(assets, settings.readyTimeoutMs, assetsCheckSuffixes[assetsStep]);
550
+ return describeAssetsWait(assets, readyTimeout, assetsCheckSuffixes[assetsStep]);
423
551
  };
424
552
  /**
425
- * Lets two frames pass once the viewport grew, so the page reacts to the new size: its observers and `resize`
426
- * listeners call back and the render they cause is done. Gives why the story isn't ready, or nothing when it is.
553
+ * Whether the capture is of the full page with the viewport's growth on: the viewport grows to the page before the
554
+ * wait hook and is measured again after a hook that ran.
555
+ */
556
+ const growsViewport = story.element === undefined && story.growViewport !== false;
557
+ /**
558
+ * Lets two frames pass once the viewport grew or was set again, as `framesStep` names, so the page reacts to its
559
+ * size: its observers and `resize` listeners call back and the render they cause is done. Gives why the story isn't
560
+ * ready, or nothing when it is.
427
561
  */
428
- const letPageReactToGrowth = async () => {
429
- step = 'frames-after-grow';
562
+ const letPageReact = async (framesStep) => {
563
+ step = framesStep;
430
564
  const frames = readFramesPassed(await waitInPage(framesAfterGrowthExpression));
431
- return frames.outcome === 'passed' ? undefined : describeFramesAfterGrowth(frames, settings.readyTimeoutMs);
565
+ return frames.outcome === 'passed' ? undefined : describeFrames(frames, readyTimeout, framesStep);
432
566
  };
433
567
  /**
434
568
  * Grows the viewport's height to the page's for a full-page capture, unless the story turns that off. When it grew,
@@ -436,18 +570,35 @@ async function captureOnPage(page, story, settings) {
436
570
  * nothing when it is.
437
571
  */
438
572
  const growViewport = async () => {
439
- if (story.element !== undefined || story.growViewport === false) {
573
+ if (!growsViewport) {
440
574
  return undefined;
441
575
  }
442
576
  step = 'grow-viewport';
443
577
  if (!(await page.growViewportToContent())) {
444
578
  return undefined;
445
579
  }
446
- return (await letPageReactToGrowth()) ?? (await checkAssets('assets-after-grow'));
580
+ return (await letPageReact('frames-after-grow')) ?? (await checkAssets('assets-after-grow'));
581
+ };
582
+ /**
583
+ * Measures the page again once the story's wait hook ran, for a full-page capture with the growth on: sets the
584
+ * story's own viewport again, so a `min-height: 100vh` page doesn't keep its last growth, and grows it to the
585
+ * page's height when the page is taller. A page the hook made shorter shrinks back, and one too tall to capture
586
+ * stays at the story's viewport. Then lets two frames pass, whether it grew or not, since setting the viewport
587
+ * fires `resize` too, and checks the images and fonts again. Gives why the story isn't ready, or nothing when it
588
+ * is.
589
+ */
590
+ const regrowViewport = async () => {
591
+ if (!growsViewport) {
592
+ return undefined;
593
+ }
594
+ step = 'regrow-viewport';
595
+ await page.setViewport(story.viewport);
596
+ await page.growViewportToContent();
597
+ return (await letPageReact('frames-after-regrow')) ?? (await checkAssets('assets-after-regrow'));
447
598
  };
448
599
  /**
449
- * Runs the story's wait hook, if it has one, and checks its images and fonts again once it ran. Gives why the story
450
- * isn't ready, or nothing when it is.
600
+ * Runs the story's wait hook, if it has one. Once it ran, checks its images and fonts again, then measures the page
601
+ * again for a full-page capture. Gives why the story isn't ready, or nothing when it is.
451
602
  */
452
603
  const runWaitHook = async () => {
453
604
  step = 'wait';
@@ -455,9 +606,10 @@ async function captureOnPage(page, story, settings) {
455
606
  if (run.outcome === 'none') {
456
607
  return undefined;
457
608
  }
458
- return run.outcome === 'done'
459
- ? await checkAssets('assets-after-wait')
460
- : describeWaitHookRun(run, settings.readyTimeoutMs);
609
+ if (run.outcome !== 'done') {
610
+ return describeWaitHookRun(run, readyTimeout);
611
+ }
612
+ return (await checkAssets('assets-after-wait')) ?? (await regrowViewport());
461
613
  };
462
614
  /**
463
615
  * Brings the story to its end state, and checks its images and fonts again when that changed anything. Gives why the
@@ -467,14 +619,14 @@ async function captureOnPage(page, story, settings) {
467
619
  step = 'end-state';
468
620
  const endState = readEndState(await waitInPage(endStateExpression));
469
621
  if (endState.outcome !== 'settled') {
470
- return describeEndState(endState, settings.readyTimeoutMs);
622
+ return describeEndState(endState, readyTimeout);
471
623
  }
472
624
  return endState.changed ? await checkAssets('assets-after-end-state') : undefined;
473
625
  };
474
626
  /**
475
627
  * Gets the finished story ready to capture: waits for its images and fonts, grows the viewport, runs its wait hook
476
- * and brings it to its end state, stopping at the first that leaves it not ready. Gives why the story isn't ready,
477
- * or nothing when it is.
628
+ * and measures the page again after it, and brings it to its end state, stopping at the first that leaves it not
629
+ * ready. Gives why the story isn't ready, or nothing when it is.
478
630
  */
479
631
  const getReady = async () => (await checkAssets('assets')) ?? (await growViewport()) ?? (await runWaitHook()) ?? (await bringToEndState());
480
632
  /**
@@ -493,9 +645,14 @@ async function captureOnPage(page, story, settings) {
493
645
  };
494
646
  const prep = readCapturePrep(await waitInPage((limit) => prepareCaptureExpression(request, limit)));
495
647
  if (prep.outcome !== 'ready') {
496
- return { broken: describeCapturePrep(prep, element, settings.readyTimeoutMs) };
648
+ return { broken: describeCapturePrep(prep, element, readyTimeout) };
497
649
  }
498
- return { area: prep.box ?? 'full-page', remote: request.findRemote ? prep.remote : undefined, grid: prep.grid };
650
+ return {
651
+ area: prep.box ?? 'full-page',
652
+ remote: request.findRemote ? prep.remote : undefined,
653
+ grid: prep.grid,
654
+ overflow: prep.overflow,
655
+ };
499
656
  };
500
657
  try {
501
658
  await page.setViewport(story.viewport);
@@ -504,7 +661,7 @@ async function captureOnPage(page, story, settings) {
504
661
  step = 'story';
505
662
  const wait = readStoryWait(await waitInPage((limit) => storyWaitExpression(story.id, limit)));
506
663
  if (wait.outcome !== 'finished') {
507
- return brokenBy(describeStoryWait(wait, settings.readyTimeoutMs));
664
+ return brokenBy(describeStoryWait(wait, readyTimeout));
508
665
  }
509
666
  const broken = await getReady();
510
667
  if (broken !== undefined) {
@@ -518,6 +675,10 @@ async function captureOnPage(page, story, settings) {
518
675
  if (gridBroken !== undefined) {
519
676
  return brokenBy(gridBroken);
520
677
  }
678
+ const overflowBroken = overflowProblemOf(prepared.overflow, prepared.area, story);
679
+ if (overflowBroken !== undefined) {
680
+ return brokenBy(overflowBroken);
681
+ }
521
682
  step = 'capture';
522
683
  const snapshot = await page.capture(prepared.area);
523
684
  return {
@@ -534,7 +695,7 @@ async function captureOnPage(page, story, settings) {
534
695
  if (error instanceof BrowserExitedError) {
535
696
  throw error;
536
697
  }
537
- return brokenBy(describeFailure(error, step, story, settings.readyTimeoutMs));
698
+ return brokenBy(describeFailure(error, step, story, readyTimeout));
538
699
  }
539
700
  }
540
701
  /**
@@ -550,6 +711,7 @@ const imagedReasons = [
550
711
  'wait-threw',
551
712
  'element-missing',
552
713
  'grid-too-wide',
714
+ 'overflows',
553
715
  ];
554
716
  /**
555
717
  * Captures the full page of a story that just broke, as it is. Gives nothing when the capture fails or doesn't finish
@@ -588,26 +750,29 @@ async function withBrokenImage(page, story, settings, capture) {
588
750
  * Calls the story's `captureAgainIf` with a snapshot just captured on the page, leaving the page as it is. When it
589
751
  * resolves true, captures the area the snapshot was captured from again at once, doing nothing to the page in between,
590
752
  * bound by the driver's own capture limit, and gives the snapshot with the second capture as `capturedAgain`. Gives the
591
- * snapshot as it is when the story has no `captureAgainIf` or it resolves false. A second capture that fails comes back
592
- * as a broken story, with the messages the page sent, read again. Rejects with a `BrowserExitedError` when the browser
593
- * exits during the second capture, and with whatever `captureAgainIf` rejects with: it runs outside the handling that
594
- * turns the page's failures into a broken story.
753
+ * snapshot as it is when the story has no `captureAgainIf` or it resolves false. Either way the page errors are read
754
+ * again, so one the page raised during `captureAgainIf` counts. A second capture that fails comes back as a broken
755
+ * story, with the messages and page errors the page sent, read again, and the loads that failed on it. Rejects with a
756
+ * `BrowserExitedError` when the browser exits during the second capture, and with whatever `captureAgainIf` rejects
757
+ * with: it runs outside the handling that turns the page's failures into a broken story.
595
758
  */
596
759
  async function captureAgainIfAsked(page, story, settings, captured) {
597
760
  const again = await story.captureAgainIf?.(captured.result.snapshot);
598
761
  if (again !== true) {
599
- return captured.result;
762
+ return { ...captured.result, ...loadsReadOf(page, story) };
600
763
  }
601
764
  try {
602
- return { ...captured.result, capturedAgain: await page.capture(captured.area) };
765
+ const capturedAgain = await page.capture(captured.area);
766
+ return { ...captured.result, ...loadsReadOf(page, story), capturedAgain };
603
767
  }
604
768
  catch (error) {
605
769
  if (error instanceof BrowserExitedError) {
606
770
  throw error;
607
771
  }
608
772
  return {
609
- broken: describeFailure(error, 'capture-again', story, settings.readyTimeoutMs),
773
+ broken: withFailedLoads(describeFailure(error, 'capture-again', story, readyTimeoutOf(story, settings)), page.failedLoads(), story.url),
610
774
  console: page.consoleMessages(),
775
+ ...loadsReadOf(page, story),
611
776
  };
612
777
  }
613
778
  }
@@ -642,6 +807,11 @@ export function pageSetupOf(settings) {
642
807
  * capture, set up with the settings, a user agent ending in `StorybookTestRunner` and the page script. After a broken
643
808
  * story, it closes the page and opens a fresh one, in a fresh browser context, for the next story.
644
809
  *
810
+ * A page watches its real network requests when the settings list hosts, or when the story it opens for asks with
811
+ * `watchRequests`. A story that asks, on a page that doesn't watch, gets a fresh page that does, the old one closed
812
+ * first. A page that watches is kept for the stories after it, since watching costs less than a fresh page, but only
813
+ * a story that asks gets the hosts of its real network requests, from every attempt, each once.
814
+ *
645
815
  * Before each later capture on that page, it clears the cookies, `localStorage`, `sessionStorage` and IndexedDB the
646
816
  * previous story left, keeping Cache Storage and service workers. The previous story's document stays loaded until the
647
817
  * next story's commits, so a timer or handler of it can still write storage after the clearing. When the clearing
@@ -651,15 +821,21 @@ export function pageSetupOf(settings) {
651
821
  * A story that navigates away is captured again at once, up to 2 more times, each on a fresh page in a fresh browser
652
822
  * context. When the third attempt navigates away too, the story is broken, with that attempt's message and URL. Any
653
823
  * other outcome of a retry, a snapshot or another broken reason, is the story's outcome, and no other reason is
654
- * retried.
824
+ * retried. The capture keeps the page errors of every attempt, each once, in the order first seen, though only the
825
+ * last attempt's outcome counts.
655
826
  *
656
827
  * A story whose page shows a grid wider than the viewport, or too tall to capture, is broken with `grid-too-wide` or
657
- * `too-tall` before anything is captured.
828
+ * `too-tall` before anything is captured. Then a story whose capture would cut content its page shows is broken with
829
+ * `overflows`, unless it sets `allowOverflow: true`.
830
+ *
831
+ * A broken story whose page couldn't load some of Storybook's own files at the network level, such as a connection the
832
+ * server dropped, keeps them as `failedLoads`, and its message gains a sentence naming the first and the browser's
833
+ * error, with how many there were when more than one. Its reason stays as it was, and nothing more is retried.
658
834
  *
659
835
  * A story that asks for it with `imageWhenBroken` and breaks while its page still shows something, for the reasons
660
- * `error`, `play-threw`, `timeout`, `fonts-not-loaded`, `wait-threw`, `element-missing` and `grid-too-wide`, comes
661
- * with an image of the full page, captured before the page is closed, unless that capture fails or takes longer than
662
- * the settings' `brokenImageTimeLimitMs`. A browser exit during it rejects the capture with a `BrowserExitedError`.
836
+ * `error`, `play-threw`, `timeout`, `fonts-not-loaded`, `wait-threw`, `element-missing`, `grid-too-wide` and
837
+ * `overflows`, comes with an image of the full page, captured before the page is closed, unless that capture fails or
838
+ * takes longer than the settings' `brokenImageTimeLimitMs`. A browser exit during it rejects the capture with a `BrowserExitedError`.
663
839
  *
664
840
  * When a story has `captureAgainIf`, each attempt that captured a snapshot calls it with the snapshot, the page left as
665
841
  * it is, and captures the same area again at once when it resolves true. A second capture that fails makes the story
@@ -671,6 +847,7 @@ export function pageSetupOf(settings) {
671
847
  export function openCaptureSession(driver, settings) {
672
848
  const setup = pageSetupOf(settings);
673
849
  let page;
850
+ let pageWatchesRequests = false;
674
851
  const closePage = async () => {
675
852
  const closing = page;
676
853
  page = undefined;
@@ -702,7 +879,11 @@ export function openCaptureSession(driver, settings) {
702
879
  */
703
880
  const captureOnOpenPage = async (story) => {
704
881
  try {
705
- page ??= await driver.newPage(setup);
882
+ if (page === undefined) {
883
+ const watchRequests = setup.watchRequests || story.watchRequests === true;
884
+ page = await driver.newPage({ ...setup, watchRequests });
885
+ pageWatchesRequests = watchRequests;
886
+ }
706
887
  }
707
888
  catch (error) {
708
889
  if (error instanceof BrowserExitedError) {
@@ -713,6 +894,7 @@ export function openCaptureSession(driver, settings) {
713
894
  reason: 'error',
714
895
  message: `visual-check couldn't open a page for the story: ${failureReasonOf(error)}`,
715
896
  },
897
+ pageErrors: [],
716
898
  };
717
899
  }
718
900
  try {
@@ -737,12 +919,23 @@ export function openCaptureSession(driver, settings) {
737
919
  };
738
920
  return {
739
921
  capture: async (story) => {
922
+ if (story.watchRequests === true && !pageWatchesRequests) {
923
+ await closePage();
924
+ }
740
925
  await clearOpenPage();
741
926
  let capture = await captureOnOpenPage(story);
927
+ const attempts = [capture];
742
928
  for (let retry = 0; retry < navigatedAwayRetries && navigatedAway(capture); retry += 1) {
743
929
  capture = await captureOnOpenPage(story);
930
+ attempts.push(capture);
744
931
  }
745
- return capture;
932
+ return {
933
+ ...capture,
934
+ pageErrors: eachPageErrorOnce(...attempts.map(({ pageErrors }) => pageErrors)),
935
+ ...(story.watchRequests === true
936
+ ? { requestHosts: [...new Set(attempts.flatMap(({ requestHosts }) => requestHosts ?? []))] }
937
+ : {}),
938
+ };
746
939
  },
747
940
  close: closePage,
748
941
  };