@itmetsam/samurai-framework 0.10.0 → 0.12.1

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 (326) hide show
  1. package/README.md +3 -4
  2. package/dist/assert/assertion-error.d.ts +1 -1
  3. package/dist/assert/expect.d.ts +5 -50
  4. package/dist/assert/expect.js +5 -182
  5. package/dist/assert/locator-assertions.d.ts +22 -0
  6. package/dist/assert/locator-assertions.js +61 -0
  7. package/dist/assert/pending-assertions.d.ts +7 -0
  8. package/dist/assert/pending-assertions.js +40 -0
  9. package/dist/assert/text-match.d.ts +4 -0
  10. package/dist/assert/text-match.js +11 -0
  11. package/dist/assert/value-assertions.d.ts +23 -0
  12. package/dist/assert/value-assertions.js +82 -0
  13. package/dist/browser/browser-context.d.ts +0 -1
  14. package/dist/browser/browser-context.js +13 -5
  15. package/dist/browser/browser-finder.js +5 -9
  16. package/dist/browser/browser.d.ts +3 -31
  17. package/dist/browser/browser.js +36 -219
  18. package/dist/browser/chrome-launch.d.ts +2 -1
  19. package/dist/browser/dialog-handling.d.ts +32 -0
  20. package/dist/browser/dialog-handling.js +85 -0
  21. package/dist/browser/document-watcher.d.ts +44 -0
  22. package/dist/browser/document-watcher.js +160 -0
  23. package/dist/browser/download-folders.d.ts +0 -1
  24. package/dist/browser/download-folders.js +7 -15
  25. package/dist/browser/download.js +5 -10
  26. package/dist/browser/downloads-dir.js +2 -2
  27. package/dist/browser/emit.d.ts +7 -0
  28. package/dist/browser/emit.js +16 -0
  29. package/dist/browser/emulation.d.ts +1 -1
  30. package/dist/browser/emulation.js +54 -18
  31. package/dist/browser/file-chooser.js +4 -11
  32. package/dist/browser/history.d.ts +6 -0
  33. package/dist/browser/history.js +89 -0
  34. package/dist/browser/index.d.ts +2 -0
  35. package/dist/browser/index.js +2 -0
  36. package/dist/browser/init-script.d.ts +2 -0
  37. package/dist/browser/init-script.js +16 -0
  38. package/dist/browser/launch-firefox.d.ts +20 -0
  39. package/dist/browser/launch-firefox.js +66 -0
  40. package/dist/browser/launch-flags.d.ts +18 -0
  41. package/dist/browser/launch-flags.js +100 -0
  42. package/dist/browser/lazy.d.ts +21 -0
  43. package/dist/browser/lazy.js +44 -0
  44. package/dist/browser/page-events.d.ts +44 -0
  45. package/dist/browser/page-events.js +58 -0
  46. package/dist/browser/page-logs.js +2 -9
  47. package/dist/browser/page-navigation.d.ts +58 -0
  48. package/dist/browser/page-navigation.js +108 -0
  49. package/dist/browser/page-network.d.ts +69 -0
  50. package/dist/browser/page-network.js +163 -0
  51. package/dist/browser/page-settings.d.ts +35 -0
  52. package/dist/browser/page-settings.js +51 -0
  53. package/dist/browser/page-transfers.d.ts +36 -0
  54. package/dist/browser/page-transfers.js +50 -0
  55. package/dist/browser/page.d.ts +39 -154
  56. package/dist/browser/page.js +134 -758
  57. package/dist/browser/pdf.d.ts +1 -1
  58. package/dist/browser/session.d.ts +16 -0
  59. package/dist/browser/session.js +32 -0
  60. package/dist/browser/viewport.d.ts +19 -0
  61. package/dist/browser/viewport.js +72 -0
  62. package/dist/browser/warm-up.d.ts +1 -1
  63. package/dist/browser/warm-up.js +2 -1
  64. package/dist/browsers/index.d.ts +1 -1
  65. package/dist/browsers/index.js +1 -1
  66. package/dist/browsers/pins.d.ts +0 -2
  67. package/dist/browsers/pins.js +0 -2
  68. package/dist/browsers/store.d.ts +0 -2
  69. package/dist/browsers/store.js +1 -2
  70. package/dist/cli/args.d.ts +13 -6
  71. package/dist/cli/args.js +13 -10
  72. package/dist/cli/browsers.d.ts +1 -2
  73. package/dist/cli/browsers.js +2 -2
  74. package/dist/cli/console-reporter.js +3 -2
  75. package/dist/cli/flow-reporter.js +2 -1
  76. package/dist/cli/flow.d.ts +1 -2
  77. package/dist/cli/flow.js +25 -22
  78. package/dist/cli/init.js +2 -7
  79. package/dist/cli/io.d.ts +10 -0
  80. package/dist/cli/io.js +1 -0
  81. package/dist/cli/main.d.ts +3 -10
  82. package/dist/cli/main.js +10 -143
  83. package/dist/cli/paint.d.ts +2 -0
  84. package/dist/cli/paint.js +4 -0
  85. package/dist/cli/record.d.ts +4 -0
  86. package/dist/cli/record.js +93 -0
  87. package/dist/cli/usage.d.ts +1 -0
  88. package/dist/cli/usage.js +58 -0
  89. package/dist/cli/version.d.ts +2 -0
  90. package/dist/cli/version.js +7 -0
  91. package/dist/config/browsers.d.ts +11 -0
  92. package/dist/config/browsers.js +32 -0
  93. package/dist/config/config.js +4 -1
  94. package/dist/config/mask.d.ts +1 -1
  95. package/dist/config/mask.js +7 -2
  96. package/dist/config/run-settings.d.ts +1 -2
  97. package/dist/config/run-settings.js +1 -6
  98. package/dist/config/timeouts.d.ts +2 -0
  99. package/dist/config/timeouts.js +13 -0
  100. package/dist/config/workers.d.ts +14 -0
  101. package/dist/config/workers.js +29 -0
  102. package/dist/flows/run/branch-context.d.ts +14 -0
  103. package/dist/flows/run/branch-context.js +35 -0
  104. package/dist/flows/run/handlers/condition.d.ts +1 -1
  105. package/dist/flows/run/handlers/end.d.ts +1 -1
  106. package/dist/flows/run/handlers/group.d.ts +1 -1
  107. package/dist/flows/run/handlers/index.d.ts +2 -2
  108. package/dist/flows/run/handlers/parallel.d.ts +1 -1
  109. package/dist/flows/run/handlers/start.d.ts +1 -1
  110. package/dist/flows/run/handlers/support.d.ts +3 -27
  111. package/dist/flows/run/handlers/test.d.ts +1 -1
  112. package/dist/flows/run/handlers/types.d.ts +27 -0
  113. package/dist/flows/run/handlers/types.js +1 -0
  114. package/dist/flows/run/index.d.ts +1 -1
  115. package/dist/flows/run/prepare-flow.d.ts +14 -0
  116. package/dist/flows/run/prepare-flow.js +44 -0
  117. package/dist/flows/run/project.d.ts +33 -2
  118. package/dist/flows/run/project.js +139 -57
  119. package/dist/flows/run/run.d.ts +3 -4
  120. package/dist/flows/run/run.js +23 -193
  121. package/dist/flows/run/walker.d.ts +56 -0
  122. package/dist/flows/run/walker.js +225 -0
  123. package/dist/flows/steps/catalog.d.ts +1 -1
  124. package/dist/flows/steps/handler.d.ts +1 -1
  125. package/dist/flows/steps/set.d.ts +1 -1
  126. package/dist/index.js +1 -1
  127. package/dist/locator/actionability.d.ts +33 -0
  128. package/dist/locator/actionability.js +104 -0
  129. package/dist/locator/chain-resolver.d.ts +20 -0
  130. package/dist/locator/chain-resolver.js +102 -0
  131. package/dist/locator/document-swap.d.ts +1 -0
  132. package/dist/locator/document-swap.js +11 -0
  133. package/dist/locator/element-state.d.ts +3 -1
  134. package/dist/locator/element-state.js +11 -3
  135. package/dist/locator/file-actions.d.ts +35 -0
  136. package/dist/locator/file-actions.js +55 -0
  137. package/dist/{script/helpers.js → locator/helper-realm.js} +2 -2
  138. package/dist/locator/input-actions.d.ts +18 -0
  139. package/dist/locator/input-actions.js +80 -0
  140. package/dist/locator/label-locator.d.ts +1 -1
  141. package/dist/locator/label-locator.js +5 -12
  142. package/dist/locator/locator.d.ts +14 -37
  143. package/dist/locator/locator.js +68 -424
  144. package/dist/locator/page-scripts.d.ts +16 -0
  145. package/dist/locator/page-scripts.js +54 -0
  146. package/dist/locator/page-search.d.ts +10 -0
  147. package/dist/locator/page-search.js +19 -0
  148. package/dist/locator/selector-errors.d.ts +0 -4
  149. package/dist/locator/selector-errors.js +0 -7
  150. package/dist/locator/selector.d.ts +14 -13
  151. package/dist/locator/selector.js +10 -16
  152. package/dist/locator/text-locator.d.ts +1 -1
  153. package/dist/locator/text-locator.js +5 -9
  154. package/dist/logger/index.d.ts +6 -0
  155. package/dist/logger/index.js +14 -7
  156. package/dist/network/bidi-wire.d.ts +10 -0
  157. package/dist/network/bidi-wire.js +38 -0
  158. package/dist/network/intercept.d.ts +30 -0
  159. package/dist/network/intercept.js +130 -0
  160. package/dist/network/network-tracker.d.ts +10 -47
  161. package/dist/network/network-tracker.js +34 -68
  162. package/dist/network/network-types.d.ts +33 -0
  163. package/dist/network/network-types.js +1 -0
  164. package/dist/network/network-wait.d.ts +7 -2
  165. package/dist/network/network-wait.js +14 -4
  166. package/dist/network/response.d.ts +1 -1
  167. package/dist/network/response.js +1 -1
  168. package/dist/network/route.d.ts +92 -0
  169. package/dist/network/route.js +142 -0
  170. package/dist/network/router.d.ts +6 -91
  171. package/dist/network/router.js +25 -258
  172. package/dist/recorder/expectation.d.ts +5 -0
  173. package/dist/recorder/expectation.js +20 -0
  174. package/dist/recorder/files-recorder.d.ts +30 -0
  175. package/dist/recorder/files-recorder.js +88 -0
  176. package/dist/recorder/normalise.d.ts +17 -6
  177. package/dist/recorder/normalise.js +96 -91
  178. package/dist/recorder/options.d.ts +56 -0
  179. package/dist/recorder/options.js +1 -0
  180. package/dist/recorder/page-messages.d.ts +35 -0
  181. package/dist/recorder/page-messages.js +26 -0
  182. package/dist/recorder/ranking.js +1 -0
  183. package/dist/recorder/realms.d.ts +6 -0
  184. package/dist/recorder/realms.js +13 -0
  185. package/dist/recorder/recorder.d.ts +10 -74
  186. package/dist/recorder/recorder.js +39 -199
  187. package/dist/recorder/session-browser.d.ts +22 -0
  188. package/dist/recorder/session-browser.js +21 -0
  189. package/dist/recorder/session-secrets.d.ts +8 -0
  190. package/dist/recorder/session-secrets.js +45 -0
  191. package/dist/recorder/session.d.ts +5 -14
  192. package/dist/recorder/session.js +22 -120
  193. package/dist/recorder/spec-source.d.ts +39 -0
  194. package/dist/recorder/spec-source.js +84 -0
  195. package/dist/recorder/toolbar/action-guard.d.ts +21 -0
  196. package/dist/recorder/toolbar/action-guard.js +43 -0
  197. package/dist/recorder/toolbar/actions/assert.d.ts +4 -0
  198. package/dist/recorder/toolbar/actions/assert.js +52 -0
  199. package/dist/recorder/toolbar/actions/insert.d.ts +6 -0
  200. package/dist/recorder/toolbar/actions/insert.js +93 -0
  201. package/dist/recorder/toolbar/actions/pick.d.ts +8 -0
  202. package/dist/recorder/toolbar/actions/pick.js +26 -0
  203. package/dist/recorder/toolbar/actions/reply.d.ts +7 -0
  204. package/dist/recorder/toolbar/actions/reply.js +10 -0
  205. package/dist/recorder/toolbar/controller-fixture.d.ts +47 -0
  206. package/dist/recorder/toolbar/controller-fixture.js +129 -0
  207. package/dist/recorder/toolbar/controller.d.ts +12 -78
  208. package/dist/recorder/toolbar/controller.js +35 -247
  209. package/dist/recorder/toolbar/inspect.d.ts +1 -3
  210. package/dist/recorder/toolbar/inspect.js +2 -2
  211. package/dist/recorder/toolbar/page-scope.d.ts +19 -0
  212. package/dist/recorder/toolbar/page-scope.js +43 -0
  213. package/dist/recorder/toolbar/protocol.d.ts +2 -1
  214. package/dist/recorder/toolbar/source/attach.d.ts +2 -0
  215. package/dist/recorder/toolbar/source/attach.js +41 -0
  216. package/dist/recorder/toolbar/source/dom.d.ts +2 -0
  217. package/dist/recorder/toolbar/source/dom.js +47 -0
  218. package/dist/recorder/toolbar/source/drag.d.ts +2 -0
  219. package/dist/recorder/toolbar/source/drag.js +32 -0
  220. package/dist/recorder/toolbar/source/events-page.d.ts +2 -0
  221. package/dist/recorder/toolbar/source/events-page.js +67 -0
  222. package/dist/recorder/toolbar/source/events-toolbar.d.ts +2 -0
  223. package/dist/recorder/toolbar/source/events-toolbar.js +35 -0
  224. package/dist/recorder/toolbar/source/fields.d.ts +2 -0
  225. package/dist/recorder/toolbar/source/fields.js +44 -0
  226. package/dist/recorder/toolbar/source/handlers.d.ts +2 -0
  227. package/dist/recorder/toolbar/source/handlers.js +134 -0
  228. package/dist/recorder/toolbar/source/names.d.ts +2 -0
  229. package/dist/recorder/toolbar/source/names.js +12 -0
  230. package/dist/recorder/toolbar/source/picking.d.ts +2 -0
  231. package/dist/recorder/toolbar/source/picking.js +72 -0
  232. package/dist/recorder/toolbar/source/placement.d.ts +2 -0
  233. package/dist/recorder/toolbar/source/placement.js +45 -0
  234. package/dist/recorder/toolbar/source/recorder-side.d.ts +2 -0
  235. package/dist/recorder/toolbar/source/recorder-side.js +54 -0
  236. package/dist/recorder/toolbar/source/setup.d.ts +2 -0
  237. package/dist/recorder/toolbar/source/setup.js +50 -0
  238. package/dist/recorder/toolbar/source/views-panels.d.ts +2 -0
  239. package/dist/recorder/toolbar/source/views-panels.js +150 -0
  240. package/dist/recorder/toolbar/source/views-rail.d.ts +2 -0
  241. package/dist/recorder/toolbar/source/views-rail.js +40 -0
  242. package/dist/recorder/toolbar/source/views-render.d.ts +2 -0
  243. package/dist/recorder/toolbar/source/views-render.js +48 -0
  244. package/dist/recorder/toolbar/source.js +30 -856
  245. package/dist/recorder/toolbar/types.d.ts +70 -0
  246. package/dist/recorder/toolbar/types.js +1 -0
  247. package/dist/recorder/toolbar-bridge.d.ts +43 -0
  248. package/dist/recorder/toolbar-bridge.js +106 -0
  249. package/dist/runner/browsers.d.ts +0 -12
  250. package/dist/runner/browsers.js +1 -33
  251. package/dist/runner/options.d.ts +31 -0
  252. package/dist/runner/options.js +1 -0
  253. package/dist/runner/pooled-run.d.ts +43 -0
  254. package/dist/runner/pooled-run.js +75 -0
  255. package/dist/runner/ports.d.ts +2 -0
  256. package/dist/runner/ports.js +2 -0
  257. package/dist/runner/registry.d.ts +1 -1
  258. package/dist/runner/registry.js +1 -1
  259. package/dist/runner/reporter.d.ts +31 -10
  260. package/dist/runner/reporter.js +39 -6
  261. package/dist/runner/run-test.d.ts +16 -0
  262. package/dist/runner/run-test.js +178 -0
  263. package/dist/runner/run.d.ts +5 -3
  264. package/dist/runner/run.js +28 -29
  265. package/dist/runner/select.d.ts +24 -0
  266. package/dist/runner/select.js +77 -0
  267. package/dist/runner/test-dir.d.ts +13 -0
  268. package/dist/runner/test-dir.js +27 -0
  269. package/dist/runner/test-runner.d.ts +25 -56
  270. package/dist/runner/test-runner.js +81 -270
  271. package/dist/runner/worker-pool.d.ts +67 -0
  272. package/dist/runner/worker-pool.js +275 -0
  273. package/dist/runner/worker-process.d.ts +6 -0
  274. package/dist/runner/worker-process.js +54 -0
  275. package/dist/runner/worker-protocol.d.ts +67 -0
  276. package/dist/runner/worker-protocol.js +1 -0
  277. package/dist/runner/worker-session.d.ts +7 -0
  278. package/dist/runner/worker-session.js +60 -0
  279. package/dist/runner/worker.d.ts +26 -0
  280. package/dist/runner/worker.js +121 -0
  281. package/dist/runner/workers-option.d.ts +15 -0
  282. package/dist/runner/workers-option.js +22 -0
  283. package/dist/script/call-function.d.ts +1 -9
  284. package/dist/script/call-function.js +2 -19
  285. package/dist/script/element-handle.d.ts +1 -2
  286. package/dist/script/element-handle.js +1 -2
  287. package/dist/script/serialize.d.ts +3 -12
  288. package/dist/script/serialize.js +53 -62
  289. package/dist/steps/parse/call.d.ts +3 -0
  290. package/dist/steps/parse/call.js +81 -0
  291. package/dist/steps/parse/expectation.d.ts +5 -0
  292. package/dist/steps/parse/expectation.js +71 -0
  293. package/dist/steps/parse/file-entry.d.ts +4 -0
  294. package/dist/steps/parse/file-entry.js +74 -0
  295. package/dist/steps/parse/literals.d.ts +4 -0
  296. package/dist/steps/parse/literals.js +28 -0
  297. package/dist/steps/parse/step.d.ts +4 -0
  298. package/dist/steps/parse/step.js +81 -0
  299. package/dist/steps/parse.js +2 -323
  300. package/dist/transport/bidi-connection.d.ts +4 -15
  301. package/dist/transport/bidi-connection.js +9 -63
  302. package/dist/transport/log-redaction.d.ts +13 -0
  303. package/dist/transport/log-redaction.js +51 -0
  304. package/dist/transport/subscriptions.js +18 -13
  305. package/dist/transport/unsupported.d.ts +7 -0
  306. package/dist/transport/unsupported.js +13 -0
  307. package/dist/types/bidi-modules/browser.d.ts +1 -12
  308. package/dist/types/bidi-modules/browsing-context.d.ts +8 -18
  309. package/dist/types/bidi-modules/emulation.d.ts +29 -21
  310. package/dist/types/bidi-modules/input.d.ts +1 -9
  311. package/dist/types/bidi-modules/network.d.ts +29 -24
  312. package/dist/types/bidi-modules/script.d.ts +0 -9
  313. package/dist/types/bidi-modules/session.d.ts +0 -8
  314. package/dist/types/bidi-modules/storage.d.ts +0 -5
  315. package/dist/types/bidi.d.ts +7 -37
  316. package/dist/types/config.d.ts +12 -0
  317. package/dist/types/test.d.ts +8 -3
  318. package/dist/wait/wait-until.d.ts +1 -5
  319. package/dist/wait/wait-until.js +7 -16
  320. package/package.json +3 -2
  321. package/dist/config/default.d.ts +0 -2
  322. package/dist/config/default.js +0 -3
  323. package/dist/types/bidi-modules/web-extensions.d.ts +0 -9
  324. package/dist/types/bidi-protocols/command.d.ts +0 -7
  325. package/dist/types/bidi-protocols/event.d.ts +0 -17
  326. /package/dist/{script/helpers.d.ts → locator/helper-realm.d.ts} +0 -0
@@ -0,0 +1,163 @@
1
+ import { DataCollector, ResponseBodyUnavailableError, } from "../network/data-collector.js";
2
+ import { NetworkTracker } from "../network/network-tracker.js";
3
+ import { RequestTimeoutError, ResponseTimeoutError, toPredicate, } from "../network/network-wait.js";
4
+ import { Response } from "../network/response.js";
5
+ import { Router } from "../network/router.js";
6
+ import { isUnsupported, UnsupportedOperationError, } from "../transport/unsupported.js";
7
+ import { Lazy } from "./lazy.js";
8
+ /** Thrown by `PageNetwork.tracker()` when config `network.track` turned tracking off */
9
+ class NetworkTrackingDisabledError extends Error {
10
+ constructor() {
11
+ super("network tracking is disabled");
12
+ this.name = "NetworkTrackingDisabledError";
13
+ }
14
+ }
15
+ /**
16
+ * Everything a page does with its network: request tracking and idle waits, response bodies, waiting for a
17
+ * request or response, the HTTP cache switch and the routes (interception).
18
+ */
19
+ export class PageNetwork {
20
+ constructor(connector, contextId, deps) {
21
+ this.connector = connector;
22
+ this.contextId = contextId;
23
+ this.deps = deps;
24
+ this.lazyTracker = new Lazy();
25
+ this.lazyCollector = new Lazy();
26
+ this.lazyRouter = new Lazy();
27
+ this.responses = new WeakMap();
28
+ this.openCollector = async () => {
29
+ const { maxBodySize } = await this.deps.config.network();
30
+ return DataCollector.start(this.connector, this.contextId, {
31
+ ...(maxBodySize !== undefined && { maxBodySize }),
32
+ });
33
+ };
34
+ }
35
+ /** The network tracker, created on first use. Rejects with NetworkTrackingDisabledError when config turned tracking off */
36
+ tracker() {
37
+ return this.lazyTracker.get(async () => {
38
+ const settings = await this.deps.config.network();
39
+ if (settings.track === false)
40
+ throw new NetworkTrackingDisabledError();
41
+ const tracker = await NetworkTracker.start(this.connector, await this.deps.tree.ensure(), this.contextId);
42
+ const { emitter } = this.deps;
43
+ tracker.on("request", (request) => emitter.emit("request", request));
44
+ tracker.on("response", (response) => emitter.emit("response", this.responseFor(response)));
45
+ tracker.on("requestfailed", (failed) => emitter.emit("requestfailed", failed));
46
+ if (settings.collectBodies)
47
+ await this.startBodyCollection();
48
+ return tracker;
49
+ }, (err) => err instanceof NetworkTrackingDisabledError);
50
+ }
51
+ /** Starts following requests now; does nothing when config `network.track` is false */
52
+ async startTracking() {
53
+ try {
54
+ await this.tracker();
55
+ }
56
+ catch (err) {
57
+ if (!(err instanceof NetworkTrackingDisabledError))
58
+ throw err;
59
+ }
60
+ }
61
+ /** Waits until no request has been in flight for `idleTime` ms (default config `network.idleTime`, then 500) */
62
+ async waitForIdle(options = {}) {
63
+ const tracker = await this.tracker();
64
+ const idleTime = await this.deps.config.idleTime(options.idleTime);
65
+ const timeout = await this.deps.config.navigationTimeout(options.timeout);
66
+ await tracker.waitForIdle({ idleTime, timeout });
67
+ }
68
+ /** Starts keeping response bodies, which is what makes `response.body()` possible */
69
+ async startBodyCollection() {
70
+ await this.lazyCollector.get(this.openCollector);
71
+ }
72
+ /** One Response per network response, whoever asks, so a body is read from the browser once */
73
+ responseFor(data) {
74
+ let response = this.responses.get(data);
75
+ if (!response) {
76
+ response = new Response(data, (loaded) => this.loadBody(loaded));
77
+ this.responses.set(data, response);
78
+ }
79
+ return response;
80
+ }
81
+ async loadBody(response) {
82
+ if (!this.lazyCollector.started) {
83
+ throw new ResponseBodyUnavailableError(response.url, "no body collection was running: call page.startBodyCollection() before the request, or listen with page.on('response')");
84
+ }
85
+ const collector = await this.lazyCollector.get(this.openCollector);
86
+ const body = await collector.read(response.id, response.url);
87
+ void collector.release(response.id);
88
+ return body;
89
+ }
90
+ /** Resolves with the next response whose URL matches (a pattern, see `route`) or that the function accepts */
91
+ async waitForResponse(match, options = {}) {
92
+ await Promise.all([this.tracker(), this.startBodyCollection()]);
93
+ return this.waitForNetworkEvent("response", match, options);
94
+ }
95
+ /** Like `waitForResponse`, for requests */
96
+ async waitForRequest(match, options = {}) {
97
+ await this.tracker();
98
+ return this.waitForNetworkEvent("request", match, options);
99
+ }
100
+ waitForNetworkEvent(event, match, options) {
101
+ const matches = toPredicate(match);
102
+ const Timeout = event === "request" ? RequestTimeoutError : ResponseTimeoutError;
103
+ return this.deps.waitForEvent(event, matches, options, (timeout) => new Timeout(event === "request" ? "waitForRequest" : "waitForResponse", match, timeout));
104
+ }
105
+ /** Turns the browser's HTTP cache off (`true`) or back on for this page: every request then goes to the server */
106
+ async setCacheDisabled(disabled) {
107
+ try {
108
+ await this.connector.send("network.setCacheBehavior", {
109
+ cacheBehavior: disabled ? "bypass" : "default",
110
+ contexts: [this.contextId],
111
+ });
112
+ }
113
+ catch (err) {
114
+ if (isUnsupported(err)) {
115
+ throw new UnsupportedOperationError("setCacheDisabled(): not supported by the browser");
116
+ }
117
+ throw err;
118
+ }
119
+ }
120
+ router() {
121
+ return this.lazyRouter.get(async () => {
122
+ const routeTimeout = (await this.deps.config.network()).routeTimeout;
123
+ return new Router(this.connector, await this.deps.tree.ensure(), this.contextId, { ...(routeTimeout !== undefined && { routeTimeout }) });
124
+ });
125
+ }
126
+ /** Sends requests whose URL matches to `handler` (see `Page.route`) */
127
+ async route(url, handler) {
128
+ await (await this.router()).route(url, handler);
129
+ }
130
+ /** Removes the routes for `url` (only the one with `handler`, when given) */
131
+ async unroute(url, handler) {
132
+ if (!this.lazyRouter.started)
133
+ return;
134
+ await (await this.router()).unroute(url, handler);
135
+ }
136
+ async unrouteAll() {
137
+ if (!this.lazyRouter.started)
138
+ return;
139
+ await (await this.router()).unrouteAll();
140
+ }
141
+ /** Errors thrown by route handlers so far */
142
+ routeErrors() {
143
+ return this.lazyRouter.peek()?.errors ?? [];
144
+ }
145
+ /** The first half of releasing the network: the tracker goes before the tree it reads */
146
+ async disposeTracker() {
147
+ try {
148
+ await (await this.lazyTracker.take())?.dispose();
149
+ }
150
+ catch {
151
+ // A tracker that never started (or was switched off) has nothing to release
152
+ }
153
+ }
154
+ /** The second half: the router, then the body collector */
155
+ disposeRest() {
156
+ const router = this.lazyRouter.take();
157
+ const collector = this.lazyCollector.take();
158
+ return [
159
+ router?.then((resolved) => resolved.dispose()),
160
+ collector?.then((resolved) => resolved.dispose()),
161
+ ];
162
+ }
163
+ }
@@ -0,0 +1,35 @@
1
+ import type { SamuraiTestConfig } from "../types/config.js";
2
+ import type { BiDiCommands } from "../types/bidi.js";
3
+ /** Options that otherwise come from `samurai.config.ts` */
4
+ export type PageSettings = Pick<SamuraiTestConfig, "network" | "navigation" | "use">;
5
+ /** What `navigateTo` and `reload` wait for */
6
+ export type ReadinessState = NonNullable<BiDiCommands["browsingContext.navigate"]["params"]["wait"]>;
7
+ /** The settings a page uses: the ones it was given, else the project's config, else the defaults */
8
+ export declare class PageConfig {
9
+ private readonly given?;
10
+ constructor(given?: PageSettings | undefined);
11
+ network(): Promise<{
12
+ track?: boolean;
13
+ idleTime?: number;
14
+ routeTimeout?: number;
15
+ collectBodies?: boolean;
16
+ maxBodySize?: number;
17
+ }>;
18
+ navigation(): Promise<{
19
+ timeout?: number;
20
+ waitUntil?: "none" | "interactive" | "complete";
21
+ }>;
22
+ use(): Promise<{
23
+ viewport?: {
24
+ width: number;
25
+ height: number;
26
+ } | null;
27
+ headless?: boolean;
28
+ }>;
29
+ /** The time (ms) a navigation or a wait may take: the call's, else config `navigation.timeout`, else 30 s */
30
+ navigationTimeout(override?: number): Promise<number>;
31
+ /** What a navigation waits for: the call's, else config `navigation.waitUntil`, else the load event */
32
+ navigationWait(override?: ReadinessState): Promise<ReadinessState>;
33
+ /** Time (ms) without requests in flight that counts as idle: the call's, else config `network.idleTime`, else 500 */
34
+ idleTime(override?: number): Promise<number>;
35
+ }
@@ -0,0 +1,51 @@
1
+ import { readConfig } from "../config/config.js";
2
+ import logger from "../logger/index.js";
3
+ /** Time (ms) a navigation or a wait for a load state may take */
4
+ const DEFAULT_NAVIGATION_TIMEOUT = 30000;
5
+ /** Time (ms) without requests in flight that counts as idle */
6
+ const DEFAULT_IDLE_TIME = 500;
7
+ /** A section of the config, or `{}` when it cannot be read (a page can be used without a project) */
8
+ async function readSection(key) {
9
+ try {
10
+ return ((await readConfig(key)) ?? {});
11
+ }
12
+ catch (err) {
13
+ logger.debug("Could not read %s config, using defaults", key, { err });
14
+ return {};
15
+ }
16
+ }
17
+ /** The settings a page uses: the ones it was given, else the project's config, else the defaults */
18
+ export class PageConfig {
19
+ constructor(given) {
20
+ this.given = given;
21
+ }
22
+ network() {
23
+ return this.given?.network
24
+ ? Promise.resolve(this.given.network)
25
+ : readSection("network");
26
+ }
27
+ navigation() {
28
+ return this.given?.navigation
29
+ ? Promise.resolve(this.given.navigation)
30
+ : readSection("navigation");
31
+ }
32
+ use() {
33
+ return this.given?.use
34
+ ? Promise.resolve(this.given.use)
35
+ : readSection("use");
36
+ }
37
+ /** The time (ms) a navigation or a wait may take: the call's, else config `navigation.timeout`, else 30 s */
38
+ async navigationTimeout(override) {
39
+ return (override ??
40
+ (await this.navigation()).timeout ??
41
+ DEFAULT_NAVIGATION_TIMEOUT);
42
+ }
43
+ /** What a navigation waits for: the call's, else config `navigation.waitUntil`, else the load event */
44
+ async navigationWait(override) {
45
+ return override ?? (await this.navigation()).waitUntil ?? "complete";
46
+ }
47
+ /** Time (ms) without requests in flight that counts as idle: the call's, else config `network.idleTime`, else 500 */
48
+ async idleTime(override) {
49
+ return override ?? (await this.network()).idleTime ?? DEFAULT_IDLE_TIME;
50
+ }
51
+ }
@@ -0,0 +1,36 @@
1
+ import type EventEmitter from "node:events";
2
+ import type { BiDiConnector } from "../transport/bidi-connection.js";
3
+ import type { BrowsingContext } from "../types/bidi-modules/browsing-context.js";
4
+ import type { TreeSource } from "./dialog-handling.js";
5
+ import { Download } from "./download.js";
6
+ import { FileChooser } from "./file-chooser.js";
7
+ import type { PageEventName, PageEvents, WaitOptions } from "./page-events.js";
8
+ import type { PageConfig } from "./page-settings.js";
9
+ /** What `PageTransfers` takes from the page around it */
10
+ export interface PageTransfersDeps {
11
+ config: PageConfig;
12
+ tree: TreeSource;
13
+ /** Where `download` and `filechooser` are emitted */
14
+ emitter: EventEmitter;
15
+ /** Resolves with the first event of a kind that `matches` accepts (the page's `waitForPageEvent`) */
16
+ waitForEvent: <E extends PageEventName>(event: E, matches: (item: PageEvents[E][0]) => boolean, options: WaitOptions, onTimeout: (timeout: number) => Error) => Promise<PageEvents[E][0]>;
17
+ }
18
+ /** What goes between a page and the disk: downloads it starts and file pickers it opens */
19
+ export declare class PageTransfers {
20
+ private connector;
21
+ private contextId;
22
+ private deps;
23
+ private lazyDownloads;
24
+ private lazyFileChoosers;
25
+ constructor(connector: BiDiConnector, contextId: BrowsingContext, deps: PageTransfersDeps);
26
+ /** Starts following downloads; the browser does this when it opens a page, `page.on("download")` and `waitForDownload` when needed */
27
+ startDownloadTracking(): Promise<void>;
28
+ /** Starts following file pickers; the browser does this when it opens a page, `page.on("filechooser")` and `waitForFileChooser` when needed */
29
+ startFileChooserTracking(): Promise<void>;
30
+ /** Resolves with the next download (that `accepts`, when given) the page starts */
31
+ waitForDownload(options?: WaitOptions, accepts?: (download: Download) => boolean): Promise<Download>;
32
+ /** Resolves with the next file picker (that `accepts`, when given) the page opens */
33
+ waitForFileChooser(options?: WaitOptions, accepts?: (chooser: FileChooser) => boolean): Promise<FileChooser>;
34
+ /** Releases both trackers */
35
+ dispose(): (Promise<void> | undefined)[];
36
+ }
@@ -0,0 +1,50 @@
1
+ import { Download, DownloadTracker } from "./download.js";
2
+ import { FileChooser, FileChooserTracker } from "./file-chooser.js";
3
+ import { Lazy } from "./lazy.js";
4
+ import { DownloadWaitTimeoutError, FileChooserTimeoutError, } from "./page-wait.js";
5
+ /** What goes between a page and the disk: downloads it starts and file pickers it opens */
6
+ export class PageTransfers {
7
+ constructor(connector, contextId, deps) {
8
+ this.connector = connector;
9
+ this.contextId = contextId;
10
+ this.deps = deps;
11
+ this.lazyDownloads = new Lazy();
12
+ this.lazyFileChoosers = new Lazy();
13
+ }
14
+ /** Starts following downloads; the browser does this when it opens a page, `page.on("download")` and `waitForDownload` when needed */
15
+ async startDownloadTracking() {
16
+ await this.lazyDownloads.get(async () => {
17
+ const timeout = await this.deps.config.navigationTimeout();
18
+ const tracker = await DownloadTracker.start(this.connector, await this.deps.tree.ensure(), this.contextId, { timeout });
19
+ tracker.on("download", (download) => this.deps.emitter.emit("download", download));
20
+ return tracker;
21
+ });
22
+ }
23
+ /** Starts following file pickers; the browser does this when it opens a page, `page.on("filechooser")` and `waitForFileChooser` when needed */
24
+ async startFileChooserTracking() {
25
+ await this.lazyFileChoosers.get(async () => {
26
+ const tracker = await FileChooserTracker.start(this.connector, await this.deps.tree.ensure(), this.contextId);
27
+ tracker.on("filechooser", (chooser) => this.deps.emitter.emit("filechooser", chooser));
28
+ return tracker;
29
+ });
30
+ }
31
+ /** Resolves with the next download (that `accepts`, when given) the page starts */
32
+ async waitForDownload(options = {}, accepts = () => true) {
33
+ await this.startDownloadTracking();
34
+ return this.deps.waitForEvent("download", accepts, options, (timeout) => new DownloadWaitTimeoutError(timeout));
35
+ }
36
+ /** Resolves with the next file picker (that `accepts`, when given) the page opens */
37
+ async waitForFileChooser(options = {}, accepts = () => true) {
38
+ await this.startFileChooserTracking();
39
+ return this.deps.waitForEvent("filechooser", accepts, options, (timeout) => new FileChooserTimeoutError(timeout));
40
+ }
41
+ /** Releases both trackers */
42
+ dispose() {
43
+ const downloads = this.lazyDownloads.take();
44
+ const fileChoosers = this.lazyFileChoosers.take();
45
+ return [
46
+ downloads?.then((resolved) => resolved.dispose()),
47
+ fileChoosers?.then((resolved) => resolved.dispose()),
48
+ ];
49
+ }
50
+ }
@@ -1,92 +1,48 @@
1
- import Locator, { type TextOptions } from "../locator/locator.js";
2
- import type { NetworkRequest, FailedRequest } from "../network/network-tracker.js";
3
- import { Recorder, type RecorderOptions } from "../recorder/recorder.js";
1
+ import Locator from "../locator/locator.js";
2
+ import type { TextOptions } from "../locator/selector.js";
3
+ import type { NetworkRequest } from "../network/network-tracker.js";
4
+ import type { Recorder, RecorderOptions } from "../recorder/recorder.js";
4
5
  import { ContextTree } from "./context-tree.js";
5
- import { Dialog } from "./dialog.js";
6
6
  import type { BrowserContext } from "./browser-context.js";
7
7
  import { type PdfOptions } from "./pdf.js";
8
8
  import { type EmulationOptions } from "./emulation.js";
9
- import { Download } from "./download.js";
10
- import { FileChooser } from "./file-chooser.js";
9
+ import type { Download } from "./download.js";
10
+ import type { FileChooser } from "./file-chooser.js";
11
11
  import { type ScreenshotOptions } from "./screenshot.js";
12
12
  import { Evidence } from "./evidence.js";
13
- import { type ConsoleMessage, type LogRecord, type PageError } from "./page-logs.js";
14
- import { type RouteHandler } from "../network/router.js";
13
+ import { type LogRecord, type PageError } from "./page-logs.js";
14
+ import type { RouteHandler } from "../network/router.js";
15
15
  import { Response } from "../network/response.js";
16
- import { type NetworkMatch } from "../network/network-wait.js";
16
+ import type { NetworkMatch } from "../network/network-wait.js";
17
17
  import type { UrlPattern } from "../network/url-match.js";
18
+ import type { LoadState, NavigateOptions, NavigationResult } from "./page-navigation.js";
19
+ import { type PageEventName, type PageEvents, type WaitableEventName, type WaitForEventOptions, type WaitOptions } from "./page-events.js";
20
+ export type { PageEventName, WaitableEventName, WaitForEventOptions, WaitOptions, };
21
+ import { type PageSettings, type ReadinessState } from "./page-settings.js";
22
+ export type { PageSettings, ReadinessState };
23
+ import { type Viewport } from "./viewport.js";
18
24
  import { type PreloadHandle } from "../script/preload.js";
19
25
  import type { BiDiConnector } from "../transport/bidi-connection.js";
20
- import type { BiDiCommands } from "../types/bidi.js";
21
- import type { SamuraiTestConfig } from "../types/config.js";
22
26
  import type { BrowsingContext } from "../types/bidi-modules/browsing-context.js";
23
- /** Options that otherwise come from `samurai.config.ts` */
24
- export type PageSettings = Pick<SamuraiTestConfig, "network" | "navigation" | "use">;
25
- export type ReadinessState = NonNullable<BiDiCommands["browsingContext.navigate"]["params"]["wait"]>;
26
- export type LoadState = "load" | "domcontentloaded" | "networkidle";
27
- export interface NavigateOptions {
28
- /** When navigateTo resolves. @default config `navigation.waitUntil`, then "complete" */
29
- wait?: ReadinessState;
30
- /** Time (ms) the navigation may take. @default config `navigation.timeout`, then 30000 */
31
- timeout?: number;
32
- /** Scheme added to a URL without one. @default "https" */
33
- protocol?: "http" | "https";
34
- }
35
- interface NetworkEvents {
36
- request: [NetworkRequest];
37
- response: [Response];
38
- requestfailed: [FailedRequest];
39
- }
40
- /** Everything `page.on` can listen for */
41
- interface PageEvents extends NetworkEvents {
42
- download: [Download];
43
- filechooser: [FileChooser];
44
- dialog: [Dialog];
45
- console: [ConsoleMessage];
46
- pageerror: [PageError];
47
- }
48
- export type PageEventName = keyof PageEvents;
49
- /** Events `page.waitForEvent` can wait for */
50
- export type WaitableEventName = "download" | "filechooser" | "request" | "response";
51
- export interface WaitForEventOptions<T> {
52
- /** Only an event this accepts counts */
53
- predicate?: (item: T) => boolean;
54
- /** Time (ms) to wait. @default config `navigation.timeout`, then 30000 */
55
- timeout?: number;
56
- /** Runs once the wait is set up; what it causes cannot be missed */
57
- trigger?: () => Promise<unknown>;
58
- }
27
+ export type { LoadState, NavigateOptions, NavigationResult };
59
28
  export default class Page {
60
29
  private biDiConnector;
61
30
  private id;
62
- private contextTree;
31
+ private lazyTree;
63
32
  private helperRealm;
64
33
  private initScripts;
65
- private settings;
66
- private networkTracker;
34
+ private pageConfig;
67
35
  private pageEvents;
68
- /** The navigation started by the last navigateTo; failures of it fail a wait */
69
- private lastNavigation;
70
- /** Base for relative page.goto URLs; falls back to the active run's baseURL */
71
- private baseURL;
72
- /** How far navigations that did not wait for the load got, by navigation id (the latest few) */
73
- private navigationProgress;
74
- private documentEvents;
75
- private dialogHandling;
76
- private pageLogs;
77
- private loadedLogs;
36
+ private documents;
37
+ private nav;
38
+ private net;
39
+ private dialogs;
40
+ private lazyLogs;
78
41
  private errorsAllowed;
79
42
  private isClosed;
80
43
  private browserContext;
81
- private downloadTracker;
82
- private fileChooserTracker;
83
- private collectorPromise;
84
- private responses;
85
- private routerPromise;
86
- private loadedRouter;
87
- /** The context tree once loaded, for handlers that cannot wait for it */
88
- private loadedTree;
89
- private openDialogs;
44
+ private transfers;
45
+ private evidence;
90
46
  /** `settings` override what `samurai.config.ts` says; without them the config is read when needed */
91
47
  constructor(biDiConnector: BiDiConnector, contextId: string, settings?: PageSettings);
92
48
  /** The BiDi browsing context id of this page's top-level context */
@@ -95,6 +51,7 @@ export default class Page {
95
51
  tree(): Promise<ContextTree>;
96
52
  /** Locates an element on the page and returns an interactable object */
97
53
  locator(xpath: string): Locator;
54
+ private locate;
98
55
  /** Locates elements with a CSS selector */
99
56
  getByCss(css: string): Locator;
100
57
  /** Locates elements by their text: an exact match unless `match: "partial"` */
@@ -133,10 +90,7 @@ export default class Page {
133
90
  * await page.goto("/products");
134
91
  * await page.goto("https://example.com", { wait: "interactive" });
135
92
  */
136
- goto(url: string, options?: NavigateOptions): Promise<{
137
- navigation: string | null;
138
- url: string;
139
- }>;
93
+ goto(url: string, options?: NavigateOptions): Promise<NavigationResult>;
140
94
  /**
141
95
  * Navigates to `url` and resolves when the page reached `wait` (default "complete", the load event).
142
96
  * A URL without a scheme gets `https://`. Throws NavigationError when the navigation fails or takes too long.
@@ -145,15 +99,7 @@ export default class Page {
145
99
  * await page.navigateTo("example.com");
146
100
  * await page.navigateTo("localhost:3000", { wait: "interactive", protocol: "http" });
147
101
  */
148
- navigateTo(url: string, options?: NavigateOptions | ReadinessState, protocol?: "http" | "https"): Promise<{
149
- navigation: string | null;
150
- url: string;
151
- }>;
152
- /**
153
- * Runs a navigation command and settles what waiting for it means: failures become NavigationErrors, and a
154
- * navigation that did not wait for the load is watched so `waitForLoadState` can tell it from the old page.
155
- */
156
- private navigation;
102
+ navigateTo(url: string, options?: NavigateOptions | ReadinessState, protocol?: "http" | "https"): Promise<NavigationResult>;
157
103
  /**
158
104
  * Reloads the page and resolves when it reached `wait` (default like `navigateTo`). Firefox does not support
159
105
  * `ignoreCache`; asking for it throws UnsupportedOperationError.
@@ -162,26 +108,11 @@ export default class Page {
162
108
  wait?: ReadinessState;
163
109
  timeout?: number;
164
110
  ignoreCache?: boolean;
165
- }): Promise<{
166
- navigation: string | null;
167
- url: string;
168
- }>;
111
+ }): Promise<NavigationResult>;
169
112
  /** Goes back one entry in the history. False when there is none to go back to */
170
113
  goBack(): Promise<boolean>;
171
114
  /** Goes forward one entry in the history. False when there is none */
172
115
  goForward(): Promise<boolean>;
173
- private traverse;
174
- /**
175
- * Whether going back would only reach the blank page a tab starts with. Firefox does not keep that page in the
176
- * history, Chrome does; the Navigation API (Chrome only) lets Chrome say the same as Firefox.
177
- */
178
- private atFirstEntry;
179
- /**
180
- * Starts listening for the end of a history traversal (the new entry committed, or the history or fragment changed
181
- * within the document). `done` resolves at the first such event, or after a second without one (a page restored from
182
- * the back-forward cache may say nothing); it never rejects.
183
- */
184
- private watchHistoryTraversal;
185
116
  /** The URL of the page now */
186
117
  url(): Promise<string>;
187
118
  /** The title of the document now */
@@ -191,27 +122,20 @@ export default class Page {
191
122
  * @example
192
123
  * await page.setViewport({ width: 390, height: 844, devicePixelRatio: 3 });
193
124
  */
194
- setViewport(viewport: {
195
- width: number;
196
- height: number;
197
- devicePixelRatio?: number;
198
- } | null): Promise<void>;
199
- /**
200
- * Runs `change`, then waits until the page has stopped resizing. Chrome answers a viewport reset before the window
201
- * has its own size back, so a read right after it can still show the old size. The wait ends 50 ms after the last
202
- * `resize` event, and after 300 ms when the size does not change at all (no event comes). Never fails: a page that
203
- * cannot be watched is simply not waited for.
204
- */
205
- private untilResized;
125
+ setViewport(viewport: Viewport | null): Promise<void>;
206
126
  /** Gives the page the size from config `use.viewport` (1280x720 by default); the browser does this when it opens a page */
207
127
  applyDefaultViewport(): Promise<void>;
128
+ /**
129
+ * What the browser sets up on every page it opens: the default size, then everything that has to be listening
130
+ * before the page does anything (requests, dialogs, logs, downloads, file pickers). Safe to call again.
131
+ */
132
+ startTracking(): Promise<void>;
208
133
  /**
209
134
  * Takes a screenshot and returns the image (also written to `options.path`).
210
135
  * @example
211
136
  * await page.screenshot({ path: "out/home.png", fullPage: true });
212
137
  */
213
138
  screenshot(options?: ScreenshotOptions): Promise<Buffer>;
214
- private evidence;
215
139
  /** @internal The runner gives each test its own evidence folder */
216
140
  setEvidence(evidence: Evidence | undefined): void;
217
141
  /** Waits `ms` milliseconds. Prefer waiting for something (an assertion, `waitForNetworkIdle`) when you can */
@@ -259,20 +183,6 @@ export default class Page {
259
183
  waitForLoadState(state?: LoadState, options?: {
260
184
  timeout?: number;
261
185
  }): Promise<void>;
262
- private progressOf;
263
- private onDocumentEvent;
264
- private onDomContentLoaded;
265
- private onLoad;
266
- /** Starts recording which navigations reached DOMContentLoaded and load; kept until dispose */
267
- private watchDocumentEvents;
268
- private canBeAborted;
269
- /** Subscribes to what a wait listens for; a browser that lacks the navigationAborted event (Firefox) is asked only once */
270
- private subscribeToDocumentEvents;
271
- private waitForDocumentState;
272
- private networkSettings;
273
- private navigationSettings;
274
- /** The network tracker, created on first use. Rejects with NetworkTrackingDisabledError when config turned tracking off */
275
- private network;
276
186
  /**
277
187
  * Starts following this page's requests now. Tracking only sees requests made after it started, so the
278
188
  * browser calls this when it opens a page; without it, tracking starts on first use. Does nothing when
@@ -310,10 +220,7 @@ export default class Page {
310
220
  * const download = await page.waitForDownload({ trigger: () => link.click() });
311
221
  * const file = await download.path();
312
222
  */
313
- waitForDownload(options?: {
314
- timeout?: number;
315
- trigger?: () => Promise<unknown>;
316
- }): Promise<Download>;
223
+ waitForDownload(options?: WaitOptions): Promise<Download>;
317
224
  /**
318
225
  * Resolves with the next file picker the page opens (a click on an `<input type=file>` or its label). Nothing shows
319
226
  * on screen: answer it with `chooser.setFiles(...)`.
@@ -321,10 +228,7 @@ export default class Page {
321
228
  * const chooser = await page.waitForFileChooser({ trigger: () => page.locator("label[@for='avatar']").click() });
322
229
  * await chooser.setFiles("./fixtures/avatar.png");
323
230
  */
324
- waitForFileChooser(options?: {
325
- timeout?: number;
326
- trigger?: () => Promise<unknown>;
327
- }): Promise<FileChooser>;
231
+ waitForFileChooser(options?: WaitOptions): Promise<FileChooser>;
328
232
  /**
329
233
  * Playwright-style wait for one page event: `download`, `filechooser`, `request` or `response`. Same as the named
330
234
  * `waitFor…` method, with an optional predicate (a function, or `predicate` in the options). Call it before the event
@@ -340,9 +244,6 @@ export default class Page {
340
244
  * `network.collectBodies` calls it when the browser opens the page.
341
245
  */
342
246
  startBodyCollection(): Promise<void>;
343
- /** One Response per network response, whoever asks, so a body is read from the browser once */
344
- private responseFor;
345
- private loadBody;
346
247
  /**
347
248
  * Resolves with the next response of this page whose URL matches (a pattern, see `route`) or that the function
348
249
  * accepts. Call it before the request is made, or pass `trigger`, which runs once the wait is set up.
@@ -350,16 +251,9 @@ export default class Page {
350
251
  * const response = await page.waitForResponse("**\/api/users", { trigger: () => button.click() });
351
252
  * const users = await response.json();
352
253
  */
353
- waitForResponse(match: NetworkMatch<Response>, options?: {
354
- timeout?: number;
355
- trigger?: () => Promise<unknown>;
356
- }): Promise<Response>;
254
+ waitForResponse(match: NetworkMatch<Response>, options?: WaitOptions): Promise<Response>;
357
255
  /** Like `waitForResponse`, for requests */
358
- waitForRequest(match: NetworkMatch<NetworkRequest>, options?: {
359
- timeout?: number;
360
- trigger?: () => Promise<unknown>;
361
- }): Promise<NetworkRequest>;
362
- private waitForNetworkEvent;
256
+ waitForRequest(match: NetworkMatch<NetworkRequest>, options?: WaitOptions): Promise<NetworkRequest>;
363
257
  /**
364
258
  * Resolves with the first `event` `matches` accepts. Listens before `trigger` runs, so what the trigger causes cannot
365
259
  * be missed; a trigger that throws rejects the wait with its error. `onTimeout` builds the error for a wait that ran out.
@@ -367,7 +261,6 @@ export default class Page {
367
261
  private waitForPageEvent;
368
262
  /** Turns the browser's HTTP cache off (`true`) or back on for this page: every request then goes to the server */
369
263
  setCacheDisabled(disabled: boolean): Promise<void>;
370
- private router;
371
264
  /**
372
265
  * Sends requests whose URL matches to `handler`, which must answer with `route.fulfill()`, `route.continue()`,
373
266
  * `route.abort()` or `route.fallback()` (await the answer: a handler that returns first lets the request continue).
@@ -402,12 +295,4 @@ export default class Page {
402
295
  get pageErrorsAllowed(): boolean;
403
296
  /** Starts watching for dialogs; the browser does this when it opens a page, `page.on("dialog")` when needed */
404
297
  startDialogHandling(): Promise<void>;
405
- private ownsContext;
406
- private onPromptOpened;
407
- private onPromptClosed;
408
- /** Lets the listeners answer; a dialog still open afterwards gets the default answer, so nothing hangs */
409
- private dispatchDialog;
410
- /** Captures an image of the given navigable, and returns it as a Base64-encoded string */
411
- captureScreenshot(clip?: BiDiCommands["browsingContext.captureScreenshot"]["params"]["clip"], format?: BiDiCommands["browsingContext.captureScreenshot"]["params"]["format"], origin?: BiDiCommands["browsingContext.captureScreenshot"]["params"]["origin"]): Promise<void>;
412
298
  }
413
- export {};