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
@@ -8,9 +8,10 @@
8
8
  *
9
9
  * @since 0.3.0
10
10
  */
11
- import { Schema } from "effect";
11
+ import { Effect, Schema } from "effect";
12
12
 
13
13
  import { DisconnectCause } from "./BrowserEvent.ts";
14
+ import * as Url from "./Url.ts";
14
15
 
15
16
  /** The operation did not finish in time. */
16
17
  export class Timeout extends Schema.TaggedError<Timeout>()("Timeout", {
@@ -162,6 +163,13 @@ export class Failed extends Schema.TaggedError<Failed>()("Failed", {
162
163
  }
163
164
  }
164
165
 
166
+ /** Caller code threw in the page's main world. Its source and payload stay private. */
167
+ export class Threw extends Schema.TaggedError<Threw>()("Threw", {}) {
168
+ override get message() {
169
+ return "the page script threw";
170
+ }
171
+ }
172
+
165
173
  export const Reason = Schema.Union([
166
174
  Timeout,
167
175
  Busy,
@@ -177,6 +185,7 @@ export const Reason = Schema.Union([
177
185
  PolicyTimeout,
178
186
  EventHistoryExpired,
179
187
  Failed,
188
+ Threw,
180
189
  ]);
181
190
 
182
191
  export type Reason = typeof Reason.Type;
@@ -195,7 +204,7 @@ export class BrowserError extends Schema.TaggedError<BrowserError>()("BrowserErr
195
204
  * What a failure leaves. `lost` is `"page"` when the page is gone and its browser stands, and
196
205
  * `"session"` when the browser is gone with its pages. `repeat` says whether the call can be made
197
206
  * again, on what still stands: `"safe"`, as nothing reached the browser; `"check"`, as it may have
198
- * taken effect, so look first, as an `Expect` attempt does; `"pointless"`, as it fails again unless
207
+ * taken effect, so look first, as a Plan expectation does; `"pointless"`, as it fails again unless
199
208
  * something changes, such as
200
209
  * a new ref; or `"resume"`, reading events again from a newer cursor.
201
210
  */
@@ -214,6 +223,8 @@ export const consequence = ({ reason, dispatched }: BrowserError): Consequence =
214
223
  lost: reason.cause === "page" || reason.cause === "crashed" ? "page" : "session",
215
224
  repeat,
216
225
  };
226
+ case "Limit":
227
+ case "PolicyTimeout":
217
228
  case "Busy":
218
229
  case "Suspended":
219
230
  case "Timeout":
@@ -221,14 +232,60 @@ export const consequence = ({ reason, dispatched }: BrowserError): Consequence =
221
232
  case "NavigationFailed":
222
233
  return { lost: "nothing", repeat };
223
234
  case "EventHistoryExpired":
224
- return { lost: "nothing", repeat: "resume" };
235
+ return { lost: "nothing", repeat: dispatched ? "check" : "resume" };
236
+ case "Threw":
225
237
  case "StaleRef":
226
238
  case "NotFound":
227
239
  case "NotActionable":
228
240
  case "InvalidRequest":
229
- case "Limit":
230
241
  case "PolicyDenied":
231
- case "PolicyTimeout":
232
- return { lost: "nothing", repeat: "pointless" };
242
+ return { lost: "nothing", repeat: dispatched ? "check" : "pointless" };
233
243
  }
234
244
  };
245
+
246
+ /** A failure before any of the operation's input reached the page. */
247
+ export const undispatched = (operation: string, reason: Reason) =>
248
+ new BrowserError({ operation, reason, dispatched: false });
249
+
250
+ /** Fail an operation before dispatch, preserving its typed reason. */
251
+ export const failWith = (operation: string, reason: Reason) =>
252
+ Effect.fail(undispatched(operation, reason));
253
+
254
+ /** Refuse an invalid request before sending anything. */
255
+ export const refuse = (operation: string, detail: string) =>
256
+ failWith(operation, new InvalidRequest({ detail }));
257
+
258
+ /** Translate a protocol/provider failure, redacting diagnostic addresses by default. */
259
+ export const reasonOf = (
260
+ cause: unknown,
261
+ timeoutMillis?: number,
262
+ closed: Closed["cause"] = "connection",
263
+ redact: (message: string) => string = Url.redactWithin,
264
+ ): Reason => {
265
+ const message =
266
+ cause instanceof Error ? cause.message : typeof cause === "string" ? cause : "unknown error";
267
+
268
+ if (
269
+ /has been closed|Target closed|Session closed|browser has disconnected|Target page, context or browser/i.test(
270
+ message,
271
+ )
272
+ )
273
+ return new Closed({ cause: closed });
274
+ if (cause instanceof Error && cause.name === "TimeoutError" && timeoutMillis !== undefined)
275
+ return new Timeout({ millis: timeoutMillis });
276
+ const line = redact(message).split("\n")[0] ?? "unknown error";
277
+
278
+ return new Failed({ detail: line.replace(/^[\w.]+: /, "") });
279
+ };
280
+
281
+ /** A native call whose action wrapper owns any later dispatch evidence. */
282
+ export const call = <A>(
283
+ operation: string,
284
+ run: () => Promise<A>,
285
+ closedBy: () => Closed["cause"],
286
+ timeoutMillis?: number,
287
+ ) =>
288
+ Effect.tryPromise({
289
+ try: run,
290
+ catch: (cause) => undispatched(operation, reasonOf(cause, timeoutMillis, closedBy())),
291
+ });
@@ -12,7 +12,8 @@
12
12
  */
13
13
  import { Schema } from "effect";
14
14
 
15
- import * as Motion from "./Motion.ts";
15
+ import { Action as ActionValue, Name } from "./Action.ts";
16
+ import * as Motion from "./Geometry.ts";
16
17
 
17
18
  /** A page opened, and the page that opened it, as a link or `window.open` does, if one did. */
18
19
  export class PageOpened extends Schema.TaggedClass<PageOpened>()("PageOpened", {
@@ -126,28 +127,9 @@ export const Box = Schema.Struct({
126
127
 
127
128
  export type Box = typeof Box.Type;
128
129
 
129
- /**
130
- * What else an action was asked, where it changes what the action does: a click's button, count
131
- * and hold, how `type` enters its text, how often and how long `press` holds its keys, how far
132
- * `scroll` moves, and the options `select` chose. Only a completed action records them.
133
- */
134
- export const ActionOptions = Schema.Struct({
135
- button: Schema.optional(Button),
136
- clickCount: Schema.optional(Schema.Finite),
137
- holdMillis: Schema.optional(Schema.Finite),
138
- replace: Schema.optional(Schema.Boolean),
139
- submit: Schema.optional(Schema.Boolean),
140
- times: Schema.optional(Schema.Finite),
141
- dx: Schema.optional(Schema.Finite),
142
- dy: Schema.optional(Schema.Finite),
143
- values: Schema.optional(Schema.Array(Schema.String)),
144
- });
145
-
146
- export type ActionOptions = typeof ActionOptions.Type;
147
-
148
130
  /**
149
131
  * One page operation ended, including one its caller interrupted (`error: "interrupted"`).
150
- * `target` is what the caller asked for: a ref, a point, a URL or keys, and `options` the rest.
132
+ * `value` is the decoded call. `target` is its short rendering for observers.
151
133
  * `subject` is what an element or point action found there, and `to` where a drag ended; an
152
134
  * action that failed before finding its target has neither. Point actions carry the viewport
153
135
  * point they used. `correlation` is the id its caller gave it with `Page.correlate`, such as a
@@ -157,12 +139,13 @@ export class Action extends Schema.TaggedClass<Action>()("Action", {
157
139
  at: Schema.Finite,
158
140
  startedAt: Schema.Finite,
159
141
  page: Schema.String,
160
- name: Schema.String,
142
+ name: Name,
143
+ /** The decoded call, with secrets removed before publication. */
144
+ value: ActionValue,
161
145
  /** The address when the action ended; absent in events recorded by older releases. */
162
146
  url: Schema.optional(Schema.String),
163
147
  correlation: Schema.optional(Schema.String),
164
148
  target: Schema.optional(Schema.String),
165
- options: Schema.optional(ActionOptions),
166
149
  subject: Schema.optional(Subject),
167
150
  to: Schema.optional(Subject),
168
151
  /** For an action at a point, the box of what it found there. */
@@ -258,7 +241,7 @@ export const TrackEvent = Schema.Union([
258
241
  export type TrackEvent = typeof TrackEvent.Type;
259
242
 
260
243
  /**
261
- * A JavaScript dialog appeared and was answered: an alert or a leave-page prompt accepted, a
244
+ * A JavaScript dialog appeared; its completed answer, or a failed response: an alert or a leave-page prompt accepted, a
262
245
  * confirm or a prompt dismissed, as if its Cancel were pressed.
263
246
  */
264
247
  export class DialogShown extends Schema.TaggedClass<DialogShown>()("DialogShown", {
@@ -266,10 +249,28 @@ export class DialogShown extends Schema.TaggedClass<DialogShown>()("DialogShown"
266
249
  page: Schema.String,
267
250
  kind: Schema.String,
268
251
  message: Schema.String,
269
- answer: Schema.Literals(["accepted", "dismissed"]),
252
+ answer: Schema.Literals(["accepted", "dismissed", "failed"]),
253
+ }) {}
254
+
255
+ /** A context policy refused traffic; page is present only when its containing page was established.
256
+ * Worker and out-of-process iframe requests may omit it while retaining proven context ownership. */
257
+ export class RequestRefused extends Schema.TaggedClass<RequestRefused>()("RequestRefused", {
258
+ at: Schema.Finite,
259
+ page: Schema.optional(Schema.String),
260
+ method: Schema.String,
261
+ url: Schema.String,
262
+ reason: Schema.String,
263
+ /** Safe structured diagnosis; arbitrary policy error details and causes stay private. */
264
+ failure: Schema.optional(
265
+ Schema.Struct({
266
+ reason: Schema.String,
267
+ timeoutMillis: Schema.optional(Schema.Finite),
268
+ }),
269
+ ),
270
270
  }) {}
271
271
 
272
272
  export const BrowserEvent = Schema.Union([
273
+ RequestRefused,
273
274
  PageOpened,
274
275
  PageClosed,
275
276
  PageUntracked,
package/src/Change.ts CHANGED
@@ -19,7 +19,6 @@
19
19
  import { Schema } from "effect";
20
20
 
21
21
  import { Subject } from "./BrowserEvent.ts";
22
- import * as Words from "./internal/timeline/words.ts";
23
22
 
24
23
  /**
25
24
  * `text` changed; `appeared` and `disappeared`, whether added or removed or shown or hidden;
@@ -85,4 +84,3 @@ export class Changes extends Schema.Class<Changes>("effect-browser/Changes")({
85
84
  }) {}
86
85
 
87
86
  /** A change in words for a model, such as `"$61,240" became "$62,010" (row "Bitcoin", column "Price")`. */
88
- export const describe = (change: Change): string => Words.describe(change);
@@ -3,7 +3,7 @@
3
3
  * offset from timed probes, how an estimate ages, and the mapping a browser's pages share.
4
4
  * `pictures.ts` takes the probes.
5
5
  */
6
- import { type Clock, Duration, Effect, Option } from "effect";
6
+ import { type Clock, Duration, Effect, Option, Semaphore } from "effect";
7
7
 
8
8
  /** Read the captured owner's clock, including from native callbacks, without changing its origin. */
9
9
  export const monotonicMillis = (clock: Clock.Clock): number =>
@@ -111,6 +111,7 @@ export const supersedes = (next: Estimate, current: Estimate): boolean => {
111
111
  export const mapping = (now: () => number): Mapping => {
112
112
  let latest: Estimate | undefined;
113
113
  let measuredAt = Number.NEGATIVE_INFINITY;
114
+ const lock = Semaphore.makeUnsafe(1);
114
115
 
115
116
  // Called where a measurement is decided, so no other can be decided before this one begins.
116
117
  const adopt = <E>(measure: Effect.Effect<Estimate, E>) => {
@@ -128,12 +129,22 @@ export const mapping = (now: () => number): Mapping => {
128
129
  return {
129
130
  latest: () => latest,
130
131
  current: (measure) =>
131
- Effect.suspend(() => (latest === undefined ? adopt(measure) : Effect.succeed(latest))),
132
- renew: (measure) =>
133
132
  Effect.suspend(() =>
134
- latest === undefined || now() - measuredAt < Duration.toMillis(renewAfter)
135
- ? Effect.void
136
- : Effect.ignore(adopt(measure)),
133
+ latest === undefined
134
+ ? lock.withPermits(1)(
135
+ Effect.suspend(() =>
136
+ latest === undefined ? adopt(measure) : Effect.succeed(latest),
137
+ ),
138
+ )
139
+ : Effect.succeed(latest),
140
+ ),
141
+ renew: (measure) =>
142
+ lock.withPermits(1)(
143
+ Effect.suspend(() =>
144
+ latest === undefined || now() - measuredAt < Duration.toMillis(renewAfter)
145
+ ? Effect.void
146
+ : Effect.ignore(adopt(measure)),
147
+ ),
137
148
  ),
138
149
  };
139
150
  };
package/src/Frame.ts CHANGED
@@ -40,6 +40,8 @@ export class Frame extends Schema.Class<Frame>("effect-browser/Frame")({
40
40
  session: Schema.String,
41
41
  /** Owning Browser connection; document counters restart on adoption or reattachment. */
42
42
  connection: Schema.String.check(Schema.isNonEmpty()),
43
+ /** Native capture identity. Screenshots have no capture generation or sequence. */
44
+ capture: Schema.optionalKey(Schema.Struct({ generation: Count, sequence: Count })),
43
45
  data: Schema.Uint8Array,
44
46
  timing: Schema.Union([BrowserPaint, Screenshot]),
45
47
  receivedAt: Schema.Finite,
@@ -72,6 +74,18 @@ export class Frame extends Schema.Class<Frame>("effect-browser/Frame")({
72
74
  }
73
75
  }
74
76
 
77
+ /** Equal capture lineage survives an image copy; untagged pictures retain object identity only. */
78
+ export const sameCapture = (frame: Frame, other: Frame | undefined): boolean =>
79
+ other !== undefined &&
80
+ (frame === other ||
81
+ (frame.capture !== undefined &&
82
+ frame.page === other.page &&
83
+ frame.session === other.session &&
84
+ frame.connection === other.connection &&
85
+ frame.document === other.document &&
86
+ frame.capture.generation === other.capture?.generation &&
87
+ frame.capture.sequence === other.capture?.sequence));
88
+
75
89
  /**
76
90
  * A page's capture counts, over its life or a window of the latest minute: what Chromium sent,
77
91
  * what readers got, and why the rest went no further. Frames that came late are counted apart from
@@ -0,0 +1,48 @@
1
+ /** Viewport geometry and bounded input schedules, independent of presentation planners. */
2
+ import { Effect, Random, Schema } from "effect";
3
+
4
+ export const maximumSamples = 2048;
5
+ export const maximumDurationMillis = 5000;
6
+
7
+ export const Point = Schema.Struct({ x: Schema.Finite, y: Schema.Finite });
8
+ export type Point = typeof Point.Type;
9
+
10
+ export const Sample = Schema.Struct({
11
+ ...Point.fields,
12
+ afterMillis: Schema.Finite.check(
13
+ Schema.isGreaterThanOrEqualTo(0),
14
+ Schema.isLessThanOrEqualTo(maximumDurationMillis),
15
+ ),
16
+ });
17
+
18
+ export type Sample = typeof Sample.Type;
19
+
20
+ /** A complete glide: 1 to 2,048 samples whose offsets never decrease. */
21
+ export const Plan = Schema.Array(Sample).check(
22
+ Schema.isBetweenLength(1, maximumSamples),
23
+ Schema.makeFilter(
24
+ (samples) =>
25
+ samples.every(
26
+ (sample, index) => sample.afterMillis >= (samples[index - 1]?.afterMillis ?? 0),
27
+ ),
28
+ { expected: "nondecreasing sample offsets" },
29
+ ),
30
+ );
31
+
32
+ export type Plan = typeof Plan.Type;
33
+
34
+ export interface Planner {
35
+ /**
36
+ * Offsets start when the performer publishes the plan, before its first input. The browser
37
+ * decodes the result as a `Plan` whose last sample must be exactly `to`. Glide time has a budget
38
+ * of its own, outside the browser's `actionTimeout`, so a drag may glide twice for 5 seconds.
39
+ */
40
+ readonly plan: (from: Point, to: Point) => Effect.Effect<ReadonlyArray<Sample>>;
41
+ }
42
+
43
+ /** One standard normal draw from the current seeded Effect random source. */
44
+ export const normal = Effect.gen(function* () {
45
+ const radius = Math.sqrt(-2 * Math.log(1 - (yield* Random.next)));
46
+
47
+ return radius * Math.cos(2 * Math.PI * (yield* Random.next));
48
+ });
@@ -9,22 +9,41 @@
9
9
  * - `near` matches when its words appear, whole and in order, in any of the element's context:
10
10
  * its row, column, label or heading. Replay chooses among candidates by the same rule.
11
11
  */
12
- import type { SubjectContext } from "../../BrowserEvent.ts";
13
- import type { Point } from "../../Motion.ts";
12
+ import type { SubjectContext } from "./BrowserEvent.ts";
13
+ import type { Point } from "./Geometry.ts";
14
+ import type { FindQuery } from "./Page.ts";
14
15
 
15
16
  /** A string, or a pattern sent to the page as its source and flags. */
16
17
  export type Wanted = string | { readonly source: string; readonly flags: string };
17
18
 
18
19
  export interface FindRequest {
20
+ readonly selector: string | null;
21
+ readonly state: "visible" | "enabled";
19
22
  readonly role: string | null;
20
23
  readonly name: Wanted | null;
21
24
  readonly text: Wanted | null;
22
25
  readonly near: string | null;
23
26
  readonly at: Point | null;
24
27
  readonly scope: "viewport" | "document";
25
- readonly firstRef: number;
26
28
  }
27
29
 
30
+ /** A public query in its serializable, fully specified form. */
31
+ export const request = (query: FindQuery, scope: FindRequest["scope"]): FindRequest => {
32
+ const wanted = (value: string | RegExp | undefined): Wanted | null =>
33
+ value instanceof RegExp ? { source: value.source, flags: value.flags } : (value ?? null);
34
+
35
+ return {
36
+ selector: query.selector ?? null,
37
+ state: query.state ?? "visible",
38
+ role: query.role ?? null,
39
+ name: wanted(query.name),
40
+ text: wanted(query.text),
41
+ near: query.near ?? null,
42
+ at: query.at ?? null,
43
+ scope: query.scope ?? scope,
44
+ };
45
+ };
46
+
28
47
  /** What a query is matched against, read only when a rule needs it. */
29
48
  export interface Candidate {
30
49
  readonly role: string | null;
@@ -87,7 +106,18 @@ export const match = () => {
87
106
  };
88
107
  };
89
108
 
90
- return { compile, holds, normalize };
109
+ /** A comparison token for ordered observations, without retaining their text. */
110
+ const mark = (observations: ReadonlyArray<string>): string => {
111
+ let hash = 0x811c9dc5;
112
+
113
+ for (const shown of observations)
114
+ for (let index = 0; index < shown.length; index++)
115
+ hash = Math.imul(hash ^ shown.charCodeAt(index), 0x01000193);
116
+
117
+ return `${observations.length}:${(hash >>> 0).toString(16)}`;
118
+ };
119
+
120
+ return { compile, holds, normalize, mark };
91
121
  };
92
122
 
93
123
  export type Match = ReturnType<typeof match>;