effect-browser 0.3.0-beta.21 → 0.3.0-beta.23
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 +130 -159
- 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-BKPAbyys.mjs +4076 -0
- package/dist/Browser-BKPAbyys.mjs.map +1 -0
- package/dist/{Browser-CiXHT1yO.d.mts → Browser-wZhwZSlG.d.mts} +51 -13
- package/dist/Browser.d.mts +2 -2
- 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/Matching.d.mts +37 -0
- package/dist/Matching.mjs +72 -0
- package/dist/Matching.mjs.map +1 -0
- package/dist/Page-BF5izr8R.mjs +795 -0
- 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/{cdp-DL7XfEj5.d.mts → connection-2KHI4_KN.d.mts} +4 -4
- package/dist/{cdp-BMpYMWYe.mjs → connection-CK83pvqP.mjs} +5 -6
- package/dist/connection-CK83pvqP.mjs.map +1 -0
- package/dist/index.d.mts +15 -18
- package/dist/index.mjs +11 -15
- 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-BG1WifW2.mjs → plan/index.mjs} +122 -199
- package/dist/plan/index.mjs.map +1 -0
- package/dist/{Policy-BGWjbqCl.d.mts → policy/Policy.d.mts} +16 -20
- 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-NHp8N81k.d.mts → presentation/Stage.d.mts} +12 -15
- 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/{Cdp.mjs → providers/Cdp.mjs} +3 -8
- 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} +6 -15
- 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 +515 -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 -3
- package/dist/workerd/Cdp.mjs +2 -7
- package/dist/workerd/Cdp.mjs.map +1 -1
- package/package.json +89 -39
- package/src/Action.ts +127 -0
- package/src/ActionPort.ts +128 -0
- package/src/Browser.ts +352 -201
- 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 +15 -6
- 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 +209 -113
- package/src/internal/page/context.ts +12 -59
- package/src/internal/page/dialogs.ts +58 -0
- package/src/internal/page/identity.ts +6 -5
- 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/{Cdp.ts → providers/Cdp.ts} +2 -2
- package/src/{Chromium.ts → providers/Chromium.ts} +7 -10
- package/src/providers/Released.ts +13 -0
- package/src/{internal/cdp.ts → providers/connection.ts} +2 -2
- package/src/{internal/pictures/motion.ts → stillness/Pixels.ts} +1 -1
- 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 +238 -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 +2 -2
- package/dist/Browser-CxXUjxOp.mjs +0 -619
- package/dist/Browser-CxXUjxOp.mjs.map +0 -1
- package/dist/Cdp-CzCRnMlM.d.mts +0 -10
- package/dist/Cdp.d.mts +0 -11
- 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-u3P_ENLX.d.mts +0 -62
- package/dist/Expect.d.mts +0 -2
- 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-BP02bmNv.mjs +0 -264
- package/dist/Page-BP02bmNv.mjs.map +0 -1
- package/dist/Plan-BG1WifW2.mjs.map +0 -1
- package/dist/Plan.d.mts +0 -2
- package/dist/Plan.mjs +0 -2
- package/dist/Policy.d.mts +0 -2
- package/dist/Policy.mjs.map +0 -1
- package/dist/Presentation-DxVikn9_.d.mts +0 -48
- package/dist/Presentation.d.mts +0 -2
- package/dist/Presentation.mjs +0 -118
- package/dist/Presentation.mjs.map +0 -1
- package/dist/Stage.d.mts +0 -2
- 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-CfRxbaso.d.mts +0 -317
- package/dist/Supervisor.d.mts +0 -2
- package/dist/Supervisor.mjs +0 -2
- package/dist/cdp-BMpYMWYe.mjs.map +0 -1
- package/dist/context-EGhOqjNN.mjs +0 -335
- package/dist/context-EGhOqjNN.mjs.map +0 -1
- package/dist/page-PTM8m5wC.mjs +0 -4057
- package/dist/page-PTM8m5wC.mjs.map +0 -1
- package/dist/url-Bsp2y55M.mjs +0 -264
- package/dist/url-Bsp2y55M.mjs.map +0 -1
- package/dist/workerd/index.d.mts +0 -16
- package/dist/workerd/index.mjs +0 -17
- 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/workerd/index.ts +0 -17
- /package/src/{internal/page/url.ts → Url.ts} +0 -0
- /package/src/{internal/pictures → stillness}/utilsBundle.d.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The page's actions: click, hover, drag, type, press, scroll and select, each sent in a style,
|
|
3
|
-
* plainly or performed for viewers
|
|
3
|
+
* plainly or performed for viewers. Each runs through
|
|
4
4
|
* `perform`, which admits it, puts it to the input guard and records it. A click, a key or a scroll
|
|
5
5
|
* then waits for the page to settle: a task and a frame, and a document if the input asked for one.
|
|
6
6
|
*/
|
|
@@ -8,6 +8,7 @@ import { Duration, Effect } from "effect";
|
|
|
8
8
|
|
|
9
9
|
import { NotActionable, StaleRef } from "../../BrowserError.ts";
|
|
10
10
|
import type { ClickOptions, PressOptions, ScrollOptions, Target, TypeOptions } from "../../Page.ts";
|
|
11
|
+
import { maximumDurationMillis } from "../../Style.ts";
|
|
11
12
|
import { type Bridge, scriptCall } from "../page/bridge.ts";
|
|
12
13
|
import { decodeWith, failWith, type PageContext, refuse } from "../page/context.ts";
|
|
13
14
|
import type { Viewport } from "../page/viewport.ts";
|
|
@@ -20,7 +21,6 @@ import * as Keys from "./keys.ts";
|
|
|
20
21
|
import * as Perform from "./perform.ts";
|
|
21
22
|
import * as Pointer from "./pointer.ts";
|
|
22
23
|
import * as Settle from "./settle.ts";
|
|
23
|
-
import { plain, type Style } from "./style.ts";
|
|
24
24
|
import * as Targets from "./targets.ts";
|
|
25
25
|
|
|
26
26
|
const partsOf = (page: PageContext, bridge: Bridge, viewport: Viewport) => {
|
|
@@ -45,55 +45,34 @@ const partsOf = (page: PageContext, bridge: Bridge, viewport: Viewport) => {
|
|
|
45
45
|
|
|
46
46
|
type Parts = ReturnType<typeof partsOf>;
|
|
47
47
|
|
|
48
|
-
/** Whether every number given is finite; a number left out is. */
|
|
49
|
-
const finite = (...values: ReadonlyArray<number | undefined>) =>
|
|
50
|
-
values.every((value) => value === undefined || Number.isFinite(value));
|
|
51
|
-
|
|
52
48
|
const named = (target: Target) => (typeof target === "string" ? target : `${target.x},${target.y}`);
|
|
53
49
|
|
|
54
50
|
/** The ref a target names, if it names one rather than a point. */
|
|
55
51
|
const refOf = (target: Target | undefined) => (typeof target === "string" ? target : undefined);
|
|
56
52
|
|
|
57
|
-
/**
|
|
58
|
-
const
|
|
59
|
-
finite(options.clickCount, options.holdMillis)
|
|
60
|
-
? Effect.void
|
|
61
|
-
: refuse("click", "clickCount and holdMillis must be finite");
|
|
62
|
-
|
|
63
|
-
/** The keys a press sends, once they and its options are valid. */
|
|
64
|
-
const pressed = (keys: string, options: PressOptions) => {
|
|
53
|
+
/** Key names have a finite vocabulary beyond the action's structural schema. */
|
|
54
|
+
const pressed = (keys: string) => {
|
|
65
55
|
const parts = Keys.parts(keys);
|
|
66
56
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return refuse("press", `"${keys}" is not a key; try Enter, Space, ArrowLeft or Control+A`);
|
|
71
|
-
|
|
72
|
-
return Effect.succeed(parts);
|
|
57
|
+
return parts === undefined
|
|
58
|
+
? refuse("press", `"${keys}" is not a key; try Enter, Space, ArrowLeft or Control+A`)
|
|
59
|
+
: Effect.succeed(parts);
|
|
73
60
|
};
|
|
74
61
|
|
|
75
62
|
const click = (input: Parts) => {
|
|
76
63
|
const { settings } = input.page;
|
|
77
64
|
const { perform, preparePolicy, targetFor, moveTo, sendMouse, flush, mark, settle } = input;
|
|
78
65
|
|
|
79
|
-
return (target: Target, clickOptions: ClickOptions = {}
|
|
66
|
+
return (target: Target, clickOptions: ClickOptions = {}) =>
|
|
80
67
|
perform(
|
|
81
|
-
"
|
|
68
|
+
{ _tag: "Click", target, options: clickOptions },
|
|
82
69
|
{
|
|
83
70
|
target: named(target),
|
|
84
|
-
options: {
|
|
85
|
-
button: clickOptions.button,
|
|
86
|
-
clickCount: clickOptions.clickCount,
|
|
87
|
-
holdMillis: clickOptions.holdMillis,
|
|
88
|
-
},
|
|
89
71
|
},
|
|
90
72
|
settings.actionTimeout,
|
|
91
|
-
|
|
92
|
-
Effect.andThen(preparePolicy("click", { target: refOf(target) }, [target])),
|
|
93
|
-
),
|
|
73
|
+
(action) => preparePolicy(action, { target: refOf(target) }, [target]),
|
|
94
74
|
(marks, approval) =>
|
|
95
75
|
Effect.gen(function* () {
|
|
96
|
-
yield* clickable(clickOptions);
|
|
97
76
|
const resolved = yield* targetFor("click", target, approval, marks);
|
|
98
77
|
const { point } = resolved;
|
|
99
78
|
const button = clickOptions.button ?? "left";
|
|
@@ -141,7 +120,6 @@ const click = (input: Parts) => {
|
|
|
141
120
|
|
|
142
121
|
return resolved;
|
|
143
122
|
}),
|
|
144
|
-
style,
|
|
145
123
|
);
|
|
146
124
|
};
|
|
147
125
|
|
|
@@ -149,12 +127,12 @@ const hover = (input: Parts) => {
|
|
|
149
127
|
const { settings } = input.page;
|
|
150
128
|
const { perform, preparePolicy, targetFor, moveTo, flush } = input;
|
|
151
129
|
|
|
152
|
-
return (target: Target
|
|
130
|
+
return (target: Target) =>
|
|
153
131
|
perform(
|
|
154
|
-
"
|
|
132
|
+
{ _tag: "Hover", target },
|
|
155
133
|
{ target: named(target) },
|
|
156
134
|
settings.actionTimeout,
|
|
157
|
-
preparePolicy(
|
|
135
|
+
(action) => preparePolicy(action, { target: refOf(target) }, [target]),
|
|
158
136
|
(marks, approval) =>
|
|
159
137
|
Effect.gen(function* () {
|
|
160
138
|
const resolved = yield* targetFor("hover", target, approval, marks);
|
|
@@ -165,45 +143,19 @@ const hover = (input: Parts) => {
|
|
|
165
143
|
yield* moveTo("hover", marks, point, resolved.cursor, "hover");
|
|
166
144
|
yield* flush("hover", marks.input);
|
|
167
145
|
}),
|
|
168
|
-
style,
|
|
169
146
|
);
|
|
170
147
|
};
|
|
171
148
|
|
|
172
|
-
/**
|
|
173
|
-
* The pointer's travel to a target, before its action is asked: no guard holds it, no action is
|
|
174
|
-
* recorded, and nothing is pressed. A guarded page aims nothing, as its input waits for approval.
|
|
175
|
-
*/
|
|
176
|
-
const aim = (input: Parts) => {
|
|
177
|
-
const { settings } = input.page;
|
|
178
|
-
const { perform, targetFor, moveTo, flush } = input;
|
|
179
|
-
|
|
180
|
-
return (target: Target, style: Style) =>
|
|
181
|
-
settings.guard === undefined
|
|
182
|
-
? perform(
|
|
183
|
-
"aim",
|
|
184
|
-
{ target: named(target), recorded: false },
|
|
185
|
-
settings.actionTimeout,
|
|
186
|
-
Effect.die("an aim is never put to a guard"),
|
|
187
|
-
(marks) =>
|
|
188
|
-
targetFor("aim", target, undefined, marks).pipe(
|
|
189
|
-
Effect.flatMap(({ point, cursor }) => moveTo("aim", marks, point, cursor)),
|
|
190
|
-
Effect.andThen(flush("aim", marks.input)),
|
|
191
|
-
),
|
|
192
|
-
style,
|
|
193
|
-
)
|
|
194
|
-
: Effect.void;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
149
|
const drag = (input: Parts) => {
|
|
198
150
|
const { settings } = input.page;
|
|
199
151
|
const { perform, preparePolicy, targetFor, resolve, moveTo, sendMouse, flush } = input;
|
|
200
152
|
|
|
201
|
-
return (from: Target, to: Target
|
|
153
|
+
return (from: Target, to: Target) =>
|
|
202
154
|
perform(
|
|
203
|
-
"
|
|
155
|
+
{ _tag: "Drag", from, to },
|
|
204
156
|
{ target: `${JSON.stringify(from)} -> ${JSON.stringify(to)}` },
|
|
205
157
|
settings.actionTimeout,
|
|
206
|
-
preparePolicy(
|
|
158
|
+
(action) => preparePolicy(action, {}, [from, to]),
|
|
207
159
|
(marks, approval) =>
|
|
208
160
|
Effect.gen(function* () {
|
|
209
161
|
yield* targetFor("drag", from, approval, marks);
|
|
@@ -230,7 +182,6 @@ const drag = (input: Parts) => {
|
|
|
230
182
|
yield* sendMouse("drag", marks.input, buttonAt("mouseReleased", end.point));
|
|
231
183
|
yield* flush("drag", marks.input);
|
|
232
184
|
}),
|
|
233
|
-
style,
|
|
234
185
|
);
|
|
235
186
|
};
|
|
236
187
|
|
|
@@ -239,30 +190,24 @@ const typeText = (input: Parts) => {
|
|
|
239
190
|
const { perform, preparePolicy, mutate, targetFor, moveTo, sendMouse, flush, evaluate } = input;
|
|
240
191
|
const { currentDocument, sameDocument, keyStroke, typeEvent, mark, settle } = input;
|
|
241
192
|
|
|
242
|
-
return (text: string, typeOptions: TypeOptions = {}
|
|
193
|
+
return (text: string, typeOptions: TypeOptions = {}) =>
|
|
243
194
|
perform(
|
|
244
|
-
"
|
|
195
|
+
{ _tag: "Type", text, options: typeOptions },
|
|
245
196
|
{
|
|
246
197
|
target: typeOptions.into,
|
|
247
|
-
options: {
|
|
248
|
-
replace: typeOptions.into === undefined ? false : typeOptions.replace,
|
|
249
|
-
submit: typeOptions.submit,
|
|
250
|
-
},
|
|
251
198
|
text,
|
|
252
|
-
secret: true,
|
|
253
199
|
},
|
|
254
200
|
settings.actionTimeout,
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
201
|
+
(action) =>
|
|
202
|
+
preparePolicy(action, { target: typeOptions.into, text }, [typeOptions.into ?? null], {
|
|
203
|
+
submit: typeOptions.submit ?? false,
|
|
204
|
+
}),
|
|
258
205
|
(marks, approval) =>
|
|
259
206
|
Effect.gen(function* () {
|
|
207
|
+
const events = yield* marks.style.typing(text, approval !== undefined);
|
|
260
208
|
const replace = typeOptions.replace ?? true;
|
|
261
209
|
const into = typeOptions.into;
|
|
262
210
|
|
|
263
|
-
if (into !== undefined && !/^e\d+$/.test(into))
|
|
264
|
-
return yield* refuse("type", `"${into}" is not a ref; refs look like e12`);
|
|
265
|
-
|
|
266
211
|
// A typed space or letter can press a focused button or change a control. Refuse
|
|
267
212
|
// those before any input, on every path.
|
|
268
213
|
const asked = scriptCall("typeable", into ?? null, typeOptions.secret === true);
|
|
@@ -333,7 +278,6 @@ const typeText = (input: Parts) => {
|
|
|
333
278
|
yield* sameDocument("type", since);
|
|
334
279
|
yield* keyStroke("type", marks.input, ["Delete"]);
|
|
335
280
|
} else {
|
|
336
|
-
const events = yield* marks.style.typing(text, approval !== undefined);
|
|
337
281
|
const keyed = events.some((event) => event.phase === "down");
|
|
338
282
|
|
|
339
283
|
const checks =
|
|
@@ -367,7 +311,6 @@ const typeText = (input: Parts) => {
|
|
|
367
311
|
yield* settle("type", before);
|
|
368
312
|
}
|
|
369
313
|
}),
|
|
370
|
-
style,
|
|
371
314
|
);
|
|
372
315
|
};
|
|
373
316
|
|
|
@@ -376,26 +319,37 @@ const press = (input: Parts) => {
|
|
|
376
319
|
const { perform, preparePolicy, currentDocument, sameDocument, keyStroke, flush } = input;
|
|
377
320
|
const { mark, settle, targetFor, mutate } = input;
|
|
378
321
|
|
|
379
|
-
return (keys: string, pressOptions: PressOptions = {}
|
|
322
|
+
return (keys: string, pressOptions: PressOptions = {}) =>
|
|
380
323
|
perform(
|
|
381
|
-
"
|
|
382
|
-
{ target: keys
|
|
324
|
+
{ _tag: "Press", keys, options: pressOptions },
|
|
325
|
+
{ target: keys },
|
|
383
326
|
settings.actionTimeout,
|
|
384
|
-
|
|
385
|
-
Effect.
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
327
|
+
(action) =>
|
|
328
|
+
Effect.suspend(() => pressed(keys)).pipe(
|
|
329
|
+
Effect.flatMap((parts) =>
|
|
330
|
+
preparePolicy(
|
|
331
|
+
action,
|
|
332
|
+
{ target: pressOptions.on, text: parts.join("+") },
|
|
333
|
+
[pressOptions.on ?? null],
|
|
334
|
+
{ keys: parts.join("+") },
|
|
335
|
+
),
|
|
391
336
|
),
|
|
392
337
|
),
|
|
393
|
-
),
|
|
394
338
|
(marks, approval) =>
|
|
395
339
|
Effect.gen(function* () {
|
|
396
|
-
const parts = yield* pressed(keys
|
|
340
|
+
const parts = yield* pressed(keys);
|
|
397
341
|
const times = Math.max(1, Math.min(50, pressOptions.times ?? 1));
|
|
398
|
-
const hold = pressOptions.holdMillis ?? 0;
|
|
342
|
+
const hold = Math.max(0, pressOptions.holdMillis ?? 0);
|
|
343
|
+
|
|
344
|
+
const gaps = yield* Effect.all(
|
|
345
|
+
Array.from({ length: times - 1 }, () => marks.style.keyGap),
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
const pacing = gaps.reduce((sum, gap) => sum + gap, 0);
|
|
349
|
+
|
|
350
|
+
if (times * hold + pacing > maximumDurationMillis)
|
|
351
|
+
return yield* refuse("press", "the key sequence exceeds the maximum duration");
|
|
352
|
+
yield* marks.present(pacing);
|
|
399
353
|
const activates = parts.at(-1) === "Enter" || parts.at(-1) === "Space";
|
|
400
354
|
const since = yield* currentDocument("press");
|
|
401
355
|
const on = pressOptions.on;
|
|
@@ -404,6 +358,9 @@ const press = (input: Parts) => {
|
|
|
404
358
|
if (on !== undefined) {
|
|
405
359
|
yield* marks.on(yield* targetFor("press", on, approval, marks));
|
|
406
360
|
|
|
361
|
+
// Focus handlers may change the page before the protocol reply returns.
|
|
362
|
+
yield* marks.sent;
|
|
363
|
+
|
|
407
364
|
const focused = yield* mutate("press", scriptCall("focusOn", on), approval).pipe(
|
|
408
365
|
Effect.flatMap(decodeWith("press", Script.EditResultSchema)),
|
|
409
366
|
);
|
|
@@ -423,17 +380,13 @@ const press = (input: Parts) => {
|
|
|
423
380
|
yield* sameDocument("press", since);
|
|
424
381
|
yield* keyStroke("press", marks.input, parts, hold);
|
|
425
382
|
if (index + 1 < times) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
yield* marks.present(gap);
|
|
429
|
-
due += hold + gap;
|
|
383
|
+
due += hold + (gaps[index] ?? 0);
|
|
430
384
|
if (due > now()) yield* Effect.sleep(Duration.millis(due - now()));
|
|
431
385
|
}
|
|
432
386
|
}
|
|
433
387
|
yield* flush("press", marks.input);
|
|
434
388
|
yield* settle("press", before);
|
|
435
389
|
}),
|
|
436
|
-
style,
|
|
437
390
|
);
|
|
438
391
|
};
|
|
439
392
|
|
|
@@ -442,30 +395,19 @@ const scroll = (input: Parts) => {
|
|
|
442
395
|
const { perform, preparePolicy, viewportFor, targetFor, resolve, moveTo, wheel, flush } = input;
|
|
443
396
|
const { mark, settle } = input;
|
|
444
397
|
|
|
445
|
-
return (scrollOptions: ScrollOptions = {}
|
|
398
|
+
return (scrollOptions: ScrollOptions = {}) => {
|
|
446
399
|
const target = scrollOptions.at;
|
|
447
400
|
|
|
448
|
-
const valid =
|
|
449
|
-
Number.isFinite(scrollOptions.dx ?? 0) && Number.isFinite(scrollOptions.dy ?? 0)
|
|
450
|
-
? Effect.void
|
|
451
|
-
: refuse("scroll", "scroll deltas must be finite");
|
|
452
|
-
|
|
453
401
|
return perform(
|
|
454
|
-
"
|
|
402
|
+
{ _tag: "Scroll", options: scrollOptions },
|
|
455
403
|
{
|
|
456
404
|
target: target === undefined ? undefined : named(target),
|
|
457
|
-
options: { dx: scrollOptions.dx, dy: scrollOptions.dy },
|
|
458
405
|
},
|
|
459
406
|
settings.actionTimeout,
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
// Scrolling the page has no target: whatever sits mid-viewport is not what is scrolled.
|
|
463
|
-
preparePolicy("scroll", { target: refOf(target) }, target === undefined ? [] : [target]),
|
|
464
|
-
),
|
|
465
|
-
),
|
|
407
|
+
(action) =>
|
|
408
|
+
preparePolicy(action, { target: refOf(target) }, target === undefined ? [] : [target]),
|
|
466
409
|
(marks, approval) =>
|
|
467
410
|
Effect.gen(function* () {
|
|
468
|
-
yield* valid;
|
|
469
411
|
// Over CDP the page reports its own viewport, so the read shares the action's deadline.
|
|
470
412
|
const viewport = yield* viewportFor("scroll");
|
|
471
413
|
|
|
@@ -480,6 +422,8 @@ const scroll = (input: Parts) => {
|
|
|
480
422
|
scrollOptions.dy ??
|
|
481
423
|
(scrollOptions.dx === undefined ? Math.round(viewport.height * 0.8) : 0);
|
|
482
424
|
|
|
425
|
+
const steps = yield* marks.style.wheel(dx, dy);
|
|
426
|
+
|
|
483
427
|
// A page scroll has no target, but viewers still see the cursor it lands on.
|
|
484
428
|
const resolved =
|
|
485
429
|
target !== undefined
|
|
@@ -498,11 +442,10 @@ const scroll = (input: Parts) => {
|
|
|
498
442
|
const before = mark();
|
|
499
443
|
|
|
500
444
|
yield* marks.sent;
|
|
501
|
-
yield* wheel("scroll", marks, point, dx, dy);
|
|
445
|
+
yield* wheel("scroll", marks, point, dx, dy, steps);
|
|
502
446
|
yield* flush("scroll", marks.input);
|
|
503
447
|
yield* settle("scroll", before);
|
|
504
448
|
}),
|
|
505
|
-
style,
|
|
506
449
|
);
|
|
507
450
|
};
|
|
508
451
|
};
|
|
@@ -513,10 +456,10 @@ const select = (input: Parts) => {
|
|
|
513
456
|
|
|
514
457
|
return (ref: string, values: ReadonlyArray<string>) =>
|
|
515
458
|
perform(
|
|
516
|
-
"
|
|
517
|
-
{ target: ref,
|
|
459
|
+
{ _tag: "Select", ref, values },
|
|
460
|
+
{ target: ref, text: values.join(", ") },
|
|
518
461
|
settings.actionTimeout,
|
|
519
|
-
preparePolicy(
|
|
462
|
+
(action) => preparePolicy(action, { target: ref, text: values.join(", ") }, [ref]),
|
|
520
463
|
(marks, approval) =>
|
|
521
464
|
Effect.gen(function* () {
|
|
522
465
|
yield* marks.on(yield* targetFor("select", ref, approval, marks));
|
|
@@ -553,7 +496,6 @@ export const make = (page: PageContext, bridge: Bridge, viewport: Viewport) => {
|
|
|
553
496
|
preparePolicy: parts.preparePolicy,
|
|
554
497
|
click: click(parts),
|
|
555
498
|
hover: hover(parts),
|
|
556
|
-
aim: aim(parts),
|
|
557
499
|
drag: drag(parts),
|
|
558
500
|
type: typeText(parts),
|
|
559
501
|
press: press(parts),
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
TextInserted,
|
|
13
13
|
WheelScrolled,
|
|
14
14
|
} from "../../BrowserEvent.ts";
|
|
15
|
-
import
|
|
15
|
+
import * as BrowserClock from "../../Clock.ts";
|
|
16
|
+
import type { Point } from "../../Geometry.ts";
|
|
16
17
|
import { type PageContext, reasonOf, undispatched } from "../page/context.ts";
|
|
17
|
-
import * as
|
|
18
|
-
import type * as Replies from "./replies.ts";
|
|
18
|
+
import type * as Replies from "../page/replies.ts";
|
|
19
19
|
|
|
20
20
|
export interface MouseEvent extends Point {
|
|
21
21
|
readonly type: "mouseMoved" | "mousePressed" | "mouseReleased" | "mouseWheel";
|
|
@@ -4,7 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Clock, Deferred, Duration, Effect, Exit, Option, type Scope } from "effect";
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
undispatched,
|
|
9
|
+
type BrowserError,
|
|
10
|
+
Busy,
|
|
11
|
+
Closed,
|
|
12
|
+
InvalidRequest,
|
|
13
|
+
Suspended,
|
|
14
|
+
} from "../../BrowserError.ts";
|
|
8
15
|
import type { DisconnectCause } from "../../BrowserEvent.ts";
|
|
9
16
|
|
|
10
17
|
interface Stopped {
|
|
@@ -86,14 +93,12 @@ export const make = (options: {
|
|
|
86
93
|
let ready = Deferred.makeUnsafe<Stopped, BrowserError>();
|
|
87
94
|
|
|
88
95
|
const error = (operation: string) =>
|
|
89
|
-
|
|
96
|
+
undispatched(
|
|
90
97
|
operation,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
dispatched: false,
|
|
96
|
-
});
|
|
98
|
+
options.closedBy() === undefined
|
|
99
|
+
? new Suspended()
|
|
100
|
+
: new Closed({ cause: options.closedBy() ?? "connection" }),
|
|
101
|
+
);
|
|
97
102
|
|
|
98
103
|
const stopped = (): Stopped => ({ since: options.sequence(), at: options.now() });
|
|
99
104
|
|
|
@@ -108,14 +113,13 @@ export const make = (options: {
|
|
|
108
113
|
Deferred.doneUnsafe(
|
|
109
114
|
ready,
|
|
110
115
|
Exit.fail(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
undispatched(
|
|
117
|
+
"suspend",
|
|
118
|
+
new Busy({
|
|
114
119
|
waitedMillis: Math.round(options.now() - before.startedAt),
|
|
115
120
|
ahead: before.inputs.size,
|
|
116
121
|
}),
|
|
117
|
-
|
|
118
|
-
}),
|
|
122
|
+
),
|
|
119
123
|
),
|
|
120
124
|
);
|
|
121
125
|
if (before._tag === "Open" && state._tag !== "Open") Deferred.doneUnsafe(refused, Exit.void);
|
|
@@ -148,11 +152,10 @@ export const make = (options: {
|
|
|
148
152
|
Duration.toMillis(duration.value) < 0
|
|
149
153
|
)
|
|
150
154
|
return Effect.fail(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}),
|
|
155
|
+
undispatched(
|
|
156
|
+
"suspend",
|
|
157
|
+
new InvalidRequest({ detail: "drain must be a finite nonnegative duration" }),
|
|
158
|
+
),
|
|
156
159
|
);
|
|
157
160
|
const id = ++next;
|
|
158
161
|
const leave = Effect.sync(() => apply({ _tag: "Leave", id }));
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { Schema } from "effect";
|
|
7
7
|
|
|
8
|
-
import type { Point } from "../../
|
|
8
|
+
import type { Point } from "../../Geometry.ts";
|
|
9
9
|
import type { Names } from "../reading/names.inpage.ts";
|
|
10
10
|
import { type Evidence, type EvidenceReader, EvidenceSchema } from "./evidence.inpage.ts";
|
|
11
11
|
import type { Targets } from "./targets.inpage.ts";
|
|
@@ -56,6 +56,7 @@ export interface ValidationOptions {
|
|
|
56
56
|
export const guard = (names: Names, targets: Targets, evidence: EvidenceReader) => {
|
|
57
57
|
const {
|
|
58
58
|
activeElement,
|
|
59
|
+
textEntry,
|
|
59
60
|
clean,
|
|
60
61
|
describe,
|
|
61
62
|
inCurrentDocument,
|
|
@@ -78,19 +79,19 @@ export const guard = (names: Names, targets: Targets, evidence: EvidenceReader)
|
|
|
78
79
|
const { controlOf, details, hitAt, hrefAttribute, linkOf, receives, within } = targets;
|
|
79
80
|
const { evidenceOf, isField, isFilled } = evidence;
|
|
80
81
|
|
|
82
|
+
const nativeActivation = (element: Element) =>
|
|
83
|
+
hrefAttribute(element) !== null ||
|
|
84
|
+
element.tagName === "BUTTON" ||
|
|
85
|
+
element.tagName === "SUMMARY" ||
|
|
86
|
+
(isInput(element) && element.type !== "hidden");
|
|
87
|
+
|
|
81
88
|
/**
|
|
82
89
|
* The element whose activation behaviour a click or key on `element` runs, as the browser
|
|
83
90
|
* resolves it along the composed path: a link, button, input, summary or a label's control.
|
|
84
91
|
*/
|
|
85
92
|
const activationTarget = (element: Element): Element | undefined => {
|
|
86
93
|
for (let node: Element | null = element; node !== null; node = parentOf(node)) {
|
|
87
|
-
if (
|
|
88
|
-
hrefAttribute(node) !== null ||
|
|
89
|
-
node.tagName === "BUTTON" ||
|
|
90
|
-
node.tagName === "SUMMARY" ||
|
|
91
|
-
(isInput(node) && node.type !== "hidden")
|
|
92
|
-
)
|
|
93
|
-
return node;
|
|
94
|
+
if (nativeActivation(node)) return node;
|
|
94
95
|
if (isLabel(node) && node.control !== null) return node.control;
|
|
95
96
|
}
|
|
96
97
|
|
|
@@ -114,10 +115,7 @@ export const guard = (names: Names, targets: Targets, evidence: EvidenceReader)
|
|
|
114
115
|
)
|
|
115
116
|
if (
|
|
116
117
|
node !== own &&
|
|
117
|
-
(
|
|
118
|
-
node.tagName === "BUTTON" ||
|
|
119
|
-
node.tagName === "SUMMARY" ||
|
|
120
|
-
(isInput(node) && node.type !== "hidden") ||
|
|
118
|
+
(nativeActivation(node) ||
|
|
121
119
|
isSelect(node) ||
|
|
122
120
|
isTextArea(node) ||
|
|
123
121
|
(isLabel(node) && node.control !== null && node.control !== own) ||
|
|
@@ -128,23 +126,6 @@ export const guard = (names: Names, targets: Targets, evidence: EvidenceReader)
|
|
|
128
126
|
return undefined;
|
|
129
127
|
};
|
|
130
128
|
|
|
131
|
-
const textEntry = (element: Element): boolean =>
|
|
132
|
-
(isInput(element) &&
|
|
133
|
-
![
|
|
134
|
-
"button",
|
|
135
|
-
"reset",
|
|
136
|
-
"submit",
|
|
137
|
-
"image",
|
|
138
|
-
"checkbox",
|
|
139
|
-
"radio",
|
|
140
|
-
"file",
|
|
141
|
-
"range",
|
|
142
|
-
"color",
|
|
143
|
-
"hidden",
|
|
144
|
-
].includes(element.type)) ||
|
|
145
|
-
isTextArea(element) ||
|
|
146
|
-
(isHtml(element) && element.isContentEditable);
|
|
147
|
-
|
|
148
129
|
const activatingRoles = new Set([
|
|
149
130
|
"button",
|
|
150
131
|
"link",
|
|
@@ -243,26 +224,19 @@ export const guard = (names: Names, targets: Targets, evidence: EvidenceReader)
|
|
|
243
224
|
? undefined
|
|
244
225
|
: defaultSubmitter(form);
|
|
245
226
|
|
|
246
|
-
const
|
|
227
|
+
const formValue = (
|
|
228
|
+
attribute: "action" | "method" | "target",
|
|
229
|
+
property: "formAction" | "formMethod" | "formTarget",
|
|
230
|
+
) =>
|
|
247
231
|
form === null
|
|
248
232
|
? undefined
|
|
249
|
-
: submitter?.hasAttribute(
|
|
250
|
-
? submitter
|
|
251
|
-
: form
|
|
233
|
+
: submitter?.hasAttribute(`form${attribute}`) === true
|
|
234
|
+
? submitter[property]
|
|
235
|
+
: form[attribute];
|
|
252
236
|
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
: submitter?.hasAttribute("formmethod") === true
|
|
257
|
-
? submitter.formMethod
|
|
258
|
-
: form.method;
|
|
259
|
-
|
|
260
|
-
const formTarget =
|
|
261
|
-
form === null
|
|
262
|
-
? undefined
|
|
263
|
-
: submitter?.hasAttribute("formtarget") === true
|
|
264
|
-
? submitter.formTarget
|
|
265
|
-
: form.target;
|
|
237
|
+
const formDestination = formValue("action", "formAction");
|
|
238
|
+
const formMethod = formValue("method", "formMethod");
|
|
239
|
+
const formTarget = formValue("target", "formTarget");
|
|
266
240
|
|
|
267
241
|
const link = linkOf(element);
|
|
268
242
|
const href = link === undefined ? null : hrefAttribute(link);
|
|
@@ -326,7 +300,7 @@ export const guard = (names: Names, targets: Targets, evidence: EvidenceReader)
|
|
|
326
300
|
metadata.href,
|
|
327
301
|
control === element ? null : refFor(control),
|
|
328
302
|
isInput(control) || isButton(control) ? control.type : control.tagName,
|
|
329
|
-
|
|
303
|
+
isDisabled(control),
|
|
330
304
|
control.getAttribute("readonly"),
|
|
331
305
|
control.getAttribute("aria-readonly"),
|
|
332
306
|
isHtml(control) && control.isContentEditable,
|
|
@@ -455,6 +429,9 @@ export const guard = (names: Names, targets: Targets, evidence: EvidenceReader)
|
|
|
455
429
|
return { ...prepared, evidence: explain() };
|
|
456
430
|
};
|
|
457
431
|
|
|
432
|
+
const bindings = (targets: PreparedInput["targets"]) =>
|
|
433
|
+
targets.map((target) => (target === null ? null : [target.ref, target.fingerprint]));
|
|
434
|
+
|
|
458
435
|
const validate = (
|
|
459
436
|
plan: InputPlan,
|
|
460
437
|
prepared: PreparedInput,
|
|
@@ -470,17 +447,7 @@ export const guard = (names: Names, targets: Targets, evidence: EvidenceReader)
|
|
|
470
447
|
? current.destination !== prepared.destination
|
|
471
448
|
: boundUrl(current.destination) !== boundUrl(prepared.destination)) ||
|
|
472
449
|
JSON.stringify(current.facts) !== JSON.stringify(prepared.facts) ||
|
|
473
|
-
current.targets
|
|
474
|
-
current.targets.some((target, index) => {
|
|
475
|
-
const previous = prepared.targets[index];
|
|
476
|
-
|
|
477
|
-
return target === null
|
|
478
|
-
? previous !== null
|
|
479
|
-
: previous === null ||
|
|
480
|
-
previous === undefined ||
|
|
481
|
-
target.ref !== previous.ref ||
|
|
482
|
-
target.fingerprint !== previous.fingerprint;
|
|
483
|
-
})
|
|
450
|
+
JSON.stringify(bindings(current.targets)) !== JSON.stringify(bindings(prepared.targets))
|
|
484
451
|
)
|
|
485
452
|
return {
|
|
486
453
|
error: "changed",
|