effect-browser 0.3.0-beta.20 → 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.
- package/README.md +221 -158
- package/dist/Action-24sLOubi.d.mts +110 -0
- package/dist/Action.d.mts +2 -0
- package/dist/Action.mjs +141 -0
- package/dist/Action.mjs.map +1 -0
- package/dist/ActionPort.d.mts +15 -0
- package/dist/ActionPort.mjs +101 -0
- package/dist/ActionPort.mjs.map +1 -0
- package/dist/Browser-Cq2K1FEA.mjs +4075 -0
- package/dist/Browser-Cq2K1FEA.mjs.map +1 -0
- package/dist/Browser-wZhwZSlG.d.mts +167 -0
- package/dist/Browser.d.mts +2 -129
- package/dist/Browser.mjs +1 -1
- package/dist/{BrowserError-Coy7EW1N.d.mts → BrowserError-BlcmLVzn.d.mts} +22 -7
- package/dist/BrowserError.d.mts +2 -2
- package/dist/BrowserError.mjs +46 -9
- package/dist/BrowserError.mjs.map +1 -1
- package/dist/{BrowserEvent-dq6FRT8w.d.mts → BrowserEvent-lLqJ3GJS.d.mts} +93 -37
- package/dist/BrowserEvent.d.mts +2 -2
- package/dist/BrowserEvent.mjs +29 -24
- package/dist/BrowserEvent.mjs.map +1 -1
- package/dist/{Change-DqING3tr.d.mts → Change-Ba7INmay.d.mts} +4 -6
- package/dist/Change.d.mts +2 -2
- package/dist/Change.mjs +97 -2
- package/dist/Change.mjs.map +1 -0
- package/dist/Clock.d.mts +57 -0
- package/dist/Clock.mjs +80 -0
- package/dist/Clock.mjs.map +1 -0
- package/dist/{Frame-DkNdjjjr.d.mts → Frame-UEH2hO5T.d.mts} +10 -3
- package/dist/Frame.d.mts +2 -2
- package/dist/Frame.mjs +10 -2
- package/dist/Frame.mjs.map +1 -1
- package/dist/{Motion-DND6I-64.d.mts → Geometry-DJx9qrYy.d.mts} +7 -10
- package/dist/Geometry.d.mts +2 -0
- package/dist/Geometry.mjs +32 -0
- package/dist/Geometry.mjs.map +1 -0
- package/dist/LICENSE-jpeg-js +28 -0
- package/dist/Matching.d.mts +37 -0
- package/dist/{match.inpage-xOe9LNO0.mjs → Matching.mjs} +28 -4
- package/dist/Matching.mjs.map +1 -0
- package/dist/{Page-CfB6Zn1p.mjs → Page-BF5izr8R.mjs} +216 -31
- package/dist/Page-BF5izr8R.mjs.map +1 -0
- package/dist/{Page-ku6j5t-v.d.mts → Page-CvsOEorc.d.mts} +158 -185
- package/dist/Page.d.mts +2 -2
- package/dist/Page.mjs +1 -1
- package/dist/Released-tURbFmal.d.mts +15 -0
- package/dist/{Snapshot-B34hZ4Jl.d.mts → Snapshot-CtBVOtuu.d.mts} +6 -1
- package/dist/Snapshot.d.mts +1 -1
- package/dist/Snapshot.mjs.map +1 -1
- package/dist/Stillness-CNlvayIo.mjs +136 -0
- package/dist/Stillness-CNlvayIo.mjs.map +1 -0
- package/dist/Style-AO4V7Czt.mjs +357 -0
- package/dist/Style-AO4V7Czt.mjs.map +1 -0
- package/dist/Style.d.mts +72 -0
- package/dist/Style.mjs +2 -0
- package/dist/Url.d.mts +26 -0
- package/dist/Url.mjs +74 -0
- package/dist/Url.mjs.map +1 -0
- package/dist/Window-CMddGMt1.d.mts +34 -0
- package/dist/Window.d.mts +2 -0
- package/dist/Window.mjs +35 -0
- package/dist/Window.mjs.map +1 -0
- package/dist/connection-2KHI4_KN.d.mts +41 -0
- package/dist/connection-BTeO0Hiz.mjs +68 -0
- package/dist/connection-BTeO0Hiz.mjs.map +1 -0
- package/dist/index.d.mts +15 -17
- package/dist/index.mjs +11 -14
- package/dist/moment/Moment.d.mts +86 -0
- package/dist/{Moment.mjs → moment/Moment.mjs} +44 -38
- package/dist/moment/Moment.mjs.map +1 -0
- package/dist/{Plan-DJ4hEEna.d.mts → plan/index.d.mts} +169 -64
- package/dist/{Plan-C-d5QYS8.mjs → plan/index.mjs} +122 -155
- package/dist/plan/index.mjs.map +1 -0
- package/dist/{Policy.d.mts → policy/Policy.d.mts} +5 -9
- package/dist/{Policy.mjs → policy/Policy.mjs} +11 -21
- package/dist/policy/Policy.mjs.map +1 -0
- package/dist/presentation/Motion.d.mts +12 -0
- package/dist/{Motion.mjs → presentation/Motion.mjs} +4 -27
- package/dist/presentation/Motion.mjs.map +1 -0
- package/dist/presentation/Presentation.d.mts +30 -0
- package/dist/presentation/Presentation.mjs +105 -0
- package/dist/presentation/Presentation.mjs.map +1 -0
- package/dist/{Stage.d.mts → presentation/Stage.d.mts} +5 -8
- package/dist/{Stage.mjs → presentation/Stage.mjs} +68 -76
- package/dist/presentation/Stage.mjs.map +1 -0
- package/dist/presentation/feed.d.mts +20 -0
- package/dist/presentation/feed.mjs +18 -0
- package/dist/presentation/feed.mjs.map +1 -0
- package/dist/providers/Cdp.d.mts +9 -0
- package/dist/providers/Cdp.mjs +15 -0
- package/dist/providers/Cdp.mjs.map +1 -0
- package/dist/{Chromium.d.mts → providers/Chromium.d.mts} +6 -7
- package/dist/{Chromium.mjs → providers/Chromium.mjs} +7 -16
- package/dist/providers/Chromium.mjs.map +1 -0
- package/dist/providers/Released.d.mts +2 -0
- package/dist/providers/Released.mjs +12 -0
- package/dist/providers/Released.mjs.map +1 -0
- package/dist/stillness/Stillness.d.mts +12 -0
- package/dist/stillness/Stillness.mjs +2 -0
- package/dist/supervisor/Supervisor.d.mts +104 -0
- package/dist/supervisor/Supervisor.mjs +513 -0
- package/dist/supervisor/Supervisor.mjs.map +1 -0
- package/dist/testing/index.d.mts +337 -0
- package/dist/testing/index.mjs +515 -0
- package/dist/testing/index.mjs.map +1 -0
- package/dist/workerd/Cdp.d.mts +8 -0
- package/dist/workerd/Cdp.mjs +13 -0
- package/dist/workerd/Cdp.mjs.map +1 -0
- package/package.json +94 -33
- package/src/Action.ts +127 -0
- package/src/ActionPort.ts +128 -0
- package/src/Browser.ts +366 -225
- package/src/BrowserError.ts +63 -6
- package/src/BrowserEvent.ts +26 -25
- package/src/Change.ts +0 -2
- package/src/{internal/pictures/clock.ts → Clock.ts} +17 -6
- package/src/Frame.ts +14 -0
- package/src/Geometry.ts +48 -0
- package/src/{internal/reading/match.inpage.ts → Matching.ts} +34 -4
- package/src/Page.ts +111 -92
- package/src/Snapshot.ts +5 -0
- package/src/{internal/input/style.ts → Style.ts} +121 -14
- package/src/Window.ts +30 -0
- package/src/index.ts +8 -13
- package/src/internal/input/actions.ts +61 -119
- package/src/internal/input/dispatch.ts +3 -3
- package/src/internal/input/gate.ts +21 -18
- package/src/internal/input/guard.inpage.ts +25 -58
- package/src/internal/input/guard.ts +11 -20
- package/src/internal/input/keyboard.ts +12 -3
- package/src/internal/input/perform.ts +78 -60
- package/src/internal/input/pointer.ts +4 -2
- package/src/internal/input/settle.ts +7 -5
- package/src/internal/input/targets.inpage.ts +1 -1
- package/src/internal/input/targets.ts +4 -9
- package/src/internal/page/bridge.ts +210 -114
- package/src/internal/page/context.ts +23 -73
- package/src/internal/page/dialogs.ts +58 -0
- package/src/internal/page/identity.ts +6 -23
- package/src/internal/page/lane.ts +14 -15
- package/src/internal/page/navigation.ts +50 -42
- package/src/internal/page/openings.ts +11 -5
- package/src/internal/page/page.ts +44 -81
- package/src/internal/page/port.ts +125 -0
- package/src/internal/{input → page}/replies.ts +1 -1
- package/src/internal/page/request-owner.ts +269 -0
- package/src/internal/page/requests.ts +357 -0
- package/src/internal/page/scripts.ts +124 -0
- package/src/internal/pictures/capture.ts +255 -332
- package/src/internal/pictures/dimensions.ts +162 -0
- package/src/internal/pictures/frame.ts +68 -0
- package/src/internal/pictures/pictures.ts +57 -23
- package/src/internal/pictures/quiescence.ts +1 -1
- package/src/internal/pictures/state.ts +26 -0
- package/src/internal/pictures/transport.ts +21 -4
- package/src/internal/reading/controls.inpage.ts +5 -70
- package/src/internal/reading/expect.inpage.ts +13 -17
- package/src/internal/reading/names.inpage.ts +89 -45
- package/src/internal/reading/outline.inpage.ts +6 -7
- package/src/internal/reading/reading.ts +144 -176
- package/src/internal/reading/ready.inpage.ts +6 -17
- package/src/internal/reading/ready.ts +13 -135
- package/src/internal/reading/subjects.inpage.ts +83 -43
- package/src/internal/reading/walk.inpage.ts +33 -13
- package/src/internal/timeline/changes.ts +55 -6
- package/src/internal/timeline/events.ts +15 -5
- package/src/internal/timeline/history.inpage.ts +1 -1
- package/src/internal/timeline/record.inpage.ts +4 -1
- package/src/internal/timeline/window.ts +2 -1
- package/src/{Moment.ts → moment/Moment.ts} +13 -31
- package/src/{internal/timeline → moment}/words.ts +2 -2
- package/src/{internal/reading → plan}/choose.ts +3 -3
- package/src/plan/data.ts +117 -0
- package/src/plan/execute.ts +411 -0
- package/src/plan/index.ts +36 -0
- package/src/plan/record.ts +71 -0
- package/src/plan/targets.ts +71 -0
- package/src/{Policy.ts → policy/Policy.ts} +13 -10
- package/src/{Motion.ts → presentation/Motion.ts} +12 -46
- package/src/presentation/Presentation.ts +176 -0
- package/src/{Stage.ts → presentation/Stage.ts} +147 -112
- package/src/presentation/feed.ts +21 -0
- package/src/providers/Cdp.ts +16 -0
- package/src/{Chromium.ts → providers/Chromium.ts} +7 -10
- package/src/providers/Released.ts +13 -0
- package/src/providers/connection.ts +134 -0
- package/src/{internal/pictures/motion.ts → stillness/Pixels.ts} +4 -4
- package/src/stillness/Stillness.ts +166 -0
- package/src/supervisor/Supervisor.ts +170 -0
- package/src/supervisor/contract.ts +105 -0
- package/src/supervisor/lifecycle.ts +272 -0
- package/src/supervisor/runtime.ts +234 -0
- package/src/testing/TestBrowser.ts +115 -0
- package/src/testing/TestPage.ts +10 -0
- package/src/testing/evidence.ts +154 -0
- package/src/testing/index.ts +3 -0
- package/src/testing/model.ts +222 -0
- package/src/testing/page.ts +360 -0
- package/src/workerd/Cdp.ts +11 -0
- package/dist/Browser-BwCldIff.mjs +0 -629
- package/dist/Browser-BwCldIff.mjs.map +0 -1
- package/dist/Cdp.d.mts +0 -32
- package/dist/Cdp.mjs +0 -61
- package/dist/Cdp.mjs.map +0 -1
- package/dist/Change-DNvztNLu.mjs +0 -138
- package/dist/Change-DNvztNLu.mjs.map +0 -1
- package/dist/Chromium.mjs.map +0 -1
- package/dist/Expect.d.mts +0 -62
- package/dist/Expect.mjs +0 -114
- package/dist/Expect.mjs.map +0 -1
- package/dist/Moment.d.mts +0 -2
- package/dist/Moment.mjs.map +0 -1
- package/dist/Motion.d.mts +0 -2
- package/dist/Motion.mjs.map +0 -1
- package/dist/Page-CfB6Zn1p.mjs.map +0 -1
- package/dist/Plan-C-d5QYS8.mjs.map +0 -1
- package/dist/Plan.d.mts +0 -2
- package/dist/Plan.mjs +0 -2
- package/dist/Policy.mjs.map +0 -1
- package/dist/Presentation.d.mts +0 -48
- package/dist/Presentation.mjs +0 -118
- package/dist/Presentation.mjs.map +0 -1
- package/dist/Stage.mjs.map +0 -1
- package/dist/Supervisor-2mPjIYYs.mjs +0 -676
- package/dist/Supervisor-2mPjIYYs.mjs.map +0 -1
- package/dist/Supervisor-mVPeEUp8.d.mts +0 -317
- package/dist/Supervisor.d.mts +0 -2
- package/dist/Supervisor.mjs +0 -2
- package/dist/context-w3NJPRLo.mjs +0 -335
- package/dist/context-w3NJPRLo.mjs.map +0 -1
- package/dist/match.inpage-xOe9LNO0.mjs.map +0 -1
- package/dist/page-BKwfF6z-.mjs +0 -5099
- package/dist/page-BKwfF6z-.mjs.map +0 -1
- package/dist/url-Cd04Okid.mjs +0 -264
- package/dist/url-Cd04Okid.mjs.map +0 -1
- package/src/Cdp.ts +0 -101
- package/src/Expect.ts +0 -180
- package/src/Plan.ts +0 -674
- package/src/Presentation.ts +0 -196
- package/src/Supervisor.ts +0 -632
- package/src/internal/supervisor/lifecycle.ts +0 -484
- /package/src/{internal/page/url.ts → Url.ts} +0 -0
- /package/src/{internal/pictures → stillness}/utilsBundle.d.ts +0 -0
package/src/BrowserError.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
+
});
|
package/src/BrowserEvent.ts
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { Schema } from "effect";
|
|
14
14
|
|
|
15
|
-
import
|
|
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
|
-
* `
|
|
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:
|
|
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
|
|
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
|
|
135
|
-
?
|
|
136
|
-
|
|
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
|
package/src/Geometry.ts
ADDED
|
@@ -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 "
|
|
13
|
-
import type { Point } from "
|
|
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
|
-
|
|
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>;
|