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
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/** A scoped, seeded Page for deterministic stories. Effects are explicit data, never page code. */
|
|
2
|
+
import { Clock, Deferred, Duration, Effect, Exit, Scope, Stream } from "effect";
|
|
3
|
+
|
|
4
|
+
import { type Action, nameOf, targetOf, recorded } from "../Action.ts";
|
|
5
|
+
import { checked, methods } from "../ActionPort.ts";
|
|
6
|
+
import { type BrowserError, Closed, NotActionable, undispatched } from "../BrowserError.ts";
|
|
7
|
+
import * as Events from "../BrowserEvent.ts";
|
|
8
|
+
import { monotonicMillis } from "../Clock.ts";
|
|
9
|
+
import type { Gate } from "../internal/input/gate.ts";
|
|
10
|
+
import * as Lane from "../internal/page/lane.ts";
|
|
11
|
+
import * as Timeline from "../internal/timeline/events.ts";
|
|
12
|
+
import { type Page, ResolvedTarget, State, Text, type UntilResult } from "../Page.ts";
|
|
13
|
+
import * as Url from "../Url.ts";
|
|
14
|
+
import * as Evidence from "./evidence.ts";
|
|
15
|
+
import * as Model from "./model.ts";
|
|
16
|
+
|
|
17
|
+
export type { Element, Seed } from "./model.ts";
|
|
18
|
+
|
|
19
|
+
const { unsupported } = Model;
|
|
20
|
+
|
|
21
|
+
const execution = (
|
|
22
|
+
model: ReturnType<typeof Model.make>,
|
|
23
|
+
lane: Lane.Lane,
|
|
24
|
+
now: () => number,
|
|
25
|
+
id: string,
|
|
26
|
+
timeline: ReturnType<typeof Timeline.make>,
|
|
27
|
+
gate?: Gate,
|
|
28
|
+
) => {
|
|
29
|
+
const outcomes: Array<Effect.Effect<string | void, BrowserError>> = [];
|
|
30
|
+
const actions: Array<Action> = [];
|
|
31
|
+
|
|
32
|
+
const perform = (action: Action): Effect.Effect<ResolvedTarget | string | void, BrowserError> => {
|
|
33
|
+
const operation = nameOf(action);
|
|
34
|
+
|
|
35
|
+
return lane.write(
|
|
36
|
+
operation,
|
|
37
|
+
Duration.seconds(10),
|
|
38
|
+
)(
|
|
39
|
+
Effect.suspend(() => {
|
|
40
|
+
const startedAt = now();
|
|
41
|
+
let dispatched = false;
|
|
42
|
+
let subject: Events.Subject | undefined;
|
|
43
|
+
let safe = recorded(action, action._tag !== "Type");
|
|
44
|
+
|
|
45
|
+
return Effect.gen(function* () {
|
|
46
|
+
yield* model.check(operation);
|
|
47
|
+
if (
|
|
48
|
+
action._tag === "Act" ||
|
|
49
|
+
((action._tag === "Back" || action._tag === "Select") && outcomes[0] === undefined)
|
|
50
|
+
)
|
|
51
|
+
return yield* unsupported(operation);
|
|
52
|
+
|
|
53
|
+
const target = targetOf(action);
|
|
54
|
+
const resolved = target === undefined ? undefined : yield* model.resolve(target);
|
|
55
|
+
|
|
56
|
+
subject = resolved?.subject;
|
|
57
|
+
safe = recorded(
|
|
58
|
+
action,
|
|
59
|
+
!(action._tag === "Type" && (action.options?.secret || resolved?.element.secret)),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (
|
|
63
|
+
resolved?.element.state?.disabled ||
|
|
64
|
+
resolved?.element.visible === false ||
|
|
65
|
+
(action._tag === "Type" &&
|
|
66
|
+
resolved !== undefined &&
|
|
67
|
+
(!resolved.element.editable || (action.options?.secret && !resolved.element.secret)))
|
|
68
|
+
)
|
|
69
|
+
return yield* undispatched(
|
|
70
|
+
operation,
|
|
71
|
+
new NotActionable({ detail: "the seeded element cannot take this input" }),
|
|
72
|
+
);
|
|
73
|
+
if (action._tag === "Drag") yield* model.resolve(action.to);
|
|
74
|
+
|
|
75
|
+
return yield* Effect.acquireUseRelease(
|
|
76
|
+
gate === undefined ? Effect.succeed(() => {}) : gate.enter(operation),
|
|
77
|
+
() =>
|
|
78
|
+
Effect.gen(function* () {
|
|
79
|
+
const outcome = outcomes.shift();
|
|
80
|
+
|
|
81
|
+
dispatched = true;
|
|
82
|
+
|
|
83
|
+
const value =
|
|
84
|
+
outcome === undefined
|
|
85
|
+
? undefined
|
|
86
|
+
: yield* outcome.pipe(
|
|
87
|
+
Effect.tapError((error) =>
|
|
88
|
+
Effect.sync(() => {
|
|
89
|
+
dispatched = error.dispatched;
|
|
90
|
+
}),
|
|
91
|
+
),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (action._tag === "Goto" || action._tag === "Reload") {
|
|
95
|
+
model.update(
|
|
96
|
+
{
|
|
97
|
+
...model.get(),
|
|
98
|
+
url: action._tag === "Goto" ? Url.redact(action.url) : model.get().url,
|
|
99
|
+
},
|
|
100
|
+
true,
|
|
101
|
+
);
|
|
102
|
+
timeline.publish(
|
|
103
|
+
new Events.Navigated({
|
|
104
|
+
at: now(),
|
|
105
|
+
page: id,
|
|
106
|
+
url: model.get().url ?? "about:blank",
|
|
107
|
+
document: model.document(),
|
|
108
|
+
sameDocument: false,
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (action._tag === "Click" && resolved !== undefined)
|
|
113
|
+
return new ResolvedTarget({
|
|
114
|
+
...resolved.subject,
|
|
115
|
+
element: resolved.ref,
|
|
116
|
+
point:
|
|
117
|
+
typeof target === "object"
|
|
118
|
+
? target
|
|
119
|
+
: {
|
|
120
|
+
x: resolved.element.box.x + resolved.element.box.width / 2,
|
|
121
|
+
y: resolved.element.box.y + resolved.element.box.height / 2,
|
|
122
|
+
},
|
|
123
|
+
cursor: "pointer",
|
|
124
|
+
box: resolved.element.box,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return value;
|
|
128
|
+
}),
|
|
129
|
+
(leave) => Effect.sync(leave),
|
|
130
|
+
);
|
|
131
|
+
}).pipe(
|
|
132
|
+
Effect.onExit((exit) =>
|
|
133
|
+
Effect.sync(() => {
|
|
134
|
+
if (dispatched) actions.push(safe);
|
|
135
|
+
timeline.publish(
|
|
136
|
+
new Events.Action({
|
|
137
|
+
at: now(),
|
|
138
|
+
startedAt,
|
|
139
|
+
page: id,
|
|
140
|
+
name: operation,
|
|
141
|
+
value: safe,
|
|
142
|
+
url: Url.redact(model.get().url ?? "about:blank"),
|
|
143
|
+
subject,
|
|
144
|
+
ok: Exit.isSuccess(exit),
|
|
145
|
+
dispatched,
|
|
146
|
+
error: Exit.isFailure(exit) ? "failed" : undefined,
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
}),
|
|
150
|
+
),
|
|
151
|
+
);
|
|
152
|
+
}),
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
perform,
|
|
158
|
+
succeedNext: (value?: string) =>
|
|
159
|
+
Effect.sync(() => {
|
|
160
|
+
outcomes.push(Effect.succeed(value));
|
|
161
|
+
}),
|
|
162
|
+
actions: Effect.sync(() => [...actions]),
|
|
163
|
+
failNext: (error: BrowserError) =>
|
|
164
|
+
Effect.sync(() => {
|
|
165
|
+
outcomes.push(Effect.fail(error));
|
|
166
|
+
}),
|
|
167
|
+
holdNext: () =>
|
|
168
|
+
Effect.sync(() => {
|
|
169
|
+
const entered = Deferred.makeUnsafe<void>();
|
|
170
|
+
const release = Deferred.makeUnsafe<void>();
|
|
171
|
+
|
|
172
|
+
outcomes.push(
|
|
173
|
+
Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release)),
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
return { entered: Deferred.await(entered), release: Deferred.succeed(release, undefined) };
|
|
177
|
+
}),
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/** Wait admission follows preceding input, then releases the lane while observing new evidence. */
|
|
182
|
+
const untilFor =
|
|
183
|
+
(model: ReturnType<typeof Model.make>, lane: Lane.Lane, now: () => number): Page["until"] =>
|
|
184
|
+
(query, want, millis) =>
|
|
185
|
+
lane
|
|
186
|
+
.read("until")(Effect.void)
|
|
187
|
+
.pipe(
|
|
188
|
+
Effect.andThen(
|
|
189
|
+
Effect.gen(function* () {
|
|
190
|
+
if (query.selector !== undefined) return yield* unsupported("until:selector");
|
|
191
|
+
if (!Number.isFinite(millis) || millis < 0) return yield* unsupported("until");
|
|
192
|
+
const deadline = now() + millis;
|
|
193
|
+
|
|
194
|
+
while (true) {
|
|
195
|
+
yield* model.check("until");
|
|
196
|
+
const found = model.find({ ...query, scope: query.scope ?? "document" });
|
|
197
|
+
|
|
198
|
+
const mark = model.mark(found);
|
|
199
|
+
|
|
200
|
+
const met =
|
|
201
|
+
want === "some"
|
|
202
|
+
? found.length > 0
|
|
203
|
+
: want === "none"
|
|
204
|
+
? found.length === 0
|
|
205
|
+
: mark !== want.other;
|
|
206
|
+
|
|
207
|
+
if (met || now() >= deadline) return { met, mark } satisfies UntilResult;
|
|
208
|
+
yield* Effect.sleep(Duration.millis(Math.min(50, deadline - now())));
|
|
209
|
+
}
|
|
210
|
+
}),
|
|
211
|
+
),
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
export const makeIn = Effect.fnUntraced(function* (
|
|
215
|
+
seed: Model.Seed = {},
|
|
216
|
+
options: {
|
|
217
|
+
readonly id?: string;
|
|
218
|
+
readonly connection?: string;
|
|
219
|
+
readonly session?: string;
|
|
220
|
+
readonly gate?: Gate;
|
|
221
|
+
readonly closedBy?: () => Events.DisconnectCause | undefined;
|
|
222
|
+
readonly disconnected?: Effect.Effect<Events.DisconnectCause>;
|
|
223
|
+
readonly timeline?: ReturnType<typeof Timeline.make>;
|
|
224
|
+
} = {},
|
|
225
|
+
) {
|
|
226
|
+
const clock = yield* Clock.Clock;
|
|
227
|
+
const scope = yield* Scope.Scope;
|
|
228
|
+
const now = () => monotonicMillis(clock);
|
|
229
|
+
const id = options.id ?? "test-page";
|
|
230
|
+
const connection = options.connection ?? "test-connection";
|
|
231
|
+
const model = Model.make(seed, options.closedBy);
|
|
232
|
+
const timeline = options.timeline ?? Timeline.make(4096);
|
|
233
|
+
|
|
234
|
+
const lane = Lane.make({
|
|
235
|
+
now,
|
|
236
|
+
actionTimeout: Duration.seconds(10),
|
|
237
|
+
documentAt: model.document,
|
|
238
|
+
scope,
|
|
239
|
+
gone: (operation) => undispatched(operation, new Closed({ cause: "page" })),
|
|
240
|
+
beforeWrite: options.gate?.check,
|
|
241
|
+
refusal: options.gate?.refused,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const evidence = yield* Evidence.make({
|
|
245
|
+
id,
|
|
246
|
+
connection,
|
|
247
|
+
session: options.session ?? "test-browser",
|
|
248
|
+
now,
|
|
249
|
+
model,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
if (options.disconnected !== undefined)
|
|
253
|
+
yield* options.disconnected.pipe(Effect.andThen(evidence.close), Effect.forkIn(scope));
|
|
254
|
+
|
|
255
|
+
const run = execution(model, lane, now, id, timeline, options.gate);
|
|
256
|
+
|
|
257
|
+
const own = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
258
|
+
Effect.provideService(effect, Clock.Clock, clock);
|
|
259
|
+
|
|
260
|
+
const read = <A>(operation: string, work: () => A) =>
|
|
261
|
+
own(lane.read(operation)(Effect.andThen(model.check(operation), Effect.sync(work))));
|
|
262
|
+
|
|
263
|
+
const perform: Page["perform"] = checked((action) => own(run.perform(action)));
|
|
264
|
+
|
|
265
|
+
const page: Page = {
|
|
266
|
+
...methods(perform),
|
|
267
|
+
id,
|
|
268
|
+
clock,
|
|
269
|
+
perform,
|
|
270
|
+
until: (query, want, millis) => own(untilFor(model, lane, now)(query, want, millis)),
|
|
271
|
+
afterInput: (effect) => own(lane.read("afterInput")(effect)),
|
|
272
|
+
read: () => unsupported("read"),
|
|
273
|
+
act: () => unsupported("act"),
|
|
274
|
+
url: Effect.sync(() => Url.redact(model.get().url ?? "about:blank")),
|
|
275
|
+
title: read("title", () => model.get().title ?? ""),
|
|
276
|
+
bringToFront: model.check("bringToFront"),
|
|
277
|
+
close: Effect.andThen(
|
|
278
|
+
Effect.sync(() => {
|
|
279
|
+
if (model.close())
|
|
280
|
+
timeline.publish(new Events.PageClosed({ at: now(), page: id, cause: "page" }));
|
|
281
|
+
}),
|
|
282
|
+
evidence.close,
|
|
283
|
+
),
|
|
284
|
+
find: (query) =>
|
|
285
|
+
query?.selector !== undefined
|
|
286
|
+
? unsupported("find:selector")
|
|
287
|
+
: read("find", () => model.find(query)),
|
|
288
|
+
snapshot: (options) =>
|
|
289
|
+
options?.within !== undefined
|
|
290
|
+
? unsupported("snapshot:within")
|
|
291
|
+
: read("snapshot", () => model.snapshot(options)),
|
|
292
|
+
text: (options) =>
|
|
293
|
+
options?.scope !== undefined && options.scope !== "viewport"
|
|
294
|
+
? unsupported("text:scope")
|
|
295
|
+
: read("text", () => {
|
|
296
|
+
const snapshot = model.snapshot({ maxChars: options?.maxChars });
|
|
297
|
+
|
|
298
|
+
return new Text({
|
|
299
|
+
url: snapshot.url,
|
|
300
|
+
title: snapshot.title,
|
|
301
|
+
text: snapshot.text,
|
|
302
|
+
truncated: snapshot.truncated,
|
|
303
|
+
at: now(),
|
|
304
|
+
});
|
|
305
|
+
}),
|
|
306
|
+
viewport: read("viewport", () => model.get().viewport ?? { width: 800, height: 600 }),
|
|
307
|
+
state: Effect.sync(
|
|
308
|
+
() =>
|
|
309
|
+
new State({
|
|
310
|
+
page: id,
|
|
311
|
+
connection,
|
|
312
|
+
at: now(),
|
|
313
|
+
document: model.document(),
|
|
314
|
+
url: Url.redact(model.get().url ?? "about:blank"),
|
|
315
|
+
}),
|
|
316
|
+
),
|
|
317
|
+
screenshot: (options) =>
|
|
318
|
+
options === undefined
|
|
319
|
+
? Effect.map(evidence.frame(), (frame) => frame.image)
|
|
320
|
+
: unsupported("screenshot"),
|
|
321
|
+
frame: evidence.frame,
|
|
322
|
+
zoom: () => unsupported("zoom"),
|
|
323
|
+
ready: () =>
|
|
324
|
+
model.get().ready === true ? read("ready", () => undefined) : unsupported("ready"),
|
|
325
|
+
capture: evidence.capture,
|
|
326
|
+
screencast: (options) =>
|
|
327
|
+
Stream.unwrap(Effect.map(evidence.capture(options), (capture) => capture.stream)),
|
|
328
|
+
captureStats: () => unsupported("captureStats"),
|
|
329
|
+
recentFrames: evidence.recentFrames,
|
|
330
|
+
changes: evidence.changes,
|
|
331
|
+
window: () => unsupported("window"),
|
|
332
|
+
recentEvents: Effect.map(timeline.recent, (records) =>
|
|
333
|
+
records
|
|
334
|
+
.filter((record) => "page" in record.event && record.event.page === id)
|
|
335
|
+
.map((record) => record.event),
|
|
336
|
+
),
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
yield* Effect.addFinalizer(() =>
|
|
340
|
+
Effect.sync(() => {
|
|
341
|
+
model.close();
|
|
342
|
+
}),
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
return {
|
|
346
|
+
page,
|
|
347
|
+
emitFrame: evidence.emitFrame,
|
|
348
|
+
event: (event: Events.BrowserEvent) =>
|
|
349
|
+
Effect.sync(() => {
|
|
350
|
+
timeline.publish(event);
|
|
351
|
+
}),
|
|
352
|
+
succeedNext: run.succeedNext,
|
|
353
|
+
isClosed: Effect.sync(model.isClosed),
|
|
354
|
+
actions: run.actions,
|
|
355
|
+
holdNext: run.holdNext,
|
|
356
|
+
failNext: run.failNext,
|
|
357
|
+
update: (seed: Model.Seed) => Effect.sync(() => model.update(seed)),
|
|
358
|
+
document: (seed: Model.Seed) => Effect.sync(() => model.update(seed, true)),
|
|
359
|
+
};
|
|
360
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CDP lifetime for Workers. The consumer supplies a runtime-compatible Playwright connector;
|
|
3
|
+
* this entry imports no Playwright Node transport.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.3.0
|
|
6
|
+
*/
|
|
7
|
+
import { make } from "../providers/connection.ts";
|
|
8
|
+
|
|
9
|
+
export type { Connector, ConnectOptions, Options } from "../providers/connection.ts";
|
|
10
|
+
|
|
11
|
+
export const { open, layer } = make();
|