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,16 +8,15 @@
8
8
  *
9
9
  * Reads keep their work. An identical read asked in the same epoch and document joins the one in
10
10
  * flight, which runs in the page's scope under the action timeout whoever gives up; one that ends
11
- * after all its callers gave up serves the next to ask the same, within an action timeout. A write
11
+ * after all its callers gave up serves the next to ask the same, within 250 milliseconds. A write
12
12
  * stops the reads nobody awaits, since no caller after it could use them.
13
13
  *
14
14
  * Effect's `Semaphore` is not fair to a writer that needs every permit, so the rule is this
15
15
  * module's own: one state, changed by `step` alone, which the model test drives.
16
16
  */
17
- import { Context, Deferred, Duration, Effect, Exit, type Fiber, type Scope } from "effect";
17
+ import { Context, Deferred, type Duration, Effect, Exit, type Fiber, type Scope } from "effect";
18
18
 
19
- import { BrowserError, Busy } from "../../BrowserError.ts";
20
- import type { Gate } from "../input/gate.ts";
19
+ import { undispatched, type BrowserError, Busy } from "../../BrowserError.ts";
21
20
 
22
21
  export type Kind = "read" | "write";
23
22
 
@@ -129,7 +128,8 @@ export const make = (options: {
129
128
  readonly gone: (operation: string) => BrowserError;
130
129
  /** The page's scope, which shared reads run in. */
131
130
  readonly scope: Scope.Scope;
132
- readonly inputGate?: Gate | undefined;
131
+ readonly beforeWrite?: ((operation: string) => Effect.Effect<void, BrowserError>) | undefined;
132
+ readonly refusal?: ((operation: string) => Effect.Effect<never, BrowserError>) | undefined;
133
133
  }) => {
134
134
  const { now, actionTimeout } = options;
135
135
  let state = initial;
@@ -153,11 +153,10 @@ export const make = (options: {
153
153
  };
154
154
 
155
155
  const busy = (operation: string, askedAt: number, id?: number) =>
156
- new BrowserError({
156
+ undispatched(
157
157
  operation,
158
- reason: new Busy({ waitedMillis: Math.round(now() - askedAt), ahead: ahead(state, id) }),
159
- dispatched: false,
160
- });
158
+ new Busy({ waitedMillis: Math.round(now() - askedAt), ahead: ahead(state, id) }),
159
+ );
161
160
 
162
161
  /**
163
162
  * Run `effect` in a turn of `kind`, waiting at most `wait` for it, or failing `Busy`. The turn
@@ -171,8 +170,8 @@ export const make = (options: {
171
170
  const ticket: Ticket = { id: ++tickets, kind };
172
171
  const askedAt = now();
173
172
 
174
- if (kind === "write" && options.inputGate !== undefined)
175
- yield* options.inputGate.check(operation);
173
+ if (kind === "write" && options.beforeWrite !== undefined)
174
+ yield* options.beforeWrite(operation);
176
175
 
177
176
  if ((yield* FailFast) && !admitsNow(state, kind)) return yield* busy(operation, askedAt);
178
177
  const admitted = Deferred.makeUnsafe<void>();
@@ -192,8 +191,8 @@ export const make = (options: {
192
191
 
193
192
  const given = yield* Effect.exit(
194
193
  restore(
195
- kind === "write" && options.inputGate !== undefined
196
- ? Effect.raceFirst(waiting, options.inputGate.refused(operation))
194
+ kind === "write" && options.beforeWrite !== undefined
195
+ ? Effect.raceFirst(waiting, options.refusal?.(operation) ?? Effect.never)
197
196
  : waiting,
198
197
  ),
199
198
  );
@@ -213,7 +212,7 @@ export const make = (options: {
213
212
  /**
214
213
  * A read whose identical calls share their work: `work` runs once per epoch and document while
215
214
  * calls await it, and with `keep` its result serves the next call after all of them gave up,
216
- * within an action timeout of its end. Pictures, whose callers say how old they may be, only
215
+ * within 250 milliseconds of its end. Pictures, whose callers say how old they may be, only
217
216
  * join.
218
217
  */
219
218
  const shared = <A>(operation: string, keep: boolean) => {
@@ -250,7 +249,7 @@ export const make = (options: {
250
249
  flight.fiber.addObserver((exit) => {
251
250
  flights.delete(id);
252
251
  if (keep && Exit.isSuccess(exit) && flight.waiting === 0 && flight.epoch === state.epoch)
253
- kept.set(id, { value: exit.value, until: now() + Duration.toMillis(actionTimeout) });
252
+ kept.set(id, { value: exit.value, until: now() + 250 });
254
253
  Deferred.doneUnsafe(
255
254
  flight.result,
256
255
  Exit.hasInterrupts(exit) ? Effect.fail(options.gone(operation)) : exit,
@@ -5,12 +5,13 @@
5
5
  */
6
6
  import { Deferred, Duration, Effect, Schedule } from "effect";
7
7
 
8
+ import { type Action, nameOf } from "../../Action.ts";
8
9
  import { BrowserError, NavigationFailed, NotActionable, NotFound } from "../../BrowserError.ts";
10
+ import * as Url from "../../Url.ts";
9
11
  import type { Guard } from "../input/guard.ts";
10
12
  import type { InputMarks, Perform } from "../input/perform.ts";
11
- import { Current } from "../input/replies.ts";
12
13
  import { failWith, type PageContext, refuse } from "./context.ts";
13
- import * as Url from "./url.ts";
14
+ import { Current } from "./replies.ts";
14
15
 
15
16
  export const make = (
16
17
  page: PageContext,
@@ -21,14 +22,15 @@ export const make = (
21
22
  const { send } = page.protocol;
22
23
 
23
24
  // `address` is where `run` goes, as the action, the guard and a failure report it.
24
- const navigation = (name: string, run: () => Promise<unknown>, address: string) => {
25
+ const navigation = (value: Action, run: () => Promise<unknown>, address: string) => {
26
+ const name = nameOf(value);
25
27
  const url = Url.redact(address);
26
28
 
27
29
  return perform(
28
- name,
29
- { target: url, input: false },
30
+ value,
31
+ { target: url },
30
32
  settings.navigationTimeout,
31
- preparePolicy(name, { target: url }, [], { destination: url }),
33
+ (action) => preparePolicy(action, { target: url }, [], { destination: url }),
32
34
  (marks) =>
33
35
  marks.sent.pipe(
34
36
  Effect.andThen(native(name, run).pipe(Effect.onError(() => page.stopLoading))),
@@ -69,37 +71,38 @@ export const make = (
69
71
 
70
72
  const noPrevious = failWith("back", new NotFound({ target: "a previous page in this tab" }));
71
73
 
72
- const prepareBack = Effect.gen(function* () {
73
- const before = yield* history;
74
- const current = before.entries[before.currentIndex];
75
- const previous = before.entries[before.currentIndex - 1];
76
-
77
- if (previous === undefined) return yield* noPrevious;
78
- const plan = yield* preparePolicy("back", {}, [], { destination: Url.redact(previous.url) });
79
-
80
- return {
81
- request: plan.request,
82
- validate: Effect.gen(function* () {
83
- const approval = yield* plan.validate;
84
- const latest = yield* history;
85
-
86
- if (
87
- latest.currentIndex !== before.currentIndex ||
88
- latest.entries[latest.currentIndex]?.id !== current?.id ||
89
- latest.entries[latest.currentIndex - 1]?.id !== previous.id ||
90
- latest.entries[latest.currentIndex - 1]?.url !== previous.url
91
- )
92
- return yield* failWith(
93
- "back",
94
- new NotActionable({
95
- detail: "the navigation history changed while input policy was pending",
96
- }),
97
- );
98
-
99
- return approval;
100
- }),
101
- };
102
- });
74
+ const prepareBack = (action: Action) =>
75
+ Effect.gen(function* () {
76
+ const before = yield* history;
77
+ const current = before.entries[before.currentIndex];
78
+ const previous = before.entries[before.currentIndex - 1];
79
+
80
+ if (previous === undefined) return yield* noPrevious;
81
+ const plan = yield* preparePolicy(action, {}, [], { destination: Url.redact(previous.url) });
82
+
83
+ return {
84
+ request: plan.request,
85
+ validate: Effect.gen(function* () {
86
+ const approval = yield* plan.validate;
87
+ const latest = yield* history;
88
+
89
+ if (
90
+ latest.currentIndex !== before.currentIndex ||
91
+ latest.entries[latest.currentIndex]?.id !== current?.id ||
92
+ latest.entries[latest.currentIndex - 1]?.id !== previous.id ||
93
+ latest.entries[latest.currentIndex - 1]?.url !== previous.url
94
+ )
95
+ return yield* failWith(
96
+ "back",
97
+ new NotActionable({
98
+ detail: "the navigation history changed while input policy was pending",
99
+ }),
100
+ );
101
+
102
+ return approval;
103
+ }),
104
+ };
105
+ });
103
106
 
104
107
  // One protocol traversal on every path. It has committed once the tab leaves its entry, which
105
108
  // also covers entries that only an iframe created, where the main frame never navigates, and
@@ -153,16 +156,21 @@ export const make = (
153
156
  )
154
157
  return refuse("navigate", `"${Url.redact(url)}" is not a URL`);
155
158
 
159
+ const run = () => playwright.goto(parsed.href, { waitUntil: "domcontentloaded", timeout: 0 });
160
+
156
161
  return navigation(
157
- "navigate",
158
- () => playwright.goto(parsed.href, { waitUntil: "domcontentloaded", timeout: 0 }),
162
+ { _tag: "Goto", url },
163
+ () =>
164
+ page.nativePort === undefined
165
+ ? run()
166
+ : page.nativePort(page.id, "goto", { url: parsed.href }, run),
159
167
  parsed.href,
160
168
  );
161
169
  };
162
170
 
163
171
  const back = perform(
164
- "back",
165
- { target: "back", input: false },
172
+ { _tag: "Back" },
173
+ { target: "back" },
166
174
  settings.navigationTimeout,
167
175
  prepareBack,
168
176
  goBack,
@@ -170,7 +178,7 @@ export const make = (
170
178
 
171
179
  const reload = Effect.suspend(() =>
172
180
  navigation(
173
- "reload",
181
+ { _tag: "Reload" },
174
182
  () => playwright.reload({ waitUntil: "domcontentloaded", timeout: 0 }),
175
183
  playwright.url(),
176
184
  ),
@@ -2,10 +2,17 @@
2
2
  import { Deferred, Effect, Exit } from "effect";
3
3
  import type { CDPSession, Page as PlaywrightPage } from "playwright-core";
4
4
 
5
- import { BrowserError, Closed, Failed, type Reason } from "../../BrowserError.ts";
5
+ import {
6
+ undispatched,
7
+ type BrowserError,
8
+ Closed,
9
+ Failed,
10
+ type Reason,
11
+ } from "../../BrowserError.ts";
12
+ import type * as Page from "../../Page.ts";
6
13
 
7
14
  /** How the browser's registration of each tab it was told of ended, once it has. */
8
- export type Registrations = WeakMap<PlaywrightPage, Deferred.Deferred<void, BrowserError>>;
15
+ export type Registrations = WeakMap<PlaywrightPage, Deferred.Deferred<Page.Page, BrowserError>>;
9
16
 
10
17
  export interface Mark {
11
18
  windows: number;
@@ -19,8 +26,7 @@ export const make = Effect.fnUntraced(function* (
19
26
  registrations: Registrations,
20
27
  closedBy: () => Closed["cause"],
21
28
  ) {
22
- const failed = (reason: Reason) =>
23
- Exit.fail(new BrowserError({ operation: "newPage", reason, dispatched: false }));
29
+ const failed = (reason: Reason) => Exit.fail(undispatched("newPage", reason));
24
30
 
25
31
  let active: Mark | undefined;
26
32
  const gone = Deferred.makeUnsafe<never, BrowserError>();
@@ -38,7 +44,7 @@ export const make = Effect.fnUntraced(function* (
38
44
  active.registrations.push(
39
45
  registered === undefined
40
46
  ? failed(new Failed({ detail: "the popup has no registration" }))
41
- : Deferred.await(registered),
47
+ : Deferred.await(registered).pipe(Effect.asVoid),
42
48
  );
43
49
  Deferred.doneUnsafe(active.changed, Exit.void);
44
50
  active.changed = Deferred.makeUnsafe<void>();
@@ -3,15 +3,15 @@
3
3
  * share (the clock mapping and event publication), so construction stays internal. A page is
4
4
  * assembled here from its domains: the script bridge, pictures, reading, its timeline, input and
5
5
  * navigation.
6
- * What a presenter and a stage need of a page, and no caller should, it keeps out of sight.
6
+ * Features use the same documented Page contract as consumers.
7
7
  */
8
- import { type Effect as Eff, Effect, Option } from "effect";
8
+ import { Effect, Option } from "effect";
9
9
 
10
- import type { BrowserError } from "../../BrowserError.ts";
10
+ import * as ActionPort from "../../ActionPort.ts";
11
11
  import type { Frame } from "../../Frame.ts";
12
12
  import { type Page, State } from "../../Page.ts";
13
+ import * as Url from "../../Url.ts";
13
14
  import * as Actions from "../input/actions.ts";
14
- import type { Controller } from "../pictures/capture.ts";
15
15
  import * as Pictures from "../pictures/pictures.ts";
16
16
  import * as Reading from "../reading/reading.ts";
17
17
  import * as Ready from "../reading/ready.ts";
@@ -20,49 +20,9 @@ import * as Window from "../timeline/window.ts";
20
20
  import * as Bridge from "./bridge.ts";
21
21
  import * as Context from "./context.ts";
22
22
  import * as Navigation from "./navigation.ts";
23
- import * as Url from "./url.ts";
23
+ import * as Scripts from "./scripts.ts";
24
24
  import * as Viewport from "./viewport.ts";
25
25
 
26
- export interface Internals {
27
- /** The page's input, in any style. */
28
- readonly input: Actions.Input;
29
- /** Drain earlier input and retain a read turn through the effect; the whole wait is bounded. */
30
- readonly afterInput: <A, E, R>(effect: Eff.Effect<A, E, R>) => Eff.Effect<A, E | BrowserError, R>;
31
- /** Start capture now, independently of its first frame. The calling scope keeps it running. */
32
- readonly capture: Controller["open"];
33
- /** Current capture/document evidence, without waiting for acknowledgement or transport. */
34
- readonly current: (frame: Frame) => boolean;
35
- /** A current frame, with a fresh bounded answer from the page and capture sessions. */
36
- readonly confirm: (frame: Frame) => Eff.Effect<boolean, BrowserError>;
37
- /** The page's documents so far, counted as `Navigated` counts them. */
38
- readonly document: () => number;
39
- /** Wait, in one call, until what a query finds is there, is not, or shows something else. */
40
- readonly until: Reading.Reading["until"];
41
- }
42
-
43
- /** A page this library built: it keeps its internals where only this module reaches them. */
44
- class Built {
45
- readonly #internals: Internals;
46
-
47
- constructor(internals: Internals) {
48
- this.#internals = internals;
49
- }
50
-
51
- static internalsOf(page: Page): Internals | undefined {
52
- return page instanceof Built ? page.#internals : undefined;
53
- }
54
- }
55
-
56
- /** What a page this library built keeps out of sight; nothing for any other `Page`. */
57
- export const internalsOf = (page: Page) => Built.internalsOf(page);
58
-
59
- /** `view`, made from `page` with some of its operations replaced, keeping what `page` keeps out of sight. */
60
- export const viewOf = <A extends Page>(page: Page, view: A): A => {
61
- const internals = internalsOf(page);
62
-
63
- return internals === undefined ? view : Object.assign(new Built(internals), view);
64
- };
65
-
66
26
  export const make = Effect.fnUntraced(function* (options: Context.MakeOptions) {
67
27
  const page = Context.make(options, yield* Effect.scope);
68
28
  const { id, playwright, native, owned, within, lane, span } = page;
@@ -85,6 +45,7 @@ export const make = Effect.fnUntraced(function* (options: Context.MakeOptions) {
85
45
 
86
46
  return new State({
87
47
  page: id,
48
+ connection: page.connection,
88
49
  at: page.now(),
89
50
  url,
90
51
  document,
@@ -100,14 +61,46 @@ export const make = Effect.fnUntraced(function* (options: Context.MakeOptions) {
100
61
  bridge.frameTag().document === frame.document &&
101
62
  frame.hostTime - frame.timing.uncertaintyMillis > page.activity.documentAt;
102
63
 
64
+ const afterInput: Page["afterInput"] = (effect) =>
65
+ lane
66
+ .read(
67
+ "inputEnded",
68
+ page.settings.navigationTimeout,
69
+ )(Effect.andThen(input.perform.idle, effect))
70
+ .pipe(within("inputEnded", page.settings.navigationTimeout), owned);
71
+
72
+ const confirm = (frame: Frame) =>
73
+ native("shown", () => page.protocol.send("Page.getFrameTree")).pipe(
74
+ Effect.flatMap(() => capture.confirm(frame)),
75
+ Effect.map((confirmed) => confirmed && current(frame)),
76
+ within("shown", "2 seconds"),
77
+ owned,
78
+ );
79
+
80
+ const perform = ActionPort.checked((action) =>
81
+ ActionPort.execute({ ...input, ...navigation }, action),
82
+ );
83
+
103
84
  const assembled: Page = {
85
+ ...Scripts.make(page, bridge, input),
86
+ ...ActionPort.methods(perform),
87
+ perform,
88
+ clock: page.clock,
89
+ afterInput,
90
+ until: reading.until,
91
+ capture: (options) =>
92
+ capture.open(options).pipe(
93
+ Effect.map((lease) => ({
94
+ ...lease,
95
+ isCurrent: current,
96
+ confirm,
97
+ sync: capture.sync,
98
+ stats: pictures.captureStats,
99
+ })),
100
+ ),
104
101
  id,
105
- playwright,
106
102
  url: Effect.sync(() => Url.redact(playwright.url())),
107
103
  title: titles("", navigation.title.pipe(within("title"))).pipe(span("Page.title"), owned),
108
- goto: navigation.goto,
109
- back: navigation.back,
110
- reload: navigation.reload,
111
104
  bringToFront: native("bringToFront", () => playwright.bringToFront()),
112
105
  // Playwright answers once the page has closed, and at once for one already closed.
113
106
  close: native("close", () => playwright.close()),
@@ -124,42 +117,12 @@ export const make = Effect.fnUntraced(function* (options: Context.MakeOptions) {
124
117
  changes,
125
118
  window: Window.make(page, changes, capture.recent),
126
119
  state,
127
- click: (target, options) => input.click(target, options),
128
- hover: (target) => input.hover(target),
129
- drag: (from, to) => input.drag(from, to),
130
- type: (text, options) => input.type(text, options),
131
- press: (keys, options) => input.press(keys, options),
132
- scroll: (options) => input.scroll(options),
133
- select: input.select,
134
- waitFor: reading.waitFor,
135
- ready: Ready.make(page, bridge, capture),
120
+ ready: Ready.make(page, bridge),
136
121
  screencast: capture.stream,
137
122
  captureStats: pictures.captureStats,
138
123
  recentFrames: capture.recent,
139
124
  recentEvents: options.recentEvents,
140
125
  };
141
126
 
142
- const internals: Internals = {
143
- input,
144
- afterInput: (effect) =>
145
- lane
146
- .read(
147
- "inputEnded",
148
- page.settings.navigationTimeout,
149
- )(Effect.andThen(input.perform.idle, effect))
150
- .pipe(within("inputEnded", page.settings.navigationTimeout), owned),
151
- capture: capture.open,
152
- current,
153
- confirm: (frame) =>
154
- native("shown", () => page.protocol.send("Page.getFrameTree")).pipe(
155
- Effect.flatMap(() => capture.confirm(frame)),
156
- Effect.map((confirmed) => confirmed && current(frame)),
157
- within("shown", "2 seconds"),
158
- owned,
159
- ),
160
- document: () => bridge.frameTag().document,
161
- until: reading.until,
162
- };
163
-
164
- return Object.assign(new Built(internals), assembled);
127
+ return assembled;
165
128
  });
@@ -0,0 +1,125 @@
1
+ /** Scoped protocol interception at the owned session boundary; native is the default. */
2
+ import { Clock, Context, Effect, Fiber } from "effect";
3
+ import type { BrowserContext, CDPSession, Page as NativePage } from "playwright-core";
4
+
5
+ import type { CaptureSource } from "../../Browser.ts";
6
+ import { call } from "../../BrowserError.ts";
7
+
8
+ export const Operation = Context.Reference<string | undefined>("effect-browser/ProtocolOperation", {
9
+ defaultValue: () => undefined,
10
+ });
11
+
12
+ export const Script = Context.Reference<string | undefined>("effect-browser/ProtocolScript", {
13
+ defaultValue: () => undefined,
14
+ });
15
+
16
+ export interface Session {
17
+ readonly channel: "page" | "capture" | "browser";
18
+ readonly clock: Clock.Clock;
19
+ page: string | undefined;
20
+ readonly nativePage?: NativePage | undefined;
21
+ }
22
+
23
+ export interface Event {
24
+ readonly method: string;
25
+ readonly params: unknown;
26
+ }
27
+
28
+ export type CaptureSend = Effect.Success<ReturnType<CaptureSource["attach"]>>;
29
+
30
+ export interface Hooks {
31
+ readonly query?:
32
+ | ((session: Session, method: string, run: () => Promise<unknown>) => Promise<unknown>)
33
+ | undefined;
34
+ readonly page?: ((session: Session, native: CDPSession) => CDPSession) | undefined;
35
+ readonly native?:
36
+ | (<A>(
37
+ page: string,
38
+ method: "keyboard.down" | "keyboard.up" | "goto",
39
+ params: Readonly<Record<string, unknown>>,
40
+ run: () => Promise<A>,
41
+ ) => Promise<A>)
42
+ | undefined;
43
+ readonly browser?: ((connection: string, context: BrowserContext) => () => void) | undefined;
44
+ readonly beforeOpen?: ((session: Session) => Promise<void>) | undefined;
45
+ readonly send?: ((session: Session, send: CDPSession["send"]) => CDPSession["send"]) | undefined;
46
+ readonly capture?: ((session: Session, send: CaptureSend) => CaptureSend) | undefined;
47
+ readonly event?:
48
+ | ((session: Session, event: Event, deliver: (event: Event) => void) => void)
49
+ | undefined;
50
+ readonly opened?: ((session: Session, inject: (event: Event) => void) => () => void) | undefined;
51
+ }
52
+
53
+ export const Current = Context.Reference<Hooks>("effect-browser/ProtocolPort", {
54
+ defaultValue: () => ({}),
55
+ });
56
+
57
+ export const labels = () => ({
58
+ operation: Fiber.getCurrent()?.getRef(Operation),
59
+ script: Fiber.getCurrent()?.getRef(Script),
60
+ });
61
+
62
+ /** The provider owns creation and passes its session to an optional scoped test adapter. */
63
+ export const openSession = Effect.fnUntraced(function* (
64
+ open: () => Promise<CDPSession>,
65
+ nativePage?: NativePage,
66
+ channel: "page" | "browser" = "page",
67
+ ) {
68
+ const hooks = yield* Current;
69
+
70
+ const session: Session = {
71
+ channel,
72
+ clock: yield* Clock.Clock,
73
+ page: undefined,
74
+ nativePage,
75
+ };
76
+
77
+ const beforeOpen = hooks.beforeOpen;
78
+ const operation = channel === "browser" ? "requests" : "newPage";
79
+
80
+ if (beforeOpen !== undefined)
81
+ yield* call(
82
+ operation,
83
+ () => beforeOpen(session),
84
+ () => "connection",
85
+ );
86
+ const native = yield* call(operation, open, () => "connection");
87
+
88
+ return hooks.page?.(session, native) ?? native;
89
+ });
90
+
91
+ /** The dedicated capture connection uses the same interception and injection rules. */
92
+ export const openCapture = Effect.fnUntraced(function* (
93
+ page: string,
94
+ source: CaptureSource,
95
+ handlers: Parameters<CaptureSource["attach"]>[1],
96
+ ) {
97
+ const hooks = yield* Current;
98
+ const session: Session = { channel: "capture", page, clock: yield* Clock.Clock };
99
+ const beforeOpen = hooks.beforeOpen;
100
+
101
+ if (beforeOpen !== undefined)
102
+ yield* call(
103
+ "screencast",
104
+ () => beforeOpen(session),
105
+ () => "connection",
106
+ );
107
+
108
+ const deliver = ({ method, params }: Event) => {
109
+ const run = ({ method, params }: Event) => handlers.event(method, params);
110
+
111
+ if (hooks.event === undefined) run({ method, params });
112
+ else hooks.event(session, { method, params }, run);
113
+ };
114
+
115
+ const release = hooks.opened?.(session, ({ method, params }) => handlers.event(method, params));
116
+
117
+ yield* Effect.addFinalizer(() => Effect.sync(() => release?.()));
118
+
119
+ const send = yield* source.attach(page, {
120
+ ...handlers,
121
+ event: (method, params) => deliver({ method, params }),
122
+ });
123
+
124
+ return hooks.capture?.(session, send) ?? send;
125
+ });
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { Context, Data, Effect, type Scope } from "effect";
7
7
 
8
- import { maximumSamples } from "../../Motion.ts";
8
+ import { maximumSamples } from "../../Geometry.ts";
9
9
 
10
10
  export const capacity = 64;
11
11