effect-browser 0.2.0-beta.9 → 0.3.0-beta.6
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 +707 -1184
- package/dist/Browser-B5AV7zPS.mjs +437 -0
- package/dist/Browser-B5AV7zPS.mjs.map +1 -0
- package/dist/Browser.d.mts +115 -3
- package/dist/Browser.mjs +2 -22
- package/dist/BrowserError-DXXIA6Rk.d.mts +135 -0
- package/dist/BrowserError.d.mts +2 -0
- package/dist/BrowserError.mjs +202 -0
- package/dist/BrowserError.mjs.map +1 -0
- package/dist/BrowserEvent-DzdNdvoh.d.mts +277 -0
- package/dist/BrowserEvent.d.mts +2 -0
- package/dist/BrowserEvent.mjs +295 -0
- package/dist/BrowserEvent.mjs.map +1 -0
- package/dist/Cdp.d.mts +32 -0
- package/dist/Cdp.mjs +61 -0
- package/dist/Cdp.mjs.map +1 -0
- package/dist/Change-DNvztNLu.mjs +138 -0
- package/dist/Change-DNvztNLu.mjs.map +1 -0
- package/dist/Change-DVP2IJWm.d.mts +71 -0
- package/dist/Change.d.mts +2 -0
- package/dist/Change.mjs +2 -0
- package/dist/Chromium.d.mts +29 -81
- package/dist/Chromium.mjs +57 -392
- package/dist/Chromium.mjs.map +1 -1
- package/dist/Expect.d.mts +62 -0
- package/dist/Expect.mjs +114 -0
- package/dist/Expect.mjs.map +1 -0
- package/dist/Frame-BERmf_gM.d.mts +117 -0
- package/dist/Frame.d.mts +2 -0
- package/dist/Frame.mjs +123 -0
- package/dist/Frame.mjs.map +1 -0
- package/dist/Moment.d.mts +2 -0
- package/dist/Moment.mjs +288 -0
- package/dist/Moment.mjs.map +1 -0
- package/dist/Motion.d.mts +40 -0
- package/dist/Motion.mjs +122 -0
- package/dist/Motion.mjs.map +1 -0
- package/dist/Page-D4281dIi.mjs +618 -0
- package/dist/Page-D4281dIi.mjs.map +1 -0
- package/dist/Page-DYTdVhYa.d.mts +593 -0
- package/dist/Page.d.mts +2 -0
- package/dist/Page.mjs +2 -0
- package/dist/Plan-5MdsRzE5.mjs +314 -0
- package/dist/Plan-5MdsRzE5.mjs.map +1 -0
- package/dist/Plan-CNNOU1Tx.d.mts +112 -0
- package/dist/Plan.d.mts +2 -3
- package/dist/Plan.mjs +2 -2
- package/dist/Policy.d.mts +76 -0
- package/dist/Policy.mjs +237 -0
- package/dist/Policy.mjs.map +1 -0
- package/dist/Presentation.d.mts +48 -0
- package/dist/Presentation.mjs +117 -0
- package/dist/Presentation.mjs.map +1 -0
- package/dist/Snapshot-B34hZ4Jl.d.mts +68 -0
- package/dist/Snapshot.d.mts +2 -0
- package/dist/Snapshot.mjs +79 -0
- package/dist/Snapshot.mjs.map +1 -0
- package/dist/Stage.d.mts +54 -0
- package/dist/Stage.mjs +133 -0
- package/dist/Stage.mjs.map +1 -0
- package/dist/Supervisor-BtEG93gR.mjs +420 -0
- package/dist/Supervisor-BtEG93gR.mjs.map +1 -0
- package/dist/Supervisor-Im6-wbg5.d.mts +230 -0
- package/dist/Supervisor.d.mts +2 -0
- package/dist/Supervisor.mjs +2 -0
- package/dist/context-DAYjATgC.mjs +137 -0
- package/dist/context-DAYjATgC.mjs.map +1 -0
- package/dist/index.d.mts +17 -14
- package/dist/index.mjs +18 -13
- package/dist/match.inpage-xOe9LNO0.mjs +48 -0
- package/dist/match.inpage-xOe9LNO0.mjs.map +1 -0
- package/dist/page-BkRcLCWZ.mjs +5097 -0
- package/dist/page-BkRcLCWZ.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/url-CcL0K7S0.mjs +262 -0
- package/dist/url-CcL0K7S0.mjs.map +1 -0
- package/package.json +96 -61
- package/src/Browser.ts +625 -0
- package/src/BrowserError.ts +225 -0
- package/src/BrowserEvent.ts +294 -0
- package/src/Cdp.ts +101 -0
- package/src/Change.ts +88 -0
- package/src/Chromium.ts +102 -0
- package/src/Expect.ts +180 -0
- package/src/Frame.ts +130 -0
- package/src/Moment.ts +479 -0
- package/src/Motion.ts +166 -0
- package/src/Page.ts +520 -0
- package/src/Plan.ts +354 -0
- package/src/Policy.ts +325 -0
- package/src/Presentation.ts +195 -0
- package/src/Snapshot.ts +89 -0
- package/src/Stage.ts +223 -0
- package/src/Supervisor.ts +353 -0
- package/src/index.ts +20 -0
- package/src/internal/input/actions.ts +610 -0
- package/src/internal/input/dispatch.ts +161 -0
- package/src/internal/input/edit.inpage.ts +162 -0
- package/src/internal/input/evidence.inpage.ts +164 -0
- package/src/internal/input/guard.inpage.ts +605 -0
- package/src/internal/input/guard.ts +183 -0
- package/src/internal/input/keyboard.ts +112 -0
- package/src/internal/input/keys.ts +127 -0
- package/src/internal/input/perform.ts +322 -0
- package/src/internal/input/pointer.ts +153 -0
- package/src/internal/input/replies.ts +159 -0
- package/src/internal/input/settle.ts +50 -0
- package/src/internal/input/style.ts +186 -0
- package/src/internal/input/targets.inpage.ts +293 -0
- package/src/internal/input/targets.ts +148 -0
- package/src/internal/page/bridge.ts +386 -0
- package/src/internal/page/context.ts +302 -0
- package/src/internal/page/lane.ts +301 -0
- package/src/internal/page/navigation.ts +183 -0
- package/src/internal/page/openings.ts +87 -0
- package/src/internal/page/page.ts +137 -0
- package/src/internal/page/url.ts +100 -0
- package/src/internal/page/viewport.ts +43 -0
- package/src/internal/pictures/capture.ts +778 -0
- package/src/internal/pictures/clock.ts +141 -0
- package/src/internal/pictures/pictures.ts +520 -0
- package/src/internal/pictures/transport.ts +242 -0
- package/src/internal/reading/choose.ts +100 -0
- package/src/internal/reading/context.inpage.ts +201 -0
- package/src/internal/reading/controls.inpage.ts +158 -0
- package/src/internal/reading/expect.inpage.ts +70 -0
- package/src/internal/reading/match.inpage.ts +92 -0
- package/src/internal/reading/names.inpage.ts +306 -0
- package/src/internal/reading/outline.inpage.ts +260 -0
- package/src/internal/reading/reading.ts +223 -0
- package/src/internal/reading/ready.inpage.ts +154 -0
- package/src/internal/reading/ready.ts +105 -0
- package/src/internal/reading/subjects.inpage.ts +188 -0
- package/src/internal/reading/text.inpage.ts +135 -0
- package/src/internal/reading/walk.inpage.ts +220 -0
- package/src/internal/supervisor/lifecycle.ts +265 -0
- package/src/internal/timeline/changes.inpage.ts +216 -0
- package/src/internal/timeline/changes.ts +100 -0
- package/src/internal/timeline/events.ts +93 -0
- package/src/internal/timeline/fold.inpage.ts +123 -0
- package/src/internal/timeline/history.inpage.ts +229 -0
- package/src/internal/timeline/marks.inpage.ts +207 -0
- package/src/internal/timeline/record.inpage.ts +133 -0
- package/src/internal/timeline/sight.inpage.ts +122 -0
- package/src/internal/timeline/window.ts +96 -0
- package/src/internal/timeline/words.ts +65 -0
- package/dist/Bootstrap-B9UUXsvF.d.mts +0 -183
- package/dist/Bootstrap-CeQOWBy6.mjs +0 -189
- package/dist/Bootstrap-CeQOWBy6.mjs.map +0 -1
- package/dist/Bootstrap.d.mts +0 -3
- package/dist/Bootstrap.mjs +0 -2
- package/dist/Browser-BF9_sORP.d.mts +0 -388
- package/dist/Browser.mjs.map +0 -1
- package/dist/BrowserData-CPIIIHol.d.mts +0 -585
- package/dist/BrowserData.d.mts +0 -3
- package/dist/BrowserData.mjs +0 -695
- package/dist/BrowserData.mjs.map +0 -1
- package/dist/BrowserRuntime-B6nT1G4X.d.mts +0 -148
- package/dist/BrowserRuntime-C1r2aSRK.mjs +0 -6820
- package/dist/BrowserRuntime-C1r2aSRK.mjs.map +0 -1
- package/dist/BrowserRuntime.d.mts +0 -3
- package/dist/BrowserRuntime.mjs +0 -3
- package/dist/Capture.d.mts +0 -56
- package/dist/Capture.mjs +0 -678
- package/dist/Capture.mjs.map +0 -1
- package/dist/CaptureData-CYriZHX1.mjs +0 -201
- package/dist/CaptureData-CYriZHX1.mjs.map +0 -1
- package/dist/CaptureData.d.mts +0 -219
- package/dist/CaptureData.mjs +0 -2
- package/dist/Errors.d.mts +0 -158
- package/dist/Errors.mjs +0 -207
- package/dist/Errors.mjs.map +0 -1
- package/dist/Images-yCG9BmRU.mjs +0 -76
- package/dist/Images-yCG9BmRU.mjs.map +0 -1
- package/dist/OperationOptions-DAeRS6O9.mjs +0 -55
- package/dist/OperationOptions-DAeRS6O9.mjs.map +0 -1
- package/dist/PageControl.d.mts +0 -15
- package/dist/PageControl.mjs +0 -34
- package/dist/PageControl.mjs.map +0 -1
- package/dist/PageRegistry-B3q9DS3g.mjs +0 -164
- package/dist/PageRegistry-B3q9DS3g.mjs.map +0 -1
- package/dist/Plan-Dyxu2q8C.mjs +0 -543
- package/dist/Plan-Dyxu2q8C.mjs.map +0 -1
- package/dist/PlanData-B668RxbQ.d.mts +0 -4831
- package/dist/PlanData.d.mts +0 -3
- package/dist/PlanData.mjs +0 -268
- package/dist/PlanData.mjs.map +0 -1
- package/dist/PlanInput-BJcPPncs.mjs +0 -75
- package/dist/PlanInput-BJcPPncs.mjs.map +0 -1
- package/dist/PublicSession-DCSMMqOj.mjs +0 -5602
- package/dist/PublicSession-DCSMMqOj.mjs.map +0 -1
- package/dist/Testing.d.mts +0 -479
- package/dist/Testing.mjs +0 -2147
- package/dist/Testing.mjs.map +0 -1
- package/dist/Timeline-fV22Xk-S.d.mts +0 -29
- package/dist/Timeline.d.mts +0 -4
- package/dist/Timeline.mjs +0 -20
- package/dist/Timeline.mjs.map +0 -1
- package/dist/TimelineData-BsOn-YGZ.d.mts +0 -3818
- package/dist/TimelineData.d.mts +0 -3
- package/dist/TimelineData.mjs +0 -482
- package/dist/TimelineData.mjs.map +0 -1
package/src/Page.ts
ADDED
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One browser tab: navigation, snapshots, pictures and input.
|
|
3
|
+
*
|
|
4
|
+
* A page waits only for itself: its operations take turns in one lane of its own. An action, which
|
|
5
|
+
* sends input or navigates, has the page to itself, in the order actions were asked; reads share
|
|
6
|
+
* it, after the action in flight and every action asked before them, so a read describes the page
|
|
7
|
+
* an action left. A wait for a turn ends at the operation's deadline as `Busy`, never `Timeout`,
|
|
8
|
+
* and a full deadline then bounds the operation itself; `failFast` fails it at once instead.
|
|
9
|
+
* Identical reads asked between the same actions share one call to the page, and one whose
|
|
10
|
+
* callers gave up finishes for the next caller to ask it. A policy holds outside the lane while
|
|
11
|
+
* other operations continue; its target is revalidated before dispatch. Element targets are refs
|
|
12
|
+
* from a snapshot; point targets are viewport coordinates in CSS pixels, the same coordinates as a
|
|
13
|
+
* screenshot's pixels. Mouse and keyboard input share a bounded pipeline, so pacing does not wait
|
|
14
|
+
* for each protocol reply. Target lookup happens before the input is sent.
|
|
15
|
+
*
|
|
16
|
+
* @since 0.3.0
|
|
17
|
+
*/
|
|
18
|
+
import { type Duration, Effect, Schema, type Stream } from "effect";
|
|
19
|
+
import type { Page as PlaywrightPage } from "playwright-core";
|
|
20
|
+
|
|
21
|
+
import { type BrowserError, type PolicyDenied } from "./BrowserError.ts";
|
|
22
|
+
import { Box, type BrowserEvent, PageLoaded, Subject, SubjectContext } from "./BrowserEvent.ts";
|
|
23
|
+
import type { Changes } from "./Change.ts";
|
|
24
|
+
import { type CaptureStats, Frame, Image, type ScreencastOptions } from "./Frame.ts";
|
|
25
|
+
import { FormFieldSchema } from "./internal/input/evidence.inpage.ts";
|
|
26
|
+
import * as Guard from "./internal/input/guard.inpage.ts";
|
|
27
|
+
import { Correlation, FailFast } from "./internal/page/lane.ts";
|
|
28
|
+
import * as Url from "./internal/page/url.ts";
|
|
29
|
+
import type { Window } from "./Moment.ts";
|
|
30
|
+
import { type Snapshot, type SnapshotOptions } from "./Snapshot.ts";
|
|
31
|
+
|
|
32
|
+
export interface Point {
|
|
33
|
+
readonly x: number;
|
|
34
|
+
readonly y: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A ref from a snapshot, such as `"e12"`, or a viewport point. */
|
|
38
|
+
export type Target = string | Point;
|
|
39
|
+
|
|
40
|
+
/** An integer rectangle in viewport CSS pixels. */
|
|
41
|
+
export class Region extends Schema.Class<Region>("effect-browser/Region")({
|
|
42
|
+
x: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
43
|
+
y: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
44
|
+
width: Schema.Int.check(Schema.isGreaterThan(0)),
|
|
45
|
+
height: Schema.Int.check(Schema.isGreaterThan(0)),
|
|
46
|
+
}) {}
|
|
47
|
+
|
|
48
|
+
/** A crop and its viewport origin: add that origin to a point read from the crop. */
|
|
49
|
+
export class Zoom extends Schema.Class<Zoom>("effect-browser/Zoom")({
|
|
50
|
+
page: Schema.String,
|
|
51
|
+
region: Region,
|
|
52
|
+
image: Image,
|
|
53
|
+
}) {}
|
|
54
|
+
|
|
55
|
+
/** The target as it read before input. Point coordinates are never snapped to another position. */
|
|
56
|
+
export class ResolvedTarget extends Schema.Class<ResolvedTarget>("effect-browser/ResolvedTarget")({
|
|
57
|
+
point: Schema.Struct({ x: Schema.Finite, y: Schema.Finite }),
|
|
58
|
+
element: Schema.String,
|
|
59
|
+
/** The element's lowercase tag name. */
|
|
60
|
+
tag: Schema.String,
|
|
61
|
+
role: Schema.NullOr(Schema.String),
|
|
62
|
+
name: Schema.String,
|
|
63
|
+
context: SubjectContext,
|
|
64
|
+
/** For a point target, the box of what it found there. */
|
|
65
|
+
box: Schema.optional(Box),
|
|
66
|
+
cursor: Schema.String,
|
|
67
|
+
href: Schema.optional(Schema.String),
|
|
68
|
+
}) {}
|
|
69
|
+
|
|
70
|
+
export interface ClickOptions {
|
|
71
|
+
readonly button?: "left" | "right" | "middle" | undefined;
|
|
72
|
+
/** 2 for a double click. */
|
|
73
|
+
readonly clickCount?: number | undefined;
|
|
74
|
+
/** Hold the button down this long before releasing it. */
|
|
75
|
+
readonly holdMillis?: number | undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface TypeOptions {
|
|
79
|
+
/** Type into this text field: it is focused first, and its content replaced unless `replace` is false. */
|
|
80
|
+
readonly into?: string | undefined;
|
|
81
|
+
readonly replace?: boolean | undefined;
|
|
82
|
+
/** Press Enter afterwards. */
|
|
83
|
+
readonly submit?: boolean | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* The text is a secret: type it only into a field the page marks secret, such as a password,
|
|
86
|
+
* and otherwise refuse with `NotActionable` before any input. A replayed password asks this.
|
|
87
|
+
*/
|
|
88
|
+
readonly secret?: boolean | undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface PressOptions {
|
|
92
|
+
/**
|
|
93
|
+
* Focus this element, by ref, before the first press: a link, a button or a field. The keys go to
|
|
94
|
+
* whatever has focus otherwise.
|
|
95
|
+
*/
|
|
96
|
+
readonly on?: string | undefined;
|
|
97
|
+
/** Press the keys this many times. */
|
|
98
|
+
readonly times?: number | undefined;
|
|
99
|
+
/** Hold the keys down this long before releasing them, as a game control might need. */
|
|
100
|
+
readonly holdMillis?: number | undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface ScrollOptions {
|
|
104
|
+
readonly dx?: number | undefined;
|
|
105
|
+
/** Pixels to scroll down; negative scrolls up. Defaults to most of a viewport. */
|
|
106
|
+
readonly dy?: number | undefined;
|
|
107
|
+
/** Scroll whatever is under this point or element. Defaults to the middle of the viewport. */
|
|
108
|
+
readonly at?: Target | undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* How current a picture must be. The newest screencast frame serves when it qualifies, at no cost;
|
|
113
|
+
* otherwise a new screenshot is taken.
|
|
114
|
+
*/
|
|
115
|
+
export interface FrameOptions {
|
|
116
|
+
/**
|
|
117
|
+
* The oldest a reused frame may be, from its paint, at the earliest its timing allows, to now.
|
|
118
|
+
* Defaults to 250 milliseconds; 0 always takes a new screenshot.
|
|
119
|
+
*/
|
|
120
|
+
readonly maxAge?: Duration.Input | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* `"input"`: reuse only a frame painted after this page's latest input, including input of an
|
|
123
|
+
* interrupted action, and never while an action is changing the page. For a caller that has
|
|
124
|
+
* just acted on the page.
|
|
125
|
+
*/
|
|
126
|
+
readonly after?: "input" | undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A screenshot reuses only a frame painted after the page's latest input, as `after: "input"`. */
|
|
130
|
+
export interface ScreenshotOptions {
|
|
131
|
+
/** The oldest a reused frame may be, as for `frame`. Defaults to 250 milliseconds. */
|
|
132
|
+
readonly maxAge?: Duration.Input | undefined;
|
|
133
|
+
/** A region of the viewport, captured in CSS pixels at the viewport's own scale; always new. */
|
|
134
|
+
readonly clip?:
|
|
135
|
+
| { readonly x: number; readonly y: number; readonly width: number; readonly height: number }
|
|
136
|
+
| undefined;
|
|
137
|
+
/** JPEG quality, 0 to 100. Defaults to 80. */
|
|
138
|
+
readonly quality?: number | undefined;
|
|
139
|
+
/** `"jpeg"`, the default, or `"png"`, which is always a new picture. */
|
|
140
|
+
readonly format?: "jpeg" | "png" | undefined;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* What `find` looks for. Every rule given must hold; with none, it finds every element in scope
|
|
145
|
+
* that has a role or is a control.
|
|
146
|
+
*/
|
|
147
|
+
export interface FindQuery {
|
|
148
|
+
/** An ARIA role, such as `"button"` or `"heading"`, ignoring case. */
|
|
149
|
+
readonly role?: string | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* The accessible name: a string that reads the same once spaces are collapsed and case folded,
|
|
152
|
+
* or a pattern found in it.
|
|
153
|
+
*/
|
|
154
|
+
readonly name?: string | RegExp | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Text it shows, ignoring case and spacing, or a pattern. Text inside a control or a heading is
|
|
157
|
+
* that control's or heading's, and only the smallest element showing it matches, not every
|
|
158
|
+
* element around it.
|
|
159
|
+
*/
|
|
160
|
+
readonly text?: string | RegExp | undefined;
|
|
161
|
+
/** Whole words in its context (row, column, label or heading), ignoring case and spacing. */
|
|
162
|
+
readonly near?: string | undefined;
|
|
163
|
+
/** Only what a point action at this viewport point would reach: the control there, or else what is painted there. */
|
|
164
|
+
readonly at?: Point | undefined;
|
|
165
|
+
/** The viewport (the default), or the whole document. */
|
|
166
|
+
readonly scope?: "viewport" | "document" | undefined;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* An element's state as its markup gives it: `checked` for what can be checked, `expanded`,
|
|
171
|
+
* `selected` and `pressed` where the page says either way, and `level` for headings.
|
|
172
|
+
*/
|
|
173
|
+
export const ElementState = Schema.Struct({
|
|
174
|
+
disabled: Schema.Boolean,
|
|
175
|
+
focused: Schema.Boolean,
|
|
176
|
+
checked: Schema.optional(Schema.Boolean),
|
|
177
|
+
expanded: Schema.optional(Schema.Boolean),
|
|
178
|
+
selected: Schema.optional(Schema.Boolean),
|
|
179
|
+
pressed: Schema.optional(Schema.Boolean),
|
|
180
|
+
level: Schema.optional(Schema.Int),
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
export type ElementState = typeof ElementState.Type;
|
|
184
|
+
|
|
185
|
+
/** An element `find` found: a ref for the actions, what it is, where it is and its state. */
|
|
186
|
+
export class Found extends Schema.Class<Found>("effect-browser/Found")({
|
|
187
|
+
ref: Schema.String,
|
|
188
|
+
subject: Subject,
|
|
189
|
+
/** Its box, rounded. Reading the document, it may be out of view. */
|
|
190
|
+
box: Box,
|
|
191
|
+
inViewport: Schema.Boolean,
|
|
192
|
+
state: ElementState,
|
|
193
|
+
}) {}
|
|
194
|
+
|
|
195
|
+
export interface TextOptions {
|
|
196
|
+
/** `"viewport"` (the default) reads what the viewport shows; a ref reads that element whole. */
|
|
197
|
+
readonly scope?: string | undefined;
|
|
198
|
+
/** Bound on the text's length, cut at a line. Defaults to 12,000 characters. */
|
|
199
|
+
readonly maxChars?: number | undefined;
|
|
200
|
+
/** Show what fields hold; a secret field still reads `••••`. Defaults to false. */
|
|
201
|
+
readonly unmask?: boolean | undefined;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** What a page showed as text: a line per block, with table cells apart by tabs. */
|
|
205
|
+
export class Text extends Schema.Class<Text>("effect-browser/Text")({
|
|
206
|
+
url: Schema.String,
|
|
207
|
+
title: Schema.String,
|
|
208
|
+
text: Schema.String,
|
|
209
|
+
/** True when `text` was cut at `maxChars`. */
|
|
210
|
+
truncated: Schema.Boolean,
|
|
211
|
+
/** Host monotonic milliseconds from the browser's captured Effect Clock. */
|
|
212
|
+
at: Schema.Finite,
|
|
213
|
+
}) {}
|
|
214
|
+
|
|
215
|
+
/** What `waitFor` waits for. */
|
|
216
|
+
export interface WaitCondition {
|
|
217
|
+
/** A CSS selector for what to watch; the document's body without one. */
|
|
218
|
+
readonly selector?: string | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* `"visible"` (the default): something it matches shows; `"hidden"`: nothing it matches shows;
|
|
221
|
+
* `"enabled"`: something it matches shows and is not disabled.
|
|
222
|
+
*/
|
|
223
|
+
readonly state?: "visible" | "hidden" | "enabled" | undefined;
|
|
224
|
+
/** Only what shows this text counts, case and all, with runs of spaces read as one. */
|
|
225
|
+
readonly text?: string | undefined;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export interface ReadyOptions {
|
|
229
|
+
/** How long the screen must also stay still, as for reels coming to rest. */
|
|
230
|
+
readonly quietMillis?: number | undefined;
|
|
231
|
+
readonly timeout?: Duration.Input | undefined;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The window `changes` reads, and whether to show what fields hold. */
|
|
235
|
+
export interface ChangesOptions {
|
|
236
|
+
/**
|
|
237
|
+
* Where the window starts: the changes a previous read returned, to continue exactly where they
|
|
238
|
+
* ended; a frame, at its paint; or host monotonic milliseconds, which mapped to the page's clock
|
|
239
|
+
* may miss or repeat changes near the start if the browser's clock mapping changed since. Defaults
|
|
240
|
+
* to the start of the record.
|
|
241
|
+
*/
|
|
242
|
+
readonly since?: Changes | Frame | number | undefined;
|
|
243
|
+
/**
|
|
244
|
+
* Where it ends: a frame, at its paint, so a delayed frame's window holds nothing it does not
|
|
245
|
+
* show; or host monotonic milliseconds. Defaults to now, and is never later.
|
|
246
|
+
*/
|
|
247
|
+
readonly until?: Frame | number | undefined;
|
|
248
|
+
/** Show what fields hold; a secret field still reads `••••`. Defaults to false. */
|
|
249
|
+
readonly unmask?: boolean | undefined;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** The window `window` reads, and whether to show what fields hold. */
|
|
253
|
+
export interface WindowOptions {
|
|
254
|
+
/**
|
|
255
|
+
* Where the window starts: a previous window, to continue exactly where it ended; a frame, at its
|
|
256
|
+
* paint; host monotonic milliseconds; or a `Duration` back from `until`. A start after `until`
|
|
257
|
+
* leaves the window empty there.
|
|
258
|
+
*/
|
|
259
|
+
readonly since: Window | Frame | Duration.Duration | number;
|
|
260
|
+
/**
|
|
261
|
+
* Where it ends: a frame, at its paint, such as one a delayed consumer airs now; or host
|
|
262
|
+
* monotonic milliseconds. Defaults to now, and is never later.
|
|
263
|
+
*/
|
|
264
|
+
readonly until?: Frame | number | undefined;
|
|
265
|
+
/** Show what fields hold in its changes; a secret field still reads `••••`. Defaults to false. */
|
|
266
|
+
readonly unmask?: boolean | undefined;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* What the library knows of a page now, without asking it, each part with when it learned it, in
|
|
271
|
+
* host monotonic milliseconds: a part's age is `at` less its time. Text read before the current
|
|
272
|
+
* document began is left out, since it tells of a document that has gone.
|
|
273
|
+
*/
|
|
274
|
+
export class State extends Schema.Class<State>("effect-browser/PageState")({
|
|
275
|
+
page: Schema.String,
|
|
276
|
+
/** When this was taken. */
|
|
277
|
+
at: Schema.Finite,
|
|
278
|
+
/** Where the main frame last committed or moved, without userinfo or known secret parameters. */
|
|
279
|
+
url: Schema.String,
|
|
280
|
+
/** The page's document, as `Navigated` counts them. */
|
|
281
|
+
document: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
282
|
+
/** When the main frame committed it; absent for the one the browser began tracking it with. */
|
|
283
|
+
committedAt: Schema.optional(Schema.Finite),
|
|
284
|
+
/** How far that document has loaded, as the page's own session heard; absent until parsed. */
|
|
285
|
+
load: Schema.optional(PageLoaded),
|
|
286
|
+
/** The newest screencast frame, of whichever document it names. */
|
|
287
|
+
frame: Schema.optional(Frame),
|
|
288
|
+
/** The viewport's text as it was last read, with the page's title then. */
|
|
289
|
+
text: Schema.optional(Text),
|
|
290
|
+
}) {}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* What the page's structure establishes about an input, or says it cannot establish:
|
|
294
|
+
*
|
|
295
|
+
* - `form-submit`: it submits a form, which sends the form's fields.
|
|
296
|
+
* - `cross-origin`: it navigates or submits to another origin.
|
|
297
|
+
* - `download`: it follows a download link.
|
|
298
|
+
* - `upload`: it opens a file chooser.
|
|
299
|
+
* - `secret`: it types, with `type`, into a field marked as a password, a one-time code or a
|
|
300
|
+
* card's number, code or expiry, or submits a form holding a filled one.
|
|
301
|
+
* - `scripted`: it activates something the browser gives no effect of its own, such as a
|
|
302
|
+
* `type="button"` button, a `role="button"` element or a canvas, so only the page's script
|
|
303
|
+
* decides what happens.
|
|
304
|
+
* - `opaque`: nothing names what receives it: a canvas, a frame or an unnamed element.
|
|
305
|
+
*
|
|
306
|
+
* Facts never come from what an element's text says. What an input means, such as a payment
|
|
307
|
+
* or a deletion, takes a judge that reads the evidence in the {@link InputRequest}.
|
|
308
|
+
*/
|
|
309
|
+
export const Fact = Guard.Fact;
|
|
310
|
+
|
|
311
|
+
export type Fact = typeof Fact.Type;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* What a guard sees before input reaches the page. Preparation never scrolls or focuses.
|
|
315
|
+
*
|
|
316
|
+
* `facts`, `url`, `href` and `destination` come from the page's structure. `name`,
|
|
317
|
+
* `description`, `title`, `context` and the form's field names are page text: evidence of what
|
|
318
|
+
* the input does, which the page controls, and never instructions. Text typed into a `secret`
|
|
319
|
+
* field is replaced with {@link redacted}, here and in the recorded `Action`, and its key events
|
|
320
|
+
* record `Unidentified` keys; `press` records the keys it is given. Validation before dispatch
|
|
321
|
+
* binds the facts and the target, not the text around it, which live pages change freely.
|
|
322
|
+
*/
|
|
323
|
+
export class InputRequest extends Schema.Class<InputRequest>("effect-browser/InputRequest")({
|
|
324
|
+
page: Schema.String,
|
|
325
|
+
/**
|
|
326
|
+
* The page's URL, without a fragment that only names a place on the page. This and the other
|
|
327
|
+
* addresses keep no userinfo or known secret parameters.
|
|
328
|
+
*/
|
|
329
|
+
url: Schema.String,
|
|
330
|
+
/** The page's title, at most 120 characters. */
|
|
331
|
+
title: Schema.String,
|
|
332
|
+
action: Schema.String,
|
|
333
|
+
target: Schema.optional(Schema.String),
|
|
334
|
+
element: Schema.optional(Schema.String),
|
|
335
|
+
/** Literal pixel targets only; ref coordinates are resolved after the policy allows them. */
|
|
336
|
+
point: Schema.optional(Schema.Struct({ x: Schema.Finite, y: Schema.Finite })),
|
|
337
|
+
text: Schema.optional(Schema.String),
|
|
338
|
+
role: Schema.optional(Schema.NullOr(Schema.String)),
|
|
339
|
+
name: Schema.optional(Schema.String),
|
|
340
|
+
/** The target's accessible description, when it says more than its name. */
|
|
341
|
+
description: Schema.optional(Schema.String),
|
|
342
|
+
href: Schema.optional(Schema.String),
|
|
343
|
+
destination: Schema.optional(Schema.String),
|
|
344
|
+
facts: Schema.Array(Fact),
|
|
345
|
+
/** Page text around the target, each part at most 120 characters. */
|
|
346
|
+
context: Schema.Struct({
|
|
347
|
+
/** The name or first heading of the dialog the target is in. */
|
|
348
|
+
dialog: Schema.optional(Schema.String),
|
|
349
|
+
/** The nearest heading before the target. */
|
|
350
|
+
heading: Schema.optional(Schema.String),
|
|
351
|
+
/** The visible text just before the target in its row, item, group or form, or after it. */
|
|
352
|
+
nearby: Schema.optional(Schema.String),
|
|
353
|
+
}),
|
|
354
|
+
/** The form the target is in, with at most 16 of its fields. */
|
|
355
|
+
form: Schema.optional(
|
|
356
|
+
Schema.Struct({
|
|
357
|
+
method: Schema.String,
|
|
358
|
+
action: Schema.String,
|
|
359
|
+
/** Each field's type, name and autocomplete tokens, and whether it is filled: never its value. */
|
|
360
|
+
fields: Schema.Array(FormFieldSchema),
|
|
361
|
+
}),
|
|
362
|
+
),
|
|
363
|
+
}) {}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* What replaces text typed into a `secret` field, in requests and in the recorded `Action`, and a
|
|
367
|
+
* credential's value in every address the library reports.
|
|
368
|
+
*/
|
|
369
|
+
export const redacted = Url.withheld;
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Run page operations without waiting their turn: on a page busy with other operations, each fails
|
|
373
|
+
* `Busy` at once, and `Browser.newPage` on a browser with `maxPages` open fails `Limit` at once.
|
|
374
|
+
*/
|
|
375
|
+
export const failFast = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
|
|
376
|
+
Effect.provideService(effect, FailFast, true);
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Give every action `effect` performs a caller's id, such as a model's tool call id, which its
|
|
380
|
+
* recorded `Action` carries as `correlation`.
|
|
381
|
+
*/
|
|
382
|
+
export const correlate =
|
|
383
|
+
(id: string) =>
|
|
384
|
+
<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
|
|
385
|
+
Effect.provideService(effect, Correlation, id);
|
|
386
|
+
|
|
387
|
+
/** Succeed to allow, fail to deny, or await an external signal to hold the input. */
|
|
388
|
+
export type InputGuard = (request: InputRequest) => Effect.Effect<void, PolicyDenied>;
|
|
389
|
+
|
|
390
|
+
export interface Page {
|
|
391
|
+
/** The page's CDP target id: the same page has it again after a reconnect to its browser. */
|
|
392
|
+
readonly id: string;
|
|
393
|
+
/** The Playwright page, for anything this API does not cover. Never give it to a model. */
|
|
394
|
+
readonly playwright: PlaywrightPage;
|
|
395
|
+
/** The page's address, without its userinfo or known secret parameters. */
|
|
396
|
+
readonly url: Effect.Effect<string>;
|
|
397
|
+
/**
|
|
398
|
+
* The document's title as the page last set it, empty for an untitled page. The browser answers
|
|
399
|
+
* it, in one call, so a page busy with a script cannot hold it up.
|
|
400
|
+
*/
|
|
401
|
+
readonly title: Effect.Effect<string, BrowserError>;
|
|
402
|
+
|
|
403
|
+
readonly goto: (url: string) => Effect.Effect<void, BrowserError>;
|
|
404
|
+
/** The previous history entry, including one only a frame created; `NotFound` when none. */
|
|
405
|
+
readonly back: Effect.Effect<void, BrowserError>;
|
|
406
|
+
readonly reload: Effect.Effect<void, BrowserError>;
|
|
407
|
+
/** Make this the visible tab. Background tabs paint rarely and send few screencast frames. */
|
|
408
|
+
readonly bringToFront: Effect.Effect<void, BrowserError>;
|
|
409
|
+
/** Close the tab, succeeding once it has closed, or at once when it already had. */
|
|
410
|
+
readonly close: Effect.Effect<void, BrowserError>;
|
|
411
|
+
|
|
412
|
+
readonly snapshot: (options?: SnapshotOptions) => Effect.Effect<Snapshot, BrowserError>;
|
|
413
|
+
/**
|
|
414
|
+
* A picture of the viewport, in CSS pixels: a screencast frame painted since the page's latest
|
|
415
|
+
* input, if one qualifies, or a new one. A caller that has just acted sees what its action did.
|
|
416
|
+
*/
|
|
417
|
+
readonly screenshot: (options?: ScreenshotOptions) => Effect.Effect<Image, BrowserError>;
|
|
418
|
+
/**
|
|
419
|
+
* The viewport with its timing: the newest screencast frame if it qualifies, else a new
|
|
420
|
+
* screenshot timed by the host interval in which it was taken.
|
|
421
|
+
*/
|
|
422
|
+
readonly frame: (options?: FrameOptions) => Effect.Effect<Frame, BrowserError>;
|
|
423
|
+
/** A crop in CSS pixels, unmagnified, with the origin that keeps later input in viewport pixels. */
|
|
424
|
+
readonly zoom: (region: Region) => Effect.Effect<Zoom, BrowserError>;
|
|
425
|
+
/**
|
|
426
|
+
* The viewport's size in CSS pixels, the space of points, crops and page scrolls. Over CDP the
|
|
427
|
+
* page reports it, within the action timeout.
|
|
428
|
+
*/
|
|
429
|
+
readonly viewport: Effect.Effect<
|
|
430
|
+
{ readonly width: number; readonly height: number },
|
|
431
|
+
BrowserError
|
|
432
|
+
>;
|
|
433
|
+
/**
|
|
434
|
+
* The elements that match a query, in tree order, with refs the actions take, in one call to the
|
|
435
|
+
* page. All that match are returned, so a caller tells them apart by their context; none is an
|
|
436
|
+
* empty result, not a failure.
|
|
437
|
+
*/
|
|
438
|
+
readonly find: (query?: FindQuery) => Effect.Effect<ReadonlyArray<Found>, BrowserError>;
|
|
439
|
+
/**
|
|
440
|
+
* The text the viewport shows, or one element whole, in one call to the page. Field values read
|
|
441
|
+
* `••••` unless `unmask`, and a secret field's always do, as does one that was secret when the
|
|
442
|
+
* library saw it.
|
|
443
|
+
*/
|
|
444
|
+
readonly text: (options?: TextOptions) => Effect.Effect<Text, BrowserError>;
|
|
445
|
+
/**
|
|
446
|
+
* What visibly changed over a window, in one call to the page. The first read starts the page's
|
|
447
|
+
* record, so it finds none; from then the page records, and from the start of each later
|
|
448
|
+
* document, until nobody has read it for two minutes. See `Change`.
|
|
449
|
+
*/
|
|
450
|
+
readonly changes: (options?: ChangesOptions) => Effect.Effect<Changes, BrowserError>;
|
|
451
|
+
/**
|
|
452
|
+
* The page's events, changes and frames over a window: the frames and events it keeps, at no
|
|
453
|
+
* call, and its changes, in one call, the first starting its record as `changes` does. A part
|
|
454
|
+
* that cannot be read is missing, with why; the window fails only for bounds that are not finite.
|
|
455
|
+
*/
|
|
456
|
+
readonly window: (options: WindowOptions) => Effect.Effect<Window, BrowserError>;
|
|
457
|
+
/**
|
|
458
|
+
* What the library knows of the page now, at no call and with no wait for its turn: where it is,
|
|
459
|
+
* its document and how far it has loaded, its newest frame, and its text and title as last read.
|
|
460
|
+
*/
|
|
461
|
+
readonly state: Effect.Effect<State>;
|
|
462
|
+
|
|
463
|
+
readonly click: (
|
|
464
|
+
target: Target,
|
|
465
|
+
options?: ClickOptions,
|
|
466
|
+
) => Effect.Effect<ResolvedTarget, BrowserError>;
|
|
467
|
+
readonly hover: (target: Target) => Effect.Effect<void, BrowserError>;
|
|
468
|
+
readonly drag: (from: Target, to: Target) => Effect.Effect<void, BrowserError>;
|
|
469
|
+
/** Type into a text field, or to whatever has focus unless a typed key could activate it. */
|
|
470
|
+
readonly type: (text: string, options?: TypeOptions) => Effect.Effect<void, BrowserError>;
|
|
471
|
+
/** Keys such as `"Enter"`, `"Space"`, `"ArrowLeft"` or `"Control+A"`. */
|
|
472
|
+
readonly press: (keys: string, options?: PressOptions) => Effect.Effect<void, BrowserError>;
|
|
473
|
+
readonly scroll: (options?: ScrollOptions) => Effect.Effect<void, BrowserError>;
|
|
474
|
+
/**
|
|
475
|
+
* Choose options of a `<select>` by value or label; returns the chosen labels. A refusal, such
|
|
476
|
+
* as no matching option, is undispatched.
|
|
477
|
+
*/
|
|
478
|
+
readonly select: (
|
|
479
|
+
ref: string,
|
|
480
|
+
values: ReadonlyArray<string>,
|
|
481
|
+
) => Effect.Effect<string, BrowserError>;
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Wait until a condition holds, in one call that the page answers as it comes, looking every
|
|
485
|
+
* 100 ms, or `Timeout` after `timeout`, 10 seconds by default. A selector that is not CSS is an
|
|
486
|
+
* `InvalidRequest`.
|
|
487
|
+
*/
|
|
488
|
+
readonly waitFor: (
|
|
489
|
+
condition: WaitCondition,
|
|
490
|
+
timeout?: Duration.Input,
|
|
491
|
+
) => Effect.Effect<void, BrowserError>;
|
|
492
|
+
/**
|
|
493
|
+
* Wait until the page is ready to be shown, asking the page every 100 ms: its document is parsed
|
|
494
|
+
* and has painted since, nothing that ends is animating in view, its fonts and the images in
|
|
495
|
+
* view have loaded, and the viewport shows something. With `quietMillis`, the screen must then
|
|
496
|
+
* also stay still that long: nothing in view changed, where the page's changes are recorded, and
|
|
497
|
+
* no frame comes, counted from the first frame of a capture the wait starts itself. A canvas
|
|
498
|
+
* that keeps drawing, such as a live chart, is never still, and a page
|
|
499
|
+
* is never ready without a painted frame, as a hidden tab may be. `Timeout` after `timeout`,
|
|
500
|
+
* 15 seconds by default.
|
|
501
|
+
*/
|
|
502
|
+
readonly ready: (options?: ReadyOptions) => Effect.Effect<void, BrowserError>;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Screencast frames for as long as the stream runs. Concurrent streams share one screencast and
|
|
506
|
+
* its settings; explicit options that differ from a running screencast's fail with InvalidRequest.
|
|
507
|
+
*/
|
|
508
|
+
readonly screencast: (options?: ScreencastOptions) => Stream.Stream<Frame, BrowserError>;
|
|
509
|
+
/**
|
|
510
|
+
* What this page's captures received, delivered and dropped, over its life or the latest
|
|
511
|
+
* `window`, which reaches back at most a minute; a longer one is an `InvalidRequest`.
|
|
512
|
+
*/
|
|
513
|
+
readonly captureStats: (options?: {
|
|
514
|
+
readonly window?: Duration.Input | undefined;
|
|
515
|
+
}) => Effect.Effect<CaptureStats, BrowserError>;
|
|
516
|
+
/** Screencast frames painted within `frameHistory` of the newest, oldest first. */
|
|
517
|
+
readonly recentFrames: Effect.Effect<ReadonlyArray<Frame>>;
|
|
518
|
+
/** This page's events among the browser's latest `eventHistory`, oldest first. */
|
|
519
|
+
readonly recentEvents: Effect.Effect<ReadonlyArray<BrowserEvent>>;
|
|
520
|
+
}
|