effect-browser 0.3.0-beta.21 → 0.3.0-beta.22

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 (248) hide show
  1. package/README.md +130 -159
  2. package/dist/Action-24sLOubi.d.mts +110 -0
  3. package/dist/Action.d.mts +2 -0
  4. package/dist/Action.mjs +141 -0
  5. package/dist/Action.mjs.map +1 -0
  6. package/dist/ActionPort.d.mts +15 -0
  7. package/dist/ActionPort.mjs +101 -0
  8. package/dist/ActionPort.mjs.map +1 -0
  9. package/dist/Browser-Cq2K1FEA.mjs +4075 -0
  10. package/dist/Browser-Cq2K1FEA.mjs.map +1 -0
  11. package/dist/{Browser-CiXHT1yO.d.mts → Browser-wZhwZSlG.d.mts} +51 -13
  12. package/dist/Browser.d.mts +2 -2
  13. package/dist/Browser.mjs +1 -1
  14. package/dist/{BrowserError-Coy7EW1N.d.mts → BrowserError-BlcmLVzn.d.mts} +22 -7
  15. package/dist/BrowserError.d.mts +2 -2
  16. package/dist/BrowserError.mjs +46 -9
  17. package/dist/BrowserError.mjs.map +1 -1
  18. package/dist/{BrowserEvent-dq6FRT8w.d.mts → BrowserEvent-lLqJ3GJS.d.mts} +93 -37
  19. package/dist/BrowserEvent.d.mts +2 -2
  20. package/dist/BrowserEvent.mjs +29 -24
  21. package/dist/BrowserEvent.mjs.map +1 -1
  22. package/dist/{Change-DqING3tr.d.mts → Change-Ba7INmay.d.mts} +4 -6
  23. package/dist/Change.d.mts +2 -2
  24. package/dist/Change.mjs +97 -2
  25. package/dist/Change.mjs.map +1 -0
  26. package/dist/Clock.d.mts +57 -0
  27. package/dist/Clock.mjs +80 -0
  28. package/dist/Clock.mjs.map +1 -0
  29. package/dist/{Frame-DkNdjjjr.d.mts → Frame-UEH2hO5T.d.mts} +10 -3
  30. package/dist/Frame.d.mts +2 -2
  31. package/dist/Frame.mjs +10 -2
  32. package/dist/Frame.mjs.map +1 -1
  33. package/dist/{Motion-DND6I-64.d.mts → Geometry-DJx9qrYy.d.mts} +7 -10
  34. package/dist/Geometry.d.mts +2 -0
  35. package/dist/Geometry.mjs +32 -0
  36. package/dist/Geometry.mjs.map +1 -0
  37. package/dist/Matching.d.mts +37 -0
  38. package/dist/Matching.mjs +72 -0
  39. package/dist/Matching.mjs.map +1 -0
  40. package/dist/Page-BF5izr8R.mjs +795 -0
  41. package/dist/Page-BF5izr8R.mjs.map +1 -0
  42. package/dist/{Page-ku6j5t-v.d.mts → Page-CvsOEorc.d.mts} +158 -185
  43. package/dist/Page.d.mts +2 -2
  44. package/dist/Page.mjs +1 -1
  45. package/dist/Released-tURbFmal.d.mts +15 -0
  46. package/dist/{Snapshot-B34hZ4Jl.d.mts → Snapshot-CtBVOtuu.d.mts} +6 -1
  47. package/dist/Snapshot.d.mts +1 -1
  48. package/dist/Snapshot.mjs.map +1 -1
  49. package/dist/Stillness-CNlvayIo.mjs +136 -0
  50. package/dist/Stillness-CNlvayIo.mjs.map +1 -0
  51. package/dist/Style-AO4V7Czt.mjs +357 -0
  52. package/dist/Style-AO4V7Czt.mjs.map +1 -0
  53. package/dist/Style.d.mts +72 -0
  54. package/dist/Style.mjs +2 -0
  55. package/dist/Url.d.mts +26 -0
  56. package/dist/Url.mjs +74 -0
  57. package/dist/Url.mjs.map +1 -0
  58. package/dist/Window-CMddGMt1.d.mts +34 -0
  59. package/dist/Window.d.mts +2 -0
  60. package/dist/Window.mjs +35 -0
  61. package/dist/Window.mjs.map +1 -0
  62. package/dist/{cdp-DL7XfEj5.d.mts → connection-2KHI4_KN.d.mts} +4 -4
  63. package/dist/{cdp-BMpYMWYe.mjs → connection-BTeO0Hiz.mjs} +5 -6
  64. package/dist/connection-BTeO0Hiz.mjs.map +1 -0
  65. package/dist/index.d.mts +15 -18
  66. package/dist/index.mjs +11 -15
  67. package/dist/moment/Moment.d.mts +86 -0
  68. package/dist/{Moment.mjs → moment/Moment.mjs} +44 -38
  69. package/dist/moment/Moment.mjs.map +1 -0
  70. package/dist/{Plan-DJ4hEEna.d.mts → plan/index.d.mts} +169 -64
  71. package/dist/{Plan-BG1WifW2.mjs → plan/index.mjs} +122 -199
  72. package/dist/plan/index.mjs.map +1 -0
  73. package/dist/{Policy-BGWjbqCl.d.mts → policy/Policy.d.mts} +16 -20
  74. package/dist/{Policy.mjs → policy/Policy.mjs} +11 -21
  75. package/dist/policy/Policy.mjs.map +1 -0
  76. package/dist/presentation/Motion.d.mts +12 -0
  77. package/dist/{Motion.mjs → presentation/Motion.mjs} +4 -27
  78. package/dist/presentation/Motion.mjs.map +1 -0
  79. package/dist/presentation/Presentation.d.mts +30 -0
  80. package/dist/presentation/Presentation.mjs +105 -0
  81. package/dist/presentation/Presentation.mjs.map +1 -0
  82. package/dist/{Stage-NHp8N81k.d.mts → presentation/Stage.d.mts} +12 -15
  83. package/dist/{Stage.mjs → presentation/Stage.mjs} +68 -76
  84. package/dist/presentation/Stage.mjs.map +1 -0
  85. package/dist/presentation/feed.d.mts +20 -0
  86. package/dist/presentation/feed.mjs +18 -0
  87. package/dist/presentation/feed.mjs.map +1 -0
  88. package/dist/providers/Cdp.d.mts +9 -0
  89. package/dist/{Cdp.mjs → providers/Cdp.mjs} +3 -8
  90. package/dist/providers/Cdp.mjs.map +1 -0
  91. package/dist/{Chromium.d.mts → providers/Chromium.d.mts} +6 -7
  92. package/dist/{Chromium.mjs → providers/Chromium.mjs} +6 -15
  93. package/dist/providers/Chromium.mjs.map +1 -0
  94. package/dist/providers/Released.d.mts +2 -0
  95. package/dist/providers/Released.mjs +12 -0
  96. package/dist/providers/Released.mjs.map +1 -0
  97. package/dist/stillness/Stillness.d.mts +12 -0
  98. package/dist/stillness/Stillness.mjs +2 -0
  99. package/dist/supervisor/Supervisor.d.mts +104 -0
  100. package/dist/supervisor/Supervisor.mjs +513 -0
  101. package/dist/supervisor/Supervisor.mjs.map +1 -0
  102. package/dist/testing/index.d.mts +337 -0
  103. package/dist/testing/index.mjs +515 -0
  104. package/dist/testing/index.mjs.map +1 -0
  105. package/dist/workerd/Cdp.d.mts +8 -3
  106. package/dist/workerd/Cdp.mjs +2 -7
  107. package/dist/workerd/Cdp.mjs.map +1 -1
  108. package/package.json +86 -36
  109. package/src/Action.ts +127 -0
  110. package/src/ActionPort.ts +128 -0
  111. package/src/Browser.ts +352 -201
  112. package/src/BrowserError.ts +63 -6
  113. package/src/BrowserEvent.ts +26 -25
  114. package/src/Change.ts +0 -2
  115. package/src/{internal/pictures/clock.ts → Clock.ts} +17 -6
  116. package/src/Frame.ts +14 -0
  117. package/src/Geometry.ts +48 -0
  118. package/src/{internal/reading/match.inpage.ts → Matching.ts} +34 -4
  119. package/src/Page.ts +111 -92
  120. package/src/Snapshot.ts +5 -0
  121. package/src/{internal/input/style.ts → Style.ts} +121 -14
  122. package/src/Window.ts +30 -0
  123. package/src/index.ts +15 -6
  124. package/src/internal/input/actions.ts +61 -119
  125. package/src/internal/input/dispatch.ts +3 -3
  126. package/src/internal/input/gate.ts +21 -18
  127. package/src/internal/input/guard.inpage.ts +25 -58
  128. package/src/internal/input/guard.ts +11 -20
  129. package/src/internal/input/keyboard.ts +12 -3
  130. package/src/internal/input/perform.ts +78 -60
  131. package/src/internal/input/pointer.ts +4 -2
  132. package/src/internal/input/settle.ts +7 -5
  133. package/src/internal/input/targets.inpage.ts +1 -1
  134. package/src/internal/input/targets.ts +4 -9
  135. package/src/internal/page/bridge.ts +209 -113
  136. package/src/internal/page/context.ts +12 -59
  137. package/src/internal/page/dialogs.ts +58 -0
  138. package/src/internal/page/lane.ts +14 -15
  139. package/src/internal/page/navigation.ts +50 -42
  140. package/src/internal/page/openings.ts +11 -5
  141. package/src/internal/page/page.ts +44 -81
  142. package/src/internal/page/port.ts +125 -0
  143. package/src/internal/{input → page}/replies.ts +1 -1
  144. package/src/internal/page/request-owner.ts +269 -0
  145. package/src/internal/page/requests.ts +357 -0
  146. package/src/internal/page/scripts.ts +124 -0
  147. package/src/internal/pictures/capture.ts +255 -332
  148. package/src/internal/pictures/dimensions.ts +162 -0
  149. package/src/internal/pictures/frame.ts +68 -0
  150. package/src/internal/pictures/pictures.ts +57 -23
  151. package/src/internal/pictures/quiescence.ts +1 -1
  152. package/src/internal/pictures/state.ts +26 -0
  153. package/src/internal/pictures/transport.ts +21 -4
  154. package/src/internal/reading/controls.inpage.ts +5 -70
  155. package/src/internal/reading/expect.inpage.ts +13 -17
  156. package/src/internal/reading/names.inpage.ts +89 -45
  157. package/src/internal/reading/outline.inpage.ts +6 -7
  158. package/src/internal/reading/reading.ts +144 -176
  159. package/src/internal/reading/ready.inpage.ts +6 -17
  160. package/src/internal/reading/ready.ts +13 -135
  161. package/src/internal/reading/subjects.inpage.ts +83 -43
  162. package/src/internal/reading/walk.inpage.ts +33 -13
  163. package/src/internal/timeline/changes.ts +55 -6
  164. package/src/internal/timeline/events.ts +15 -5
  165. package/src/internal/timeline/history.inpage.ts +1 -1
  166. package/src/internal/timeline/record.inpage.ts +4 -1
  167. package/src/internal/timeline/window.ts +2 -1
  168. package/src/{Moment.ts → moment/Moment.ts} +13 -31
  169. package/src/{internal/timeline → moment}/words.ts +2 -2
  170. package/src/{internal/reading → plan}/choose.ts +3 -3
  171. package/src/plan/data.ts +117 -0
  172. package/src/plan/execute.ts +411 -0
  173. package/src/plan/index.ts +36 -0
  174. package/src/plan/record.ts +71 -0
  175. package/src/plan/targets.ts +71 -0
  176. package/src/{Policy.ts → policy/Policy.ts} +13 -10
  177. package/src/{Motion.ts → presentation/Motion.ts} +12 -46
  178. package/src/presentation/Presentation.ts +176 -0
  179. package/src/{Stage.ts → presentation/Stage.ts} +147 -112
  180. package/src/presentation/feed.ts +21 -0
  181. package/src/{Cdp.ts → providers/Cdp.ts} +2 -2
  182. package/src/{Chromium.ts → providers/Chromium.ts} +7 -10
  183. package/src/providers/Released.ts +13 -0
  184. package/src/{internal/cdp.ts → providers/connection.ts} +2 -2
  185. package/src/{internal/pictures/motion.ts → stillness/Pixels.ts} +1 -1
  186. package/src/stillness/Stillness.ts +166 -0
  187. package/src/supervisor/Supervisor.ts +170 -0
  188. package/src/supervisor/contract.ts +105 -0
  189. package/src/supervisor/lifecycle.ts +272 -0
  190. package/src/supervisor/runtime.ts +234 -0
  191. package/src/testing/TestBrowser.ts +115 -0
  192. package/src/testing/TestPage.ts +10 -0
  193. package/src/testing/evidence.ts +154 -0
  194. package/src/testing/index.ts +3 -0
  195. package/src/testing/model.ts +222 -0
  196. package/src/testing/page.ts +360 -0
  197. package/src/workerd/Cdp.ts +2 -2
  198. package/dist/Browser-CxXUjxOp.mjs +0 -619
  199. package/dist/Browser-CxXUjxOp.mjs.map +0 -1
  200. package/dist/Cdp-CzCRnMlM.d.mts +0 -10
  201. package/dist/Cdp.d.mts +0 -11
  202. package/dist/Cdp.mjs.map +0 -1
  203. package/dist/Change-DNvztNLu.mjs +0 -138
  204. package/dist/Change-DNvztNLu.mjs.map +0 -1
  205. package/dist/Chromium.mjs.map +0 -1
  206. package/dist/Expect-u3P_ENLX.d.mts +0 -62
  207. package/dist/Expect.d.mts +0 -2
  208. package/dist/Expect.mjs +0 -114
  209. package/dist/Expect.mjs.map +0 -1
  210. package/dist/Moment.d.mts +0 -2
  211. package/dist/Moment.mjs.map +0 -1
  212. package/dist/Motion.d.mts +0 -2
  213. package/dist/Motion.mjs.map +0 -1
  214. package/dist/Page-BP02bmNv.mjs +0 -264
  215. package/dist/Page-BP02bmNv.mjs.map +0 -1
  216. package/dist/Plan-BG1WifW2.mjs.map +0 -1
  217. package/dist/Plan.d.mts +0 -2
  218. package/dist/Plan.mjs +0 -2
  219. package/dist/Policy.d.mts +0 -2
  220. package/dist/Policy.mjs.map +0 -1
  221. package/dist/Presentation-DxVikn9_.d.mts +0 -48
  222. package/dist/Presentation.d.mts +0 -2
  223. package/dist/Presentation.mjs +0 -118
  224. package/dist/Presentation.mjs.map +0 -1
  225. package/dist/Stage.d.mts +0 -2
  226. package/dist/Stage.mjs.map +0 -1
  227. package/dist/Supervisor-2mPjIYYs.mjs +0 -676
  228. package/dist/Supervisor-2mPjIYYs.mjs.map +0 -1
  229. package/dist/Supervisor-CfRxbaso.d.mts +0 -317
  230. package/dist/Supervisor.d.mts +0 -2
  231. package/dist/Supervisor.mjs +0 -2
  232. package/dist/cdp-BMpYMWYe.mjs.map +0 -1
  233. package/dist/context-EGhOqjNN.mjs +0 -335
  234. package/dist/context-EGhOqjNN.mjs.map +0 -1
  235. package/dist/page-PTM8m5wC.mjs +0 -4057
  236. package/dist/page-PTM8m5wC.mjs.map +0 -1
  237. package/dist/url-Bsp2y55M.mjs +0 -264
  238. package/dist/url-Bsp2y55M.mjs.map +0 -1
  239. package/dist/workerd/index.d.mts +0 -16
  240. package/dist/workerd/index.mjs +0 -17
  241. package/src/Expect.ts +0 -180
  242. package/src/Plan.ts +0 -674
  243. package/src/Presentation.ts +0 -196
  244. package/src/Supervisor.ts +0 -632
  245. package/src/internal/supervisor/lifecycle.ts +0 -484
  246. package/src/workerd/index.ts +0 -17
  247. /package/src/{internal/page/url.ts → Url.ts} +0 -0
  248. /package/src/{internal/pictures → stillness}/utilsBundle.d.ts +0 -0
package/src/Page.ts CHANGED
@@ -2,12 +2,12 @@
2
2
  * One browser tab: navigation, snapshots, pictures and input.
3
3
  *
4
4
  * A page waits only for itself: its operations take turns in one lane of its own. An action, which
5
- * sends input or navigates, has the page to itself, in the order actions were asked; reads share
5
+ * sends input or navigates, has the page to itself, in the order admitted after policy approval; reads share
6
6
  * it, after the action in flight and every action asked before them, so a read describes the page
7
7
  * an action left. A wait for a turn ends at the operation's deadline as `Busy`, never `Timeout`,
8
8
  * and a full deadline then bounds the operation itself; `failFast` fails it at once instead.
9
9
  * Identical reads asked between the same actions share one call to the page, and one whose
10
- * callers gave up finishes for the next caller to ask it. A policy holds outside the lane while
10
+ * callers gave up finishes for the next caller to ask it within 250 ms. A policy holds outside the lane while
11
11
  * other operations continue; its target is revalidated before dispatch. Element targets are refs
12
12
  * from a snapshot; point targets are viewport coordinates in CSS pixels, the same coordinates as a
13
13
  * screenshot's pixels. Mouse and keyboard input share a bounded pipeline, so pacing does not wait
@@ -15,20 +15,26 @@
15
15
  *
16
16
  * @since 0.3.0
17
17
  */
18
- import { type Duration, Effect, Schema, type Stream } from "effect";
19
- import type { Page as PlaywrightPage } from "playwright-core";
20
-
18
+ import { type Clock, type Duration, Effect, Schema, type Scope, type Stream } from "effect";
19
+
20
+ import {
21
+ Action,
22
+ type ClickOptions as ClickOptionsSchema,
23
+ type TypeOptions as TypeOptionsSchema,
24
+ type PressOptions as PressOptionsSchema,
25
+ type ScrollOptions as ScrollOptionsSchema,
26
+ } from "./Action.ts";
21
27
  import { type BrowserError, type PolicyDenied } from "./BrowserError.ts";
22
28
  import { Box, type BrowserEvent, PageLoaded, Subject } from "./BrowserEvent.ts";
23
29
  import type { Changes } from "./Change.ts";
24
30
  import { type CaptureStats, Frame, Image, type ScreencastOptions } from "./Frame.ts";
31
+ import * as Motion from "./Geometry.ts";
25
32
  import { FormFieldSchema } from "./internal/input/evidence.inpage.ts";
26
33
  import * as Guard from "./internal/input/guard.inpage.ts";
27
34
  import { Correlation, FailFast } from "./internal/page/lane.ts";
28
- import * as Url from "./internal/page/url.ts";
29
- import type { Window } from "./Moment.ts";
30
- import * as Motion from "./Motion.ts";
31
35
  import { type Snapshot, type SnapshotOptions } from "./Snapshot.ts";
36
+ import * as Url from "./Url.ts";
37
+ import type { Window } from "./Window.ts";
32
38
 
33
39
  export type Point = Motion.Point;
34
40
 
@@ -61,46 +67,11 @@ export class ResolvedTarget extends Schema.Class<ResolvedTarget>("effect-browser
61
67
  href: Schema.optional(Schema.String),
62
68
  }) {}
63
69
 
64
- export interface ClickOptions {
65
- readonly button?: "left" | "right" | "middle" | undefined;
66
- /** 2 for a double click. */
67
- readonly clickCount?: number | undefined;
68
- /** Hold the button down this long before releasing it. */
69
- readonly holdMillis?: number | undefined;
70
- }
71
-
72
- export interface TypeOptions {
73
- /** Type into this text field: it is focused first, and its content replaced unless `replace` is false. */
74
- readonly into?: string | undefined;
75
- readonly replace?: boolean | undefined;
76
- /** Press Enter afterwards. */
77
- readonly submit?: boolean | undefined;
78
- /**
79
- * The text is a secret: type it only into a field the page marks secret, such as a password,
80
- * and otherwise refuse with `NotActionable` before any input. A replayed password asks this.
81
- */
82
- readonly secret?: boolean | undefined;
83
- }
84
-
85
- export interface PressOptions {
86
- /**
87
- * Focus this element, by ref, before the first press: a link, a button or a field. The keys go to
88
- * whatever has focus otherwise.
89
- */
90
- readonly on?: string | undefined;
91
- /** Press the keys this many times. */
92
- readonly times?: number | undefined;
93
- /** Hold the keys down this long before releasing them, as a game control might need. */
94
- readonly holdMillis?: number | undefined;
95
- }
96
-
97
- export interface ScrollOptions {
98
- readonly dx?: number | undefined;
99
- /** Pixels to scroll down; negative scrolls up. Defaults to most of a viewport. */
100
- readonly dy?: number | undefined;
101
- /** Scroll whatever is under this point or element. Defaults to the middle of the viewport. */
102
- readonly at?: Target | undefined;
103
- }
70
+ /** Action options share the execution codec. */
71
+ export type ClickOptions = typeof ClickOptionsSchema.Type;
72
+ export type TypeOptions = typeof TypeOptionsSchema.Type;
73
+ export type PressOptions = typeof PressOptionsSchema.Type;
74
+ export type ScrollOptions = typeof ScrollOptionsSchema.Type;
104
75
 
105
76
  /**
106
77
  * How current a picture must be. The newest screencast frame serves when it qualifies, at no cost;
@@ -130,6 +101,11 @@ export interface ScreenshotOptions {
130
101
  readonly quality?: number | undefined;
131
102
  /** `"jpeg"`, the default, or `"png"`, which is always a new picture. */
132
103
  readonly format?: "jpeg" | "png" | undefined;
104
+ /**
105
+ * `"css"`, the default, a picture pixel per CSS pixel; `"device"`, the screen's own pixels, as
106
+ * many to a CSS pixel as its device scale factor, which is always a new picture.
107
+ */
108
+ readonly scale?: "css" | "device" | undefined;
133
109
  }
134
110
 
135
111
  /**
@@ -137,6 +113,10 @@ export interface ScreenshotOptions {
137
113
  * that has a role or is a control.
138
114
  */
139
115
  export interface FindQuery {
116
+ /** Narrow matching to this CSS selector. Invalid CSS fails InvalidRequest. */
117
+ readonly selector?: string | undefined;
118
+ /** Require a visible match, optionally enabled. */
119
+ readonly state?: "visible" | "enabled" | undefined;
140
120
  /** An ARIA role, such as `"button"` or `"heading"`, ignoring case. */
141
121
  readonly role?: string | undefined;
142
122
  /**
@@ -204,26 +184,8 @@ export class Text extends Schema.Class<Text>("effect-browser/Text")({
204
184
  at: Schema.Finite,
205
185
  }) {}
206
186
 
207
- /** What `waitFor` waits for. */
208
- export interface WaitCondition {
209
- /** A CSS selector for what to watch; the document's body without one. */
210
- readonly selector?: string | undefined;
211
- /**
212
- * `"visible"` (the default): something it matches shows; `"hidden"`: nothing it matches shows;
213
- * `"enabled"`: something it matches shows and is not disabled.
214
- */
215
- readonly state?: "visible" | "hidden" | "enabled" | undefined;
216
- /** Only what shows this text counts, case and all, with runs of spaces read as one. */
217
- readonly text?: string | undefined;
218
- }
219
-
220
187
  export interface ReadyOptions {
221
- /**
222
- * What must stay still during quietMillis: screen paint (default); recorded content; or the
223
- * `"foreground"`, the screen but for what was already moving before the page's latest input.
224
- */
225
- readonly still?: "screen" | "content" | "foreground" | undefined;
226
- /** How long the selected evidence must stay still; screen paint by default. */
188
+ /** How long recorded content must stay unchanged. Screen stillness is a separate feature. */
227
189
  readonly quietMillis?: number | undefined;
228
190
  readonly timeout?: Duration.Input | undefined;
229
191
  }
@@ -270,6 +232,8 @@ export interface WindowOptions {
270
232
  */
271
233
  export class State extends Schema.Class<State>("effect-browser/PageState")({
272
234
  page: Schema.String,
235
+ /** The tracking connection that owns this document counter. */
236
+ connection: Schema.String,
273
237
  /** When this was taken. */
274
238
  at: Schema.Finite,
275
239
  /** Where the main frame last committed or moved, without userinfo or known secret parameters. */
@@ -326,7 +290,7 @@ export class InputRequest extends Schema.Class<InputRequest>("effect-browser/Inp
326
290
  url: Schema.String,
327
291
  /** The page's title, at most 120 characters. */
328
292
  title: Schema.String,
329
- action: Schema.String,
293
+ action: Action,
330
294
  target: Schema.optional(Schema.String),
331
295
  element: Schema.optional(Schema.String),
332
296
  /** Literal pixel targets only; ref coordinates are resolved after the policy allows them. */
@@ -384,11 +348,76 @@ export const correlate =
384
348
  /** Succeed to allow, fail to deny, or await an external signal to hold the input. */
385
349
  export type InputGuard = (request: InputRequest) => Effect.Effect<void, PolicyDenied>;
386
350
 
351
+ /** What a wait requires of the query's matches. */
352
+ export type UntilWant = "some" | "none" | { readonly other: string };
353
+
354
+ export interface UntilResult {
355
+ readonly met: boolean;
356
+ readonly mark: string;
357
+ }
358
+
359
+ /** Scoped access to one page's shared capture and its current-document evidence. */
360
+ export interface Capture {
361
+ readonly stream: Stream.Stream<Frame, BrowserError>;
362
+ readonly current: Frame | undefined;
363
+ readonly isCurrent: (frame: Frame) => boolean;
364
+ readonly confirm: (frame: Frame) => Effect.Effect<boolean, BrowserError>;
365
+ readonly sync: Effect.Effect<void, BrowserError>;
366
+ readonly stats: (options?: {
367
+ readonly window?: Duration.Input | undefined;
368
+ }) => Effect.Effect<CaptureStats, BrowserError>;
369
+ }
370
+
371
+ /** Script values cross the page boundary through the caller's Schema. A bundler may rewrite functions. */
372
+ export interface ScriptOptions<A, Arg> {
373
+ readonly arg: Arg;
374
+ readonly result: Schema.Codec<A, unknown>;
375
+ }
376
+
377
+ export interface ActOptions<A, Arg> extends ScriptOptions<A, Arg> {
378
+ readonly document: number;
379
+ /** Supplying the read's connection also refuses a document counter from another connection. */
380
+ readonly connection?: string | undefined;
381
+ }
382
+
387
383
  export interface Page {
384
+ /** Decode and perform a data action through the same policy and lane as the named methods. */
385
+ readonly perform: (action: Action) => Effect.Effect<ResolvedTarget | string | void, BrowserError>;
386
+ /** Read declared side-effect-free code in the main world, retrying one replaced document. */
387
+ readonly read: <A, Arg>(
388
+ script: (arg: Arg) => unknown,
389
+ options: ScriptOptions<A, Arg>,
390
+ ) => Effect.Effect<
391
+ { readonly value: A; readonly document: number; readonly connection: string },
392
+ BrowserError
393
+ >;
394
+ /**
395
+ * Run code as a guarded, recorded action bound to the caller's document.
396
+ * A timeout or cancellation cannot stop JavaScript already running: later input waits for its
397
+ * actual reply. Close the page and open a replacement if the script never settles.
398
+ */
399
+ readonly act: <A, Arg>(
400
+ script: (arg: Arg) => unknown,
401
+ options: ActOptions<A, Arg>,
402
+ ) => Effect.Effect<A, BrowserError>;
403
+ /** Owning browser clock: deadlines and all frame/event timestamps use this clock. */
404
+ readonly clock: Clock.Clock;
405
+ /** Wait for admitted input and retain a bounded read turn through effect. */
406
+ readonly afterInput: <A, E, R>(
407
+ effect: Effect.Effect<A, E, R>,
408
+ ) => Effect.Effect<A, E | BrowserError, R>;
409
+ /** A scoped lease starts capture immediately, independently of its first frame. */
410
+ readonly capture: (
411
+ options?: ScreencastOptions,
412
+ ) => Effect.Effect<Capture, BrowserError, Scope.Scope>;
413
+ /** One page-side wait; replaced documents share one deadline. Unmet is met:false; an empty mark means no stable document could be sampled. */
414
+ readonly until: (
415
+ query: FindQuery,
416
+ want: UntilWant,
417
+ millis: number,
418
+ ) => Effect.Effect<UntilResult, BrowserError>;
388
419
  /** The page's CDP target id: the same page has it again after a reconnect to its browser. */
389
420
  readonly id: string;
390
- /** The Playwright page, for anything this API does not cover. Never give it to a model. */
391
- readonly playwright: PlaywrightPage;
392
421
  /** The page's address, without its userinfo or known secret parameters. */
393
422
  readonly url: Effect.Effect<string>;
394
423
  /**
@@ -417,8 +446,14 @@ export interface Page {
417
446
  * screenshot timed by the host interval in which it was taken.
418
447
  */
419
448
  readonly frame: (options?: FrameOptions) => Effect.Effect<Frame, BrowserError>;
420
- /** A crop in CSS pixels, unmagnified, with the origin that keeps later input in viewport pixels. */
421
- readonly zoom: (region: Region) => Effect.Effect<Zoom, BrowserError>;
449
+ /**
450
+ * A crop in CSS pixels, unmagnified, with the origin that keeps later input in viewport pixels.
451
+ * With `scale: "device"` its picture has the screen's own pixels, as a screenshot's would.
452
+ */
453
+ readonly zoom: (
454
+ region: Region,
455
+ options?: Pick<ScreenshotOptions, "scale">,
456
+ ) => Effect.Effect<Zoom, BrowserError>;
422
457
  /**
423
458
  * The viewport's size in CSS pixels, the space of points, crops and page scrolls. Over CDP the
424
459
  * page reports it, within the action timeout.
@@ -478,26 +513,10 @@ export interface Page {
478
513
  ) => Effect.Effect<string, BrowserError>;
479
514
 
480
515
  /**
481
- * Wait until a condition holds, in one call that the page answers as it comes, looking every
482
- * 100 ms, or `Timeout` after `timeout`, 10 seconds by default. A selector that is not CSS is an
483
- * `InvalidRequest`.
484
- */
485
- readonly waitFor: (
486
- condition: WaitCondition,
487
- timeout?: Duration.Input,
488
- ) => Effect.Effect<void, BrowserError>;
489
- /**
490
- * Wait until the page is ready to be shown, asking the page every 100 ms: its document is parsed
491
- * and has painted since, nothing that ends is animating in view, its fonts and the images in
492
- * view have loaded, and the viewport shows something. With `quietMillis`, the screen must then
493
- * also stay still that long: nothing in view changed, where the page's changes are recorded, and
494
- * no frame comes, counted from the first frame of a capture the wait starts itself. A canvas
495
- * that keeps drawing, such as a live chart, is never still. With `still: "foreground"`, frames
496
- * may keep coming, but nothing may move in them outside what moved in the frames of the 1.5 s
497
- * before the page's latest input, such as an idle animation; reels set spinning, or a counter
498
- * set rolling, by the input keep the wait going. Without those frames, as where they are older
499
- * than the browser's `frameHistory`, nothing may move at all. A page is never ready without a
500
- * painted frame, as a hidden tab may be. `Timeout` after `timeout`, 15 seconds by default.
516
+ * Wait for document evidence, polling every 50 ms: parsed, painted, visible, fonts and visible
517
+ * images loaded, and finite animations finished. Optional quietMillis requires recorded content
518
+ * to stay unchanged. Screen or foreground stillness belongs to the Stillness feature.
519
+ * Fails Timeout after timeout, 15 seconds by default.
501
520
  */
502
521
  readonly ready: (options?: ReadyOptions) => Effect.Effect<void, BrowserError>;
503
522
 
package/src/Snapshot.ts CHANGED
@@ -86,4 +86,9 @@ export interface SnapshotOptions {
86
86
  readonly within?: string | undefined;
87
87
  /** Bound on the outline's length. Defaults to 12,000 characters. */
88
88
  readonly maxChars?: number | undefined;
89
+ /**
90
+ * Give every control's box, as `WxH at (x,y)` in viewport CSS pixels, as a canvas's or a frame's
91
+ * always has. Defaults to false.
92
+ */
93
+ readonly boxes?: boolean | undefined;
89
94
  }
@@ -4,11 +4,21 @@
4
4
  * actions take one, and the input reaches the same controls either way; only its timing, and
5
5
  * what viewers see of it, differ. A presenter builds the performed one.
6
6
  */
7
- import { Effect, type MutableRef, type Option, Random } from "effect";
7
+ import {
8
+ Context,
9
+ type Duration,
10
+ Effect,
11
+ type MutableRef,
12
+ type Option,
13
+ Random,
14
+ Schema,
15
+ } from "effect";
8
16
 
9
- import type * as Motion from "../../Motion.ts";
10
- import type { Point } from "../../Page.ts";
11
- import * as Keys from "./keys.ts";
17
+ import { undispatched, type BrowserError, InvalidRequest, refuse } from "./BrowserError.ts";
18
+ import type * as Motion from "./Geometry.ts";
19
+ import { normal } from "./Geometry.ts";
20
+ import * as Keys from "./internal/input/keys.ts";
21
+ import type { Point } from "./Page.ts";
12
22
 
13
23
  export interface TypingEvent {
14
24
  /** From the start of the typing. */
@@ -25,6 +35,14 @@ export interface WheelStep {
25
35
  }
26
36
 
27
37
  export interface Style {
38
+ /** Own presentation only after policy allows input; wait options belong to the page. */
39
+ readonly withInput?:
40
+ | ((options: {
41
+ readonly operation: string;
42
+ readonly wait: Duration.Duration;
43
+ readonly failFast: boolean;
44
+ }) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | BrowserError, R>)
45
+ | undefined;
28
46
  /**
29
47
  * Whether viewers watch the input: then the pointer clicks into a field before typing, finds
30
48
  * what lies under it as it scrolls, and scrolls to a target out of view with the wheel.
@@ -39,13 +57,16 @@ export interface Style {
39
57
  dragging: boolean,
40
58
  ) => Effect.Effect<ReadonlyArray<Motion.Sample>>;
41
59
  /** How long a button stays down when a click does not say. */
42
- readonly hold: Effect.Effect<number>;
60
+ readonly hold: Effect.Effect<number, BrowserError>;
43
61
  /** The key events that type `text`, or one insertion of it under a guard, timed from the start. */
44
- readonly typing: (text: string, guarded: boolean) => Effect.Effect<ReadonlyArray<TypingEvent>>;
62
+ readonly typing: (
63
+ text: string,
64
+ guarded: boolean,
65
+ ) => Effect.Effect<ReadonlyArray<TypingEvent>, BrowserError>;
45
66
  /** The pause between repeated presses of the same keys. */
46
- readonly keyGap: Effect.Effect<number>;
67
+ readonly keyGap: Effect.Effect<number, BrowserError>;
47
68
  /** A wheel scroll as the wheel turns: in one step, or in notches and bursts. */
48
- readonly wheel: (dx: number, dy: number) => Effect.Effect<ReadonlyArray<WheelStep>>;
69
+ readonly wheel: (dx: number, dy: number) => Effect.Effect<ReadonlyArray<WheelStep>, BrowserError>;
49
70
  }
50
71
 
51
72
  /** Each key as it comes, with no pause; a drag moves in eight short steps so its target sees it. */
@@ -88,10 +109,7 @@ const lognormal = Effect.fnUntraced(function* (
88
109
  minimum: number,
89
110
  maximum: number,
90
111
  ) {
91
- const radius = Math.sqrt(-2 * Math.log(1 - (yield* Random.next)));
92
- const normal = radius * Math.cos(2 * Math.PI * (yield* Random.next));
93
-
94
- return Math.max(minimum, Math.min(maximum, median * Math.exp(sigma * normal)));
112
+ return Math.max(minimum, Math.min(maximum, median * Math.exp(sigma * (yield* normal))));
95
113
  });
96
114
 
97
115
  /** A pause around `median`, as the research measured reactions: at most four times it. */
@@ -110,16 +128,87 @@ const eventOrder = { up: 0, insert: 1, down: 2 };
110
128
  * to reach the keys, each later one follows the last by a gap drawn around `gap`, and a word's
111
129
  * first key comes 60 ms later.
112
130
  */
131
+ export const maximumDurationMillis = 10_000;
132
+
133
+ const Delay = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: maximumDurationMillis }));
134
+
135
+ const ordered = <A extends { readonly afterMillis: number }>(sample: Schema.Codec<A>) =>
136
+ Schema.Array(sample).check(
137
+ Schema.makeFilter(
138
+ (samples) =>
139
+ samples.every(
140
+ (event, index) => event.afterMillis >= (samples[index - 1]?.afterMillis ?? 0),
141
+ ),
142
+ { expected: "nondecreasing input offsets" },
143
+ ),
144
+ );
145
+
146
+ const Typing = ordered(
147
+ Schema.Struct({
148
+ afterMillis: Delay,
149
+ phase: Schema.Literals(["down", "up", "insert"]),
150
+ key: Schema.String,
151
+ }),
152
+ ).check(
153
+ Schema.makeFilter(
154
+ (events) => {
155
+ const held = new Set<string>();
156
+
157
+ for (const event of events) {
158
+ if (event.phase === "insert") continue;
159
+ const code = Keys.description(event.key)?.code;
160
+
161
+ if (code === undefined || (event.phase === "down") === held.has(code)) return false;
162
+ if (event.phase === "down") held.add(code);
163
+ else held.delete(code);
164
+ }
165
+
166
+ return held.size === 0;
167
+ },
168
+ { expected: "matched key holds" },
169
+ ),
170
+ );
171
+
172
+ const Wheel = ordered(Schema.Struct({ afterMillis: Delay, dx: Schema.Finite, dy: Schema.Finite }));
173
+
174
+ const decode =
175
+ <A>(schema: Schema.Codec<A>, operation: string) =>
176
+ (value: unknown) =>
177
+ Schema.decodeUnknownEffect(schema)(value).pipe(
178
+ Effect.catch(() =>
179
+ refuse(operation, "style must provide a finite bounded ordered input schedule"),
180
+ ),
181
+ );
182
+
183
+ /** Copy and validate custom schedules before their first input; planning uses the action bound. */
184
+ export const validated = (style: Style): Style => ({
185
+ ...style,
186
+ hold: style.hold.pipe(Effect.flatMap(decode(Delay, "click"))),
187
+ keyGap: style.keyGap.pipe(Effect.flatMap(decode(Delay, "press"))),
188
+ typing: (text, guarded) =>
189
+ style.typing(text, guarded).pipe(Effect.flatMap(decode(Typing, "type"))),
190
+ wheel: (dx, dy) => style.wheel(dx, dy).pipe(Effect.flatMap(decode(Wheel, "scroll"))),
191
+ });
192
+
193
+ const overBudget = (operation: string) =>
194
+ undispatched(
195
+ operation,
196
+ new InvalidRequest({
197
+ detail: `presentation must take at most ${maximumDurationMillis} milliseconds`,
198
+ }),
199
+ );
200
+
113
201
  const typing = Effect.fnUntraced(function* (
114
202
  text: string,
115
203
  gap: number,
116
- ): Effect.fn.Return<ReadonlyArray<TypingEvent>> {
204
+ ): Effect.fn.Return<ReadonlyArray<TypingEvent>, BrowserError> {
117
205
  const events: Array<TypingEvent> = [];
118
206
  const releases = new Map<string, number>();
119
207
  let due = text === "" ? 0 : yield* Random.nextBetween(150, 400);
120
208
  let previous = "";
121
209
 
122
210
  for (const character of text) {
211
+ if (due > maximumDurationMillis) return yield* overBudget("type");
123
212
  if (/\s/u.test(previous) && /[\p{L}\p{N}]/u.test(character)) due += 60;
124
213
  const description = Keys.description(character);
125
214
 
@@ -139,6 +228,9 @@ const typing = Effect.fnUntraced(function* (
139
228
  previous = character;
140
229
  }
141
230
 
231
+ if (events.some((event) => event.afterMillis > maximumDurationMillis))
232
+ return yield* overBudget("type");
233
+
142
234
  return events.toSorted(
143
235
  (left, right) =>
144
236
  left.afterMillis - right.afterMillis || eventOrder[left.phase] - eventOrder[right.phase],
@@ -154,12 +246,16 @@ export const keyGap = (wordsPerMinute: number) => 12_000 / wordsPerMinute - 10;
154
246
  */
155
247
  const bursts = Effect.fnUntraced(function* (dx: number, dy: number) {
156
248
  const notches = Math.max(1, Math.ceil(Math.hypot(dx, dy) / 100));
249
+
250
+ // Even the shortest possible schedule exceeds the cap; refuse before allocating it.
251
+ if (notches > 1 + maximumDurationMillis / 30) return yield* overBudget("scroll");
157
252
  const steps: Array<WheelStep> = [];
158
253
  let due = 0;
159
254
 
160
255
  for (let index = 0; index < notches; index++) {
161
256
  if (index > 0)
162
257
  due += yield* index % 9 === 0 ? Random.nextBetween(600, 2600) : Random.nextBetween(30, 140);
258
+ if (due > maximumDurationMillis) return yield* overBudget("scroll");
163
259
  steps.push({ dx: dx / notches, dy: dy / notches, afterMillis: due });
164
260
  }
165
261
 
@@ -169,7 +265,7 @@ const bursts = Effect.fnUntraced(function* (dx: number, dy: number) {
169
265
  /** Input performed for viewers, with this pointer and pace. */
170
266
  export const performed = (options: {
171
267
  readonly pointer: MutableRef.MutableRef<Option.Option<Point>>;
172
- readonly motion: Motion.Service;
268
+ readonly motion: Motion.Planner;
173
269
  readonly wordsPerMinute: number;
174
270
  }): Style => {
175
271
  const gap = keyGap(options.wordsPerMinute);
@@ -184,3 +280,14 @@ export const performed = (options: {
184
280
  wheel: bursts,
185
281
  };
186
282
  };
283
+
284
+ /** Input style in this fiber; plain input is the default. */
285
+ export const Current = Context.Reference<Style>("effect-browser/Style", {
286
+ defaultValue: () => plain,
287
+ });
288
+
289
+ /** Apply a style through page input, including pages selected later by a browser adapter. */
290
+ export const provide =
291
+ (style: Style) =>
292
+ <A, E, R>(effect: Effect.Effect<A, E, R>) =>
293
+ Effect.provideService(effect, Current, style);
package/src/Window.ts ADDED
@@ -0,0 +1,30 @@
1
+ /** A bounded window of a page's events, visible changes and frames on the owning clock. */
2
+ import { Schema } from "effect";
3
+
4
+ import { BrowserError } from "./BrowserError.ts";
5
+ import { BrowserEvent } from "./BrowserEvent.ts";
6
+ import { Changes } from "./Change.ts";
7
+ import { Frame } from "./Frame.ts";
8
+
9
+ /** A page's events, changes and frames over one window of its browser's host clock. */
10
+ export class Window extends Schema.Class<Window>("effect-browser/Window")({
11
+ page: Schema.String,
12
+ /** Where the window starts, in host monotonic milliseconds on the owning browser’s clock. */
13
+ since: Schema.Finite,
14
+ /** Where it ends, never after it was taken. */
15
+ until: Schema.Finite,
16
+ /** The page's events after `since`, up to `until`, oldest first, without the input presentation track. */
17
+ events: Schema.Array(BrowserEvent),
18
+ /**
19
+ * What visibly changed after `since`, up to `until`; absent where `missing` says why. A page's
20
+ * first window starts its record, so the record sees none of it.
21
+ */
22
+ changes: Schema.optional(Changes),
23
+ /** Screencast frames painted from `since` to `until`, oldest first, as far back as kept. */
24
+ frames: Schema.Array(Frame),
25
+ /**
26
+ * Why each part that could not be read is missing: the read of its changes, by whatever
27
+ * operation failed there, or a moment's picture (`frame`) or outline (`snapshot`).
28
+ */
29
+ missing: Schema.Array(BrowserError),
30
+ }) {}
package/src/index.ts CHANGED
@@ -1,6 +1,15 @@
1
- /**
2
- * @since 0.3.0
3
- */
4
- export * from "./workerd/index.ts";
5
- export * as Cdp from "./Cdp.ts";
6
- export * as Chromium from "./Chromium.ts";
1
+ /** The browser kernel. Providers and optional features have explicit subpaths. */
2
+ export * as Action from "./Action.ts";
3
+ export * as ActionPort from "./ActionPort.ts";
4
+ export * as Browser from "./Browser.ts";
5
+ export * as BrowserError from "./BrowserError.ts";
6
+ export * as BrowserEvent from "./BrowserEvent.ts";
7
+ export * as Change from "./Change.ts";
8
+ export * as Clock from "./Clock.ts";
9
+ export * as Frame from "./Frame.ts";
10
+ export * as Geometry from "./Geometry.ts";
11
+ export * as Page from "./Page.ts";
12
+ export * as Snapshot from "./Snapshot.ts";
13
+ export * as Style from "./Style.ts";
14
+ export * as Window from "./Window.ts";
15
+ export * as Url from "./Url.ts";