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,167 @@
|
|
|
1
|
+
import { t as BrowserError } from "./BrowserError-BlcmLVzn.mjs";
|
|
2
|
+
import { _ as RecordedEvent, i as BrowserEvent_d_exports, r as BrowserEvent, s as DisconnectCause } from "./BrowserEvent-lLqJ3GJS.mjs";
|
|
3
|
+
import { f as Page, p as Page_d_exports, u as InputGuard } from "./Page-CvsOEorc.mjs";
|
|
4
|
+
import { Context, DateTime, Duration, Effect, Option, Schema, Scope, Stream } from "effect";
|
|
5
|
+
import { BrowserContext } from "playwright-core";
|
|
6
|
+
declare namespace Browser_d_exports {
|
|
7
|
+
export { Browser$1 as Browser, CaptureSource, EventOptions, InitScript, Options, RequestDecision, RequestPolicy, Service, SuspendOptions, Suspension, make };
|
|
8
|
+
}
|
|
9
|
+
/** A script that documents run before their own, such as a consent-banner remover. */
|
|
10
|
+
interface InitScript {
|
|
11
|
+
/**
|
|
12
|
+
* The documents that run it, by a pattern their address (`location.href`) matches; every
|
|
13
|
+
* document and frame when left out. Under a `match`, the source runs as a block, so its own
|
|
14
|
+
* top-level `let`, `const` and classes stay its own.
|
|
15
|
+
*/
|
|
16
|
+
readonly match?: RegExp | undefined;
|
|
17
|
+
readonly source: string;
|
|
18
|
+
}
|
|
19
|
+
/** Consumer-owned decision for one request caught by a narrow URL pattern. */
|
|
20
|
+
type RequestDecision = {
|
|
21
|
+
readonly _tag: "Allowed";
|
|
22
|
+
} | {
|
|
23
|
+
readonly _tag: "Refused";
|
|
24
|
+
readonly reason: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly _tag: "Fulfilled";
|
|
27
|
+
readonly status: number;
|
|
28
|
+
readonly contentType: string;
|
|
29
|
+
readonly headers?: Readonly<Record<string, string>> | undefined;
|
|
30
|
+
readonly body: string;
|
|
31
|
+
};
|
|
32
|
+
interface RequestPolicy {
|
|
33
|
+
readonly patterns: ReadonlyArray<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Receives sensitive data for this context only; keep it out of model inputs and logs.
|
|
36
|
+
* Body is exact UTF-8 text, or null when absent. Incomplete/binary body evidence refuses
|
|
37
|
+
* that request. Preexisting shared workers make installation fail InvalidRequest.
|
|
38
|
+
* Enforcement belongs to this connection's scope; it is not a firewall after CDP disconnects.
|
|
39
|
+
*/
|
|
40
|
+
readonly decide: (request: {
|
|
41
|
+
readonly url: string;
|
|
42
|
+
readonly method: string;
|
|
43
|
+
readonly body: string | null;
|
|
44
|
+
}) => Effect.Effect<RequestDecision, BrowserError>;
|
|
45
|
+
readonly timeout?: Duration.Input | undefined;
|
|
46
|
+
}
|
|
47
|
+
interface Options {
|
|
48
|
+
/** Fixed viewport applied before each existing or newly opened page registers. */
|
|
49
|
+
readonly viewport?: {
|
|
50
|
+
readonly width: number;
|
|
51
|
+
readonly height: number;
|
|
52
|
+
} | undefined;
|
|
53
|
+
/** This context's policy, installed before pages register; redirects retain ownership. */
|
|
54
|
+
readonly requests?: RequestPolicy | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Bound on each action; finite and positive. Defaults to 10 seconds. What a presenter's view
|
|
57
|
+
* takes to show an action, such as its glides and typing at a person's pace, does not count
|
|
58
|
+
* against it.
|
|
59
|
+
*/
|
|
60
|
+
readonly actionTimeout?: Duration.Input | undefined;
|
|
61
|
+
/** Bound on each navigation; finite and positive. Defaults to 30 seconds. */
|
|
62
|
+
readonly navigationTimeout?: Duration.Input | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* How long each page keeps screencast frames for `recentFrames`, measured back from the newest;
|
|
65
|
+
* finite and positive. Defaults to 5 seconds, a moment's default window.
|
|
66
|
+
*/
|
|
67
|
+
readonly frameHistory?: Duration.Input | undefined;
|
|
68
|
+
/** Events retained for replay and `recentEvents`. A positive safe integer, defaulting to 4,096. */
|
|
69
|
+
readonly eventHistory?: number | undefined;
|
|
70
|
+
/** Allow, deny or hold each input or navigation before it reaches the page. Defaults to allow. */
|
|
71
|
+
readonly guard?: InputGuard | undefined;
|
|
72
|
+
/** A separate bound for policy holds, outside action timeouts. Defaults to 5 minutes. */
|
|
73
|
+
readonly policyTimeout?: Duration.Input | undefined;
|
|
74
|
+
/** Scripts that new documents run before their own, each where its `match` allows. */
|
|
75
|
+
readonly initScripts?: ReadonlyArray<InitScript> | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* The most pages the browser keeps open, those a site opens included, which are never refused. At
|
|
78
|
+
* it, `newPage` waits for one to close, within the action timeout, then fails `Limit`; under
|
|
79
|
+
* `Page.failFast` it fails at once. A positive safe integer; no limit when left out.
|
|
80
|
+
*/
|
|
81
|
+
readonly maxPages?: number | undefined;
|
|
82
|
+
}
|
|
83
|
+
interface EventOptions {
|
|
84
|
+
/** Resume after this sequence; 0 replays from the beginning if it is still retained. */
|
|
85
|
+
readonly after?: number | undefined;
|
|
86
|
+
}
|
|
87
|
+
interface SuspendOptions {
|
|
88
|
+
/** Finite, nonnegative drain bound; defaults to the browser's navigationTimeout. */
|
|
89
|
+
readonly drain?: Duration.Input | undefined;
|
|
90
|
+
}
|
|
91
|
+
declare const Suspension_base: Schema.Class<Suspension, Schema.Struct<{
|
|
92
|
+
readonly since: Schema.Int;
|
|
93
|
+
readonly at: Schema.Finite;
|
|
94
|
+
}>, {}>;
|
|
95
|
+
/** When admitted input finished; events after `since` describe the handoff interval. */
|
|
96
|
+
declare class Suspension extends Suspension_base {}
|
|
97
|
+
/**
|
|
98
|
+
* A connection to the browser apart from the one that drives its pages, for their screencasts,
|
|
99
|
+
* as a provider that reaches the browser over a network supplies it: a frame and its
|
|
100
|
+
* acknowledgement then never wait behind a large message, such as an upload or a read's answer,
|
|
101
|
+
* on the connection that drives the page. It is read-only. A page's session on it sends the
|
|
102
|
+
* capture's commands alone, and the page's own session keeps its focus emulation, which keeps a
|
|
103
|
+
* tab behind painting.
|
|
104
|
+
*/
|
|
105
|
+
interface CaptureSource {
|
|
106
|
+
/**
|
|
107
|
+
* A session on the page's target, for the scope. `event` gets the session's events in the order
|
|
108
|
+
* the browser sent them, its target's detach among them, until the scope closes; `lost` gets
|
|
109
|
+
* the connection's failure, once, if it fails first. Its calls never throw: a failure rejects.
|
|
110
|
+
*/
|
|
111
|
+
readonly attach: (target: string, listener: {
|
|
112
|
+
readonly event: (method: string, params: unknown) => void;
|
|
113
|
+
readonly lost: (error: BrowserError) => void;
|
|
114
|
+
}) => Effect.Effect<(method: "Page.enable" | "Page.getFrameTree" | "Page.startScreencast" | "Page.screencastFrameAck" | "Page.stopScreencast", params?: Record<string, unknown>) => Promise<unknown>, BrowserError, Scope.Scope>;
|
|
115
|
+
}
|
|
116
|
+
interface Service {
|
|
117
|
+
/** The provider's session id, or a local id. */
|
|
118
|
+
readonly id: string;
|
|
119
|
+
/** Fresh for this connection, even when reattaching the same provider session and page. */
|
|
120
|
+
readonly connection: string;
|
|
121
|
+
readonly provider: string;
|
|
122
|
+
/** When the provider ends the session on its own, as a hosted session's timeout does. */
|
|
123
|
+
readonly expiresAt: DateTime.Utc | undefined;
|
|
124
|
+
/** Host monotonic milliseconds on the clock shared by this browser’s events and frames. */
|
|
125
|
+
readonly now: Effect.Effect<number>;
|
|
126
|
+
/** Drain admitted input and withhold new input for this scope; reads and capture continue. */
|
|
127
|
+
readonly suspend: (options?: SuspendOptions) => Effect.Effect<Suspension, BrowserError, Scope.Scope>;
|
|
128
|
+
/** Open pages in the order this browser began tracking them. */
|
|
129
|
+
readonly pages: Effect.Effect<ReadonlyArray<Page>>;
|
|
130
|
+
/** The open page with this id, its CDP target id, as stored before a reconnect. */
|
|
131
|
+
readonly page: (id: string) => Effect.Effect<Option.Option<Page>>;
|
|
132
|
+
/** The first open page, opening one when there is none. */
|
|
133
|
+
readonly firstPage: Effect.Effect<Page, BrowserError>;
|
|
134
|
+
readonly newPage: (url?: string) => Effect.Effect<Page, BrowserError>;
|
|
135
|
+
/** Whether an applicable cookie exists; its value never leaves the browser owner. */
|
|
136
|
+
readonly hasCookie: (query: {
|
|
137
|
+
readonly name: string;
|
|
138
|
+
readonly url: string;
|
|
139
|
+
}) => Effect.Effect<boolean, BrowserError>;
|
|
140
|
+
/**
|
|
141
|
+
* Completes once the browser is lost to its owner, with why: its connection dropped, its
|
|
142
|
+
* provider ended its session, or its owner's scope released it.
|
|
143
|
+
*/
|
|
144
|
+
readonly disconnected: Effect.Effect<DisconnectCause>;
|
|
145
|
+
/** Live events, or replay after a cursor. A reader that falls behind fails with EventHistoryExpired. */
|
|
146
|
+
readonly events: (options?: EventOptions) => Stream.Stream<RecordedEvent, BrowserError>;
|
|
147
|
+
/** The latest `eventHistory` events, oldest first. */
|
|
148
|
+
readonly recentEvents: Effect.Effect<ReadonlyArray<BrowserEvent>>;
|
|
149
|
+
}
|
|
150
|
+
declare const Browser_base: Context.ServiceClass<Browser$1, "effect-browser/Browser", Service>;
|
|
151
|
+
declare class Browser$1 extends Browser_base {}
|
|
152
|
+
/**
|
|
153
|
+
* Build the service over a context the provider owns. The provider closes the context; this only
|
|
154
|
+
* tracks its pages and events, for as long as the surrounding scope is open. Each page's protocol
|
|
155
|
+
* session, capture and listeners end when that page closes or when the scope does, so a closed
|
|
156
|
+
* tab retains nothing and the context keeps none of them afterwards.
|
|
157
|
+
*/
|
|
158
|
+
declare const make: (context: BrowserContext, info: {
|
|
159
|
+
readonly id?: string | undefined;
|
|
160
|
+
readonly provider: string;
|
|
161
|
+
readonly expiresAt?: DateTime.Utc | undefined;
|
|
162
|
+
/** Where pages' screencasts run, if not on each page's own session. */
|
|
163
|
+
readonly capture?: CaptureSource | undefined;
|
|
164
|
+
}, options?: Options | undefined) => Effect.Effect<Service, BrowserError, Scope.Scope>;
|
|
165
|
+
//#endregion
|
|
166
|
+
export { InitScript as a, RequestPolicy as c, Suspension as d, make as f, EventOptions as i, Service as l, Browser_d_exports as n, Options as o, CaptureSource as r, RequestDecision as s, Browser$1 as t, SuspendOptions as u };
|
|
167
|
+
//# sourceMappingURL=Browser-wZhwZSlG.d.mts.map
|
package/dist/Browser.d.mts
CHANGED
|
@@ -1,129 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
import { c as InputGuard, d as Page_d_exports, u as Page$1 } from "./Page-ku6j5t-v.mjs";
|
|
4
|
-
import { Context, DateTime, Duration, Effect, Option, Schema, Scope, Stream } from "effect";
|
|
5
|
-
import { BrowserContext } from "playwright-core";
|
|
6
|
-
declare namespace Browser_d_exports {
|
|
7
|
-
export { Browser, CaptureSource, EventOptions, InitScript, Options, Service, SuspendOptions, Suspension, make };
|
|
8
|
-
}
|
|
9
|
-
/** A script that documents run before their own, such as a consent-banner remover. */
|
|
10
|
-
export interface InitScript {
|
|
11
|
-
/**
|
|
12
|
-
* The documents that run it, by a pattern their address (`location.href`) matches; every
|
|
13
|
-
* document and frame when left out. Under a `match`, the source runs as a block, so its own
|
|
14
|
-
* top-level `let`, `const` and classes stay its own.
|
|
15
|
-
*/
|
|
16
|
-
readonly match?: RegExp | undefined;
|
|
17
|
-
readonly source: string;
|
|
18
|
-
}
|
|
19
|
-
export interface Options {
|
|
20
|
-
/**
|
|
21
|
-
* Bound on each action; finite and positive. Defaults to 10 seconds. What a presenter's view
|
|
22
|
-
* takes to show an action, such as its glides and typing at a person's pace, does not count
|
|
23
|
-
* against it.
|
|
24
|
-
*/
|
|
25
|
-
readonly actionTimeout?: Duration.Input | undefined;
|
|
26
|
-
/** Bound on each navigation; finite and positive. Defaults to 30 seconds. */
|
|
27
|
-
readonly navigationTimeout?: Duration.Input | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* How long each page keeps screencast frames for `recentFrames`, measured back from the newest;
|
|
30
|
-
* finite and positive. Defaults to 5 seconds, a moment's default window.
|
|
31
|
-
*/
|
|
32
|
-
readonly frameHistory?: Duration.Input | undefined;
|
|
33
|
-
/** Events retained for replay and `recentEvents`. A positive safe integer, defaulting to 4,096. */
|
|
34
|
-
readonly eventHistory?: number | undefined;
|
|
35
|
-
/** Allow, deny or hold each input or navigation before it reaches the page. Defaults to allow. */
|
|
36
|
-
readonly guard?: InputGuard | undefined;
|
|
37
|
-
/** A separate bound for policy holds, outside action timeouts. Defaults to 5 minutes. */
|
|
38
|
-
readonly policyTimeout?: Duration.Input | undefined;
|
|
39
|
-
/** Scripts that new documents run before their own, each where its `match` allows. */
|
|
40
|
-
readonly initScripts?: ReadonlyArray<InitScript> | undefined;
|
|
41
|
-
/**
|
|
42
|
-
* The most pages the browser keeps open, those a site opens included, which are never refused. At
|
|
43
|
-
* it, `newPage` waits for one to close, within the action timeout, then fails `Limit`; under
|
|
44
|
-
* `Page.failFast` it fails at once. A positive safe integer; no limit when left out.
|
|
45
|
-
*/
|
|
46
|
-
readonly maxPages?: number | undefined;
|
|
47
|
-
}
|
|
48
|
-
export interface EventOptions {
|
|
49
|
-
/** Resume after this sequence; 0 replays from the beginning if it is still retained. */
|
|
50
|
-
readonly after?: number | undefined;
|
|
51
|
-
}
|
|
52
|
-
export interface SuspendOptions {
|
|
53
|
-
/** Finite, nonnegative drain bound; defaults to the browser's navigationTimeout. */
|
|
54
|
-
readonly drain?: Duration.Input | undefined;
|
|
55
|
-
}
|
|
56
|
-
declare const Suspension_base: Schema.Class<Suspension, Schema.Struct<{
|
|
57
|
-
readonly since: Schema.Int;
|
|
58
|
-
readonly at: Schema.Finite;
|
|
59
|
-
}>, {}>;
|
|
60
|
-
/** When admitted input finished; events after `since` describe the handoff interval. */
|
|
61
|
-
export declare class Suspension extends Suspension_base {}
|
|
62
|
-
/**
|
|
63
|
-
* A connection to the browser apart from the one that drives its pages, for their screencasts,
|
|
64
|
-
* as a provider that reaches the browser over a network supplies it: a frame and its
|
|
65
|
-
* acknowledgement then never wait behind a large message, such as an upload or a read's answer,
|
|
66
|
-
* on the connection that drives the page. It is read-only. A page's session on it sends the
|
|
67
|
-
* capture's commands alone, and the page's own session keeps its focus emulation, which keeps a
|
|
68
|
-
* tab behind painting.
|
|
69
|
-
*/
|
|
70
|
-
export interface CaptureSource {
|
|
71
|
-
/**
|
|
72
|
-
* A session on the page's target, for the scope. `event` gets the session's events in the order
|
|
73
|
-
* the browser sent them, its target's detach among them, until the scope closes; `lost` gets
|
|
74
|
-
* the connection's failure, once, if it fails first. Its calls never throw: a failure rejects.
|
|
75
|
-
*/
|
|
76
|
-
readonly attach: (target: string, listener: {
|
|
77
|
-
readonly event: (method: string, params: unknown) => void;
|
|
78
|
-
readonly lost: (error: BrowserError) => void;
|
|
79
|
-
}) => Effect.Effect<(method: "Page.enable" | "Page.getFrameTree" | "Page.startScreencast" | "Page.screencastFrameAck" | "Page.stopScreencast", params?: Record<string, unknown>) => Promise<unknown>, BrowserError, Scope.Scope>;
|
|
80
|
-
}
|
|
81
|
-
export interface Service {
|
|
82
|
-
/** The provider's session id, or a local id. */
|
|
83
|
-
readonly id: string;
|
|
84
|
-
/** Fresh for this connection, even when reattaching the same provider session and page. */
|
|
85
|
-
readonly connection: string;
|
|
86
|
-
readonly provider: string;
|
|
87
|
-
/** When the provider ends the session on its own, as a hosted session's timeout does. */
|
|
88
|
-
readonly expiresAt: DateTime.Utc | undefined;
|
|
89
|
-
/** Host monotonic milliseconds on the clock shared by this browser’s events and frames. */
|
|
90
|
-
readonly now: Effect.Effect<number>;
|
|
91
|
-
/** Drain admitted input and withhold new input for this scope; reads and capture continue. */
|
|
92
|
-
readonly suspend: (options?: SuspendOptions) => Effect.Effect<Suspension, BrowserError, Scope.Scope>;
|
|
93
|
-
/** The Playwright context, for anything this API does not cover. Never give it to a model. */
|
|
94
|
-
readonly context: BrowserContext;
|
|
95
|
-
/** Open pages in the order this browser began tracking them. */
|
|
96
|
-
readonly pages: Effect.Effect<ReadonlyArray<Page$1>>;
|
|
97
|
-
/** The open page with this id, its CDP target id, as stored before a reconnect. */
|
|
98
|
-
readonly page: (id: string) => Effect.Effect<Option.Option<Page$1>>;
|
|
99
|
-
/** The first open page, opening one when there is none. */
|
|
100
|
-
readonly firstPage: Effect.Effect<Page$1, BrowserError>;
|
|
101
|
-
readonly newPage: (url?: string) => Effect.Effect<Page$1, BrowserError>;
|
|
102
|
-
/**
|
|
103
|
-
* Completes once the browser is lost to its owner, with why: its connection dropped, its
|
|
104
|
-
* provider ended its session, or its owner's scope released it.
|
|
105
|
-
*/
|
|
106
|
-
readonly disconnected: Effect.Effect<DisconnectCause>;
|
|
107
|
-
/** Live events, or replay after a cursor. A reader that falls behind fails with EventHistoryExpired. */
|
|
108
|
-
readonly events: (options?: EventOptions) => Stream.Stream<RecordedEvent, BrowserError>;
|
|
109
|
-
/** The latest `eventHistory` events, oldest first. */
|
|
110
|
-
readonly recentEvents: Effect.Effect<ReadonlyArray<BrowserEvent>>;
|
|
111
|
-
}
|
|
112
|
-
declare const Browser_base: Context.ServiceClass<Browser, "effect-browser/Browser", Service>;
|
|
113
|
-
export declare class Browser extends Browser_base {}
|
|
114
|
-
/**
|
|
115
|
-
* Build the service over a context the provider owns. The provider closes the context; this only
|
|
116
|
-
* tracks its pages and events, for as long as the surrounding scope is open. Each page's protocol
|
|
117
|
-
* session, capture and listeners end when that page closes or when the scope does, so a closed
|
|
118
|
-
* tab retains nothing and the context keeps none of them afterwards.
|
|
119
|
-
*/
|
|
120
|
-
export declare const make: (context: BrowserContext, info: {
|
|
121
|
-
readonly id: string;
|
|
122
|
-
readonly provider: string;
|
|
123
|
-
readonly expiresAt?: DateTime.Utc | undefined;
|
|
124
|
-
/** Where pages' screencasts run, if not on each page's own session. */
|
|
125
|
-
readonly capture?: CaptureSource | undefined;
|
|
126
|
-
}, options?: Options | undefined) => Effect.Effect<Service, BrowserError, Scope.Scope>;
|
|
127
|
-
//#endregion
|
|
128
|
-
export { Browser_d_exports as t };
|
|
129
|
-
//# sourceMappingURL=Browser.d.mts.map
|
|
1
|
+
import { a as InitScript, c as RequestPolicy, d as Suspension, f as make, i as EventOptions, l as Service, o as Options, r as CaptureSource, s as RequestDecision, t as Browser, u as SuspendOptions } from "./Browser-wZhwZSlG.mjs";
|
|
2
|
+
export { Browser, CaptureSource, EventOptions, InitScript, Options, RequestDecision, RequestPolicy, Service, SuspendOptions, Suspension, make };
|
package/dist/Browser.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as make, r as Suspension, t as Browser } from "./Browser-
|
|
1
|
+
import { i as make, r as Suspension, t as Browser } from "./Browser-Cq2K1FEA.mjs";
|
|
2
2
|
export { Browser, Suspension, make };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
2
|
declare namespace BrowserError_d_exports {
|
|
3
|
-
export { BrowserError, Busy, Closed, Consequence, EventHistoryExpired, Failed, InvalidRequest, Limit, NavigationFailed, NotActionable, NotFound, PolicyDenied, PolicyTimeout, Reason, StaleRef, Suspended, Timeout, consequence };
|
|
3
|
+
export { BrowserError, Busy, Closed, Consequence, EventHistoryExpired, Failed, InvalidRequest, Limit, NavigationFailed, NotActionable, NotFound, PolicyDenied, PolicyTimeout, Reason, StaleRef, Suspended, Threw, Timeout, call, consequence, failWith, reasonOf, refuse, undispatched };
|
|
4
4
|
}
|
|
5
5
|
declare const Timeout_base: Schema.Class<Timeout, Schema.TaggedStruct<"Timeout", {
|
|
6
6
|
readonly millis: Schema.Finite;
|
|
@@ -111,11 +111,16 @@ declare const Failed_base: Schema.Class<Failed, Schema.TaggedStruct<"Failed", {
|
|
|
111
111
|
declare class Failed extends Failed_base {
|
|
112
112
|
get message(): string;
|
|
113
113
|
}
|
|
114
|
-
declare const
|
|
114
|
+
declare const Threw_base: Schema.Class<Threw, Schema.TaggedStruct<"Threw", {}>, import("effect/Cause").YieldableError>;
|
|
115
|
+
/** Caller code threw in the page's main world. Its source and payload stay private. */
|
|
116
|
+
declare class Threw extends Threw_base {
|
|
117
|
+
get message(): string;
|
|
118
|
+
}
|
|
119
|
+
declare const Reason: Schema.Union<readonly [typeof Timeout, typeof Busy, typeof Suspended, typeof Limit, typeof StaleRef, typeof NotFound, typeof NotActionable, typeof NavigationFailed, typeof Closed, typeof InvalidRequest, typeof PolicyDenied, typeof PolicyTimeout, typeof EventHistoryExpired, typeof Failed, typeof Threw]>;
|
|
115
120
|
type Reason = typeof Reason.Type;
|
|
116
121
|
declare const BrowserError_base: Schema.Class<BrowserError, Schema.TaggedStruct<"BrowserError", {
|
|
117
122
|
readonly operation: Schema.String;
|
|
118
|
-
readonly reason: Schema.Union<readonly [typeof Timeout, typeof Busy, typeof Suspended, typeof Limit, typeof StaleRef, typeof NotFound, typeof NotActionable, typeof NavigationFailed, typeof Closed, typeof InvalidRequest, typeof PolicyDenied, typeof PolicyTimeout, typeof EventHistoryExpired, typeof Failed]>;
|
|
123
|
+
readonly reason: Schema.Union<readonly [typeof Timeout, typeof Busy, typeof Suspended, typeof Limit, typeof StaleRef, typeof NotFound, typeof NotActionable, typeof NavigationFailed, typeof Closed, typeof InvalidRequest, typeof PolicyDenied, typeof PolicyTimeout, typeof EventHistoryExpired, typeof Failed, typeof Threw]>;
|
|
119
124
|
readonly dispatched: Schema.Boolean;
|
|
120
125
|
}>, import("effect/Cause").YieldableError>;
|
|
121
126
|
declare class BrowserError extends BrowserError_base {
|
|
@@ -125,7 +130,7 @@ declare class BrowserError extends BrowserError_base {
|
|
|
125
130
|
* What a failure leaves. `lost` is `"page"` when the page is gone and its browser stands, and
|
|
126
131
|
* `"session"` when the browser is gone with its pages. `repeat` says whether the call can be made
|
|
127
132
|
* again, on what still stands: `"safe"`, as nothing reached the browser; `"check"`, as it may have
|
|
128
|
-
* taken effect, so look first, as
|
|
133
|
+
* taken effect, so look first, as a Plan expectation does; `"pointless"`, as it fails again unless
|
|
129
134
|
* something changes, such as
|
|
130
135
|
* a new ref; or `"resume"`, reading events again from a newer cursor.
|
|
131
136
|
*/
|
|
@@ -135,6 +140,16 @@ interface Consequence {
|
|
|
135
140
|
}
|
|
136
141
|
/** What `error` leaves, from its reason and whether it was dispatched alone. */
|
|
137
142
|
declare const consequence: ({ reason, dispatched }: BrowserError) => Consequence;
|
|
143
|
+
/** A failure before any of the operation's input reached the page. */
|
|
144
|
+
declare const undispatched: (operation: string, reason: Reason) => BrowserError;
|
|
145
|
+
/** Fail an operation before dispatch, preserving its typed reason. */
|
|
146
|
+
declare const failWith: (operation: string, reason: Reason) => Effect.Effect<never, BrowserError, never>;
|
|
147
|
+
/** Refuse an invalid request before sending anything. */
|
|
148
|
+
declare const refuse: (operation: string, detail: string) => Effect.Effect<never, BrowserError, never>;
|
|
149
|
+
/** Translate a protocol/provider failure, redacting diagnostic addresses by default. */
|
|
150
|
+
declare const reasonOf: (cause: unknown, timeoutMillis?: number, closed?: Closed["cause"], redact?: (message: string) => string) => Reason;
|
|
151
|
+
/** A native call whose action wrapper owns any later dispatch evidence. */
|
|
152
|
+
declare const call: <A>(operation: string, run: () => Promise<A>, closedBy: () => Closed["cause"], timeoutMillis?: number) => Effect.Effect<A, BrowserError, never>;
|
|
138
153
|
//#endregion
|
|
139
|
-
export { Suspended as _, Consequence as a, InvalidRequest as c, NotActionable as d, NotFound as f, StaleRef as g, Reason as h, Closed as i, Limit as l, PolicyTimeout as m, BrowserError_d_exports as n, EventHistoryExpired as o, PolicyDenied as p, Busy as r, Failed as s, BrowserError as t, NavigationFailed as u,
|
|
140
|
-
//# sourceMappingURL=BrowserError-
|
|
154
|
+
export { reasonOf as C, failWith as S, undispatched as T, Suspended as _, Consequence as a, call as b, InvalidRequest as c, NotActionable as d, NotFound as f, StaleRef as g, Reason as h, Closed as i, Limit as l, PolicyTimeout as m, BrowserError_d_exports as n, EventHistoryExpired as o, PolicyDenied as p, Busy as r, Failed as s, BrowserError as t, NavigationFailed as u, Threw as v, refuse as w, consequence as x, Timeout as y };
|
|
155
|
+
//# sourceMappingURL=BrowserError-BlcmLVzn.d.mts.map
|
package/dist/BrowserError.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as Suspended, a as Consequence, c as InvalidRequest, d as NotActionable, f as NotFound, g as StaleRef, h as Reason, i as Closed, l as Limit, m as PolicyTimeout, o as EventHistoryExpired, p as PolicyDenied, r as Busy, s as Failed, t as BrowserError, u as NavigationFailed, v as
|
|
2
|
-
export { BrowserError, Busy, Closed, Consequence, EventHistoryExpired, Failed, InvalidRequest, Limit, NavigationFailed, NotActionable, NotFound, PolicyDenied, PolicyTimeout, Reason, StaleRef, Suspended, Timeout, consequence };
|
|
1
|
+
import { C as reasonOf, S as failWith, T as undispatched, _ as Suspended, a as Consequence, b as call, c as InvalidRequest, d as NotActionable, f as NotFound, g as StaleRef, h as Reason, i as Closed, l as Limit, m as PolicyTimeout, o as EventHistoryExpired, p as PolicyDenied, r as Busy, s as Failed, t as BrowserError, u as NavigationFailed, v as Threw, w as refuse, x as consequence, y as Timeout } from "./BrowserError-BlcmLVzn.mjs";
|
|
2
|
+
export { BrowserError, Busy, Closed, Consequence, EventHistoryExpired, Failed, InvalidRequest, Limit, NavigationFailed, NotActionable, NotFound, PolicyDenied, PolicyTimeout, Reason, StaleRef, Suspended, Threw, Timeout, call, consequence, failWith, reasonOf, refuse, undispatched };
|
package/dist/BrowserError.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { redactWithin } from "./Url.mjs";
|
|
2
3
|
import { DisconnectCause } from "./BrowserEvent.mjs";
|
|
3
|
-
import { Schema } from "effect";
|
|
4
|
+
import { Effect, Schema } from "effect";
|
|
4
5
|
//#region src/BrowserError.ts
|
|
5
6
|
/**
|
|
6
7
|
* The one error every browser operation fails with.
|
|
@@ -28,8 +29,14 @@ var BrowserError_exports = /* @__PURE__ */ __exportAll({
|
|
|
28
29
|
Reason: () => Reason,
|
|
29
30
|
StaleRef: () => StaleRef,
|
|
30
31
|
Suspended: () => Suspended,
|
|
32
|
+
Threw: () => Threw,
|
|
31
33
|
Timeout: () => Timeout,
|
|
32
|
-
|
|
34
|
+
call: () => call,
|
|
35
|
+
consequence: () => consequence,
|
|
36
|
+
failWith: () => failWith,
|
|
37
|
+
reasonOf: () => reasonOf,
|
|
38
|
+
refuse: () => refuse,
|
|
39
|
+
undispatched: () => undispatched
|
|
33
40
|
});
|
|
34
41
|
/** The operation did not finish in time. */
|
|
35
42
|
var Timeout = class extends Schema.TaggedError()("Timeout", { millis: Schema.Finite }) {
|
|
@@ -148,6 +155,12 @@ var Failed = class extends Schema.TaggedError()("Failed", { detail: Schema.Strin
|
|
|
148
155
|
return this.detail;
|
|
149
156
|
}
|
|
150
157
|
};
|
|
158
|
+
/** Caller code threw in the page's main world. Its source and payload stay private. */
|
|
159
|
+
var Threw = class extends Schema.TaggedError()("Threw", {}) {
|
|
160
|
+
get message() {
|
|
161
|
+
return "the page script threw";
|
|
162
|
+
}
|
|
163
|
+
};
|
|
151
164
|
const Reason = Schema.Union([
|
|
152
165
|
Timeout,
|
|
153
166
|
Busy,
|
|
@@ -162,7 +175,8 @@ const Reason = Schema.Union([
|
|
|
162
175
|
PolicyDenied,
|
|
163
176
|
PolicyTimeout,
|
|
164
177
|
EventHistoryExpired,
|
|
165
|
-
Failed
|
|
178
|
+
Failed,
|
|
179
|
+
Threw
|
|
166
180
|
]);
|
|
167
181
|
var BrowserError = class extends Schema.TaggedError()("BrowserError", {
|
|
168
182
|
operation: Schema.String,
|
|
@@ -181,6 +195,8 @@ const consequence = ({ reason, dispatched }) => {
|
|
|
181
195
|
lost: reason.cause === "page" || reason.cause === "crashed" ? "page" : "session",
|
|
182
196
|
repeat
|
|
183
197
|
};
|
|
198
|
+
case "Limit":
|
|
199
|
+
case "PolicyTimeout":
|
|
184
200
|
case "Busy":
|
|
185
201
|
case "Suspended":
|
|
186
202
|
case "Timeout":
|
|
@@ -191,21 +207,42 @@ const consequence = ({ reason, dispatched }) => {
|
|
|
191
207
|
};
|
|
192
208
|
case "EventHistoryExpired": return {
|
|
193
209
|
lost: "nothing",
|
|
194
|
-
repeat: "resume"
|
|
210
|
+
repeat: dispatched ? "check" : "resume"
|
|
195
211
|
};
|
|
212
|
+
case "Threw":
|
|
196
213
|
case "StaleRef":
|
|
197
214
|
case "NotFound":
|
|
198
215
|
case "NotActionable":
|
|
199
216
|
case "InvalidRequest":
|
|
200
|
-
case "
|
|
201
|
-
case "PolicyDenied":
|
|
202
|
-
case "PolicyTimeout": return {
|
|
217
|
+
case "PolicyDenied": return {
|
|
203
218
|
lost: "nothing",
|
|
204
|
-
repeat: "pointless"
|
|
219
|
+
repeat: dispatched ? "check" : "pointless"
|
|
205
220
|
};
|
|
206
221
|
}
|
|
207
222
|
};
|
|
223
|
+
/** A failure before any of the operation's input reached the page. */
|
|
224
|
+
const undispatched = (operation, reason) => new BrowserError({
|
|
225
|
+
operation,
|
|
226
|
+
reason,
|
|
227
|
+
dispatched: false
|
|
228
|
+
});
|
|
229
|
+
/** Fail an operation before dispatch, preserving its typed reason. */
|
|
230
|
+
const failWith = (operation, reason) => Effect.fail(undispatched(operation, reason));
|
|
231
|
+
/** Refuse an invalid request before sending anything. */
|
|
232
|
+
const refuse = (operation, detail) => failWith(operation, new InvalidRequest({ detail }));
|
|
233
|
+
/** Translate a protocol/provider failure, redacting diagnostic addresses by default. */
|
|
234
|
+
const reasonOf = (cause, timeoutMillis, closed = "connection", redact = redactWithin) => {
|
|
235
|
+
const message = cause instanceof Error ? cause.message : typeof cause === "string" ? cause : "unknown error";
|
|
236
|
+
if (/has been closed|Target closed|Session closed|browser has disconnected|Target page, context or browser/i.test(message)) return new Closed({ cause: closed });
|
|
237
|
+
if (cause instanceof Error && cause.name === "TimeoutError" && timeoutMillis !== void 0) return new Timeout({ millis: timeoutMillis });
|
|
238
|
+
return new Failed({ detail: (redact(message).split("\n")[0] ?? "unknown error").replace(/^[\w.]+: /, "") });
|
|
239
|
+
};
|
|
240
|
+
/** A native call whose action wrapper owns any later dispatch evidence. */
|
|
241
|
+
const call = (operation, run, closedBy, timeoutMillis) => Effect.tryPromise({
|
|
242
|
+
try: run,
|
|
243
|
+
catch: (cause) => undispatched(operation, reasonOf(cause, timeoutMillis, closedBy()))
|
|
244
|
+
});
|
|
208
245
|
//#endregion
|
|
209
|
-
export { BrowserError, Busy, Closed, EventHistoryExpired, Failed, InvalidRequest, Limit, NavigationFailed, NotActionable, NotFound, PolicyDenied, PolicyTimeout, Reason, StaleRef, Suspended, Timeout, consequence, BrowserError_exports as t };
|
|
246
|
+
export { BrowserError, Busy, Closed, EventHistoryExpired, Failed, InvalidRequest, Limit, NavigationFailed, NotActionable, NotFound, PolicyDenied, PolicyTimeout, Reason, StaleRef, Suspended, Threw, Timeout, call, consequence, failWith, reasonOf, refuse, BrowserError_exports as t, undispatched };
|
|
210
247
|
|
|
211
248
|
//# sourceMappingURL=BrowserError.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrowserError.mjs","names":[],"sources":["../src/BrowserError.ts"],"sourcesContent":["/**\n * The one error every browser operation fails with.\n *\n * `reason` says what went wrong and `dispatched` says whether the action's own input (a press,\n * key, wheel, selection or hover, not the pointer travelling toward a press) or a navigation\n * reached the browser first. `consequence` says what that leaves: what was lost, and whether the\n * call can be repeated. `message` is a sentence for operators.\n *\n * @since 0.3.0\n */\nimport { Schema } from \"effect\";\n\nimport { DisconnectCause } from \"./BrowserEvent.ts\";\n\n/** The operation did not finish in time. */\nexport class Timeout extends Schema.TaggedError<Timeout>()(\"Timeout\", {\n millis: Schema.Finite,\n}) {\n override get message() {\n return `timed out after ${this.millis} ms`;\n }\n}\n\n/**\n * The operation waited its turn behind others on its page and was not given one in time, or was\n * asked to fail fast: the page may be well, only busy.\n */\nexport class Busy extends Schema.TaggedError<Busy>()(\"Busy\", {\n waitedMillis: Schema.Finite,\n /** The operations ahead of it: those holding the page and those asked before it. */\n ahead: Schema.Int,\n}) {\n override get message() {\n const others = this.ahead === 1 ? \"operation\" : \"operations\";\n\n return `the page was busy: it waited ${this.waitedMillis} ms behind ${this.ahead} other ${others}`;\n }\n}\n\n/** Input is withheld by a scoped suspension; nothing was dispatched. */\nexport class Suspended extends Schema.TaggedError<Suspended>()(\"Suspended\", {}) {\n override get message() {\n return \"browser input is suspended\";\n }\n}\n\n/** The browser has as many pages open as `maxPages` allows, and none closed in time. */\nexport class Limit extends Schema.TaggedError<Limit>()(\"Limit\", {\n maxPages: Schema.Int,\n}) {\n override get message() {\n return `the browser already has ${this.maxPages} pages open, as many as it allows`;\n }\n}\n\n/** A ref from an earlier snapshot no longer names an element on the page. */\nexport class StaleRef extends Schema.TaggedError<StaleRef>()(\"StaleRef\", {\n ref: Schema.String,\n}) {\n override get message() {\n return `${this.ref} is not on the page any more`;\n }\n}\n\n/** What the operation looked for is not on the page. */\nexport class NotFound extends Schema.TaggedError<NotFound>()(\"NotFound\", {\n target: Schema.String,\n}) {\n override get message() {\n return `${this.target} was not found`;\n }\n}\n\n/** The element exists but cannot take this input: covered, disabled, hidden or the wrong kind. */\nexport class NotActionable extends Schema.TaggedError<NotActionable>()(\"NotActionable\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\n/** A navigation failed, for example on a DNS error or a refused connection. */\nexport class NavigationFailed extends Schema.TaggedError<NavigationFailed>()(\"NavigationFailed\", {\n url: Schema.String,\n detail: Schema.String,\n}) {\n override get message() {\n return `could not load ${this.url}: ${this.detail}`;\n }\n}\n\nconst closedBy = {\n page: \"the page was closed\",\n crashed: \"the page crashed\",\n connection: \"the connection to the browser was lost\",\n session: \"the browser's session ended\",\n released: \"the browser was released\",\n};\n\n/**\n * The page is gone: it was closed (`page`) or crashed, or its browser was lost for one of the\n * browser's `DisconnectCause`s.\n */\nexport class Closed extends Schema.TaggedError<Closed>()(\"Closed\", {\n cause: Schema.Literals([\"page\", \"crashed\", ...DisconnectCause.literals]),\n}) {\n override get message() {\n return closedBy[this.cause];\n }\n}\n\n/** The request itself is invalid, such as a ref that is not a ref or a point off the screen. */\nexport class InvalidRequest extends Schema.TaggedError<InvalidRequest>()(\"InvalidRequest\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\n/** The input policy refused the action before any input was sent. */\nexport class PolicyDenied extends Schema.TaggedError<PolicyDenied>()(\"PolicyDenied\", {\n detail: Schema.String,\n /** What made the policy deny, such as the failure of the judge it asked. */\n cause: Schema.optional(Schema.Defect()),\n}) {\n override get message() {\n return `the input policy denied this action: ${this.detail}`;\n }\n}\n\n/** The input policy did not release its hold within its own bound. */\nexport class PolicyTimeout extends Schema.TaggedError<PolicyTimeout>()(\"PolicyTimeout\", {\n millis: Schema.Finite,\n}) {\n override get message() {\n return `the input policy did not allow this action within ${this.millis} ms`;\n }\n}\n\n/** The requested event cursor fell behind the browser's bounded replay history. */\nexport class EventHistoryExpired extends Schema.TaggedError<EventHistoryExpired>()(\n \"EventHistoryExpired\",\n {\n after: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n oldest: Schema.Int.check(Schema.isGreaterThan(0)),\n latest: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n },\n) {\n override get message() {\n return `event history after ${this.after} expired; retained sequences are ${this.oldest}–${this.latest}`;\n }\n}\n\n/** The browser, the connection or the provider failed in a way the other reasons do not cover. */\nexport class Failed extends Schema.TaggedError<Failed>()(\"Failed\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\nexport const Reason = Schema.Union([\n Timeout,\n Busy,\n Suspended,\n Limit,\n StaleRef,\n NotFound,\n NotActionable,\n NavigationFailed,\n Closed,\n InvalidRequest,\n PolicyDenied,\n PolicyTimeout,\n EventHistoryExpired,\n Failed,\n]);\n\nexport type Reason = typeof Reason.Type;\n\nexport class BrowserError extends Schema.TaggedError<BrowserError>()(\"BrowserError\", {\n operation: Schema.String,\n reason: Reason,\n dispatched: Schema.Boolean,\n}) {\n override get message() {\n return `${this.operation} failed${this.dispatched ? \" after it was sent\" : \"\"}: ${this.reason.message}`;\n }\n}\n\n/**\n * What a failure leaves. `lost` is `\"page\"` when the page is gone and its browser stands, and\n * `\"session\"` when the browser is gone with its pages. `repeat` says whether the call can be made\n * again, on what still stands: `\"safe\"`, as nothing reached the browser; `\"check\"`, as it may have\n * taken effect, so look first, as an `Expect` attempt does; `\"pointless\"`, as it fails again unless\n * something changes, such as\n * a new ref; or `\"resume\"`, reading events again from a newer cursor.\n */\nexport interface Consequence {\n readonly lost: \"nothing\" | \"page\" | \"session\";\n readonly repeat: \"safe\" | \"check\" | \"pointless\" | \"resume\";\n}\n\n/** What `error` leaves, from its reason and whether it was dispatched alone. */\nexport const consequence = ({ reason, dispatched }: BrowserError): Consequence => {\n const repeat = dispatched ? \"check\" : \"safe\";\n\n switch (reason._tag) {\n case \"Closed\":\n return {\n lost: reason.cause === \"page\" || reason.cause === \"crashed\" ? \"page\" : \"session\",\n repeat,\n };\n case \"Busy\":\n case \"Suspended\":\n case \"Timeout\":\n case \"Failed\":\n case \"NavigationFailed\":\n return { lost: \"nothing\", repeat };\n case \"EventHistoryExpired\":\n return { lost: \"nothing\", repeat: \"resume\" };\n case \"StaleRef\":\n case \"NotFound\":\n case \"NotActionable\":\n case \"InvalidRequest\":\n case \"Limit\":\n case \"PolicyDenied\":\n case \"PolicyTimeout\":\n return { lost: \"nothing\", repeat: \"pointless\" };\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,IAAa,UAAb,cAA6B,OAAO,YAAqB,CAAC,CAAC,WAAW,EACpE,QAAQ,OAAO,OACjB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,OAAO,mBAAmB,KAAK,OAAO;CACxC;AACF;;;;;AAMA,IAAa,OAAb,cAA0B,OAAO,YAAkB,CAAC,CAAC,QAAQ;CAC3D,cAAc,OAAO;;CAErB,OAAO,OAAO;AAChB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,MAAM,SAAS,KAAK,UAAU,IAAI,cAAc;EAEhD,OAAO,gCAAgC,KAAK,aAAa,aAAa,KAAK,MAAM,SAAS;CAC5F;AACF;;AAGA,IAAa,YAAb,cAA+B,OAAO,YAAuB,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;CAC9E,IAAa,UAAU;EACrB,OAAO;CACT;AACF;;AAGA,IAAa,QAAb,cAA2B,OAAO,YAAmB,CAAC,CAAC,SAAS,EAC9D,UAAU,OAAO,IACnB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,OAAO,2BAA2B,KAAK,SAAS;CAClD;AACF;;AAGA,IAAa,W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vE;EACF;EACF,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,oBACH,OAAO;GAAE,MAAM;GAAW;EAAO;EACnC,KAAK,uBACH,OAAO;GAAE,MAAM;GAAW,QAAQ;EAAS;EAC7C,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,iBACH,OAAO;GAAE,MAAM;GAAW,QAAQ;EAAY;CAClD;AACF"}
|
|
1
|
+
{"version":3,"file":"BrowserError.mjs","names":["Url.redactWithin"],"sources":["../src/BrowserError.ts"],"sourcesContent":["/**\n * The one error every browser operation fails with.\n *\n * `reason` says what went wrong and `dispatched` says whether the action's own input (a press,\n * key, wheel, selection or hover, not the pointer travelling toward a press) or a navigation\n * reached the browser first. `consequence` says what that leaves: what was lost, and whether the\n * call can be repeated. `message` is a sentence for operators.\n *\n * @since 0.3.0\n */\nimport { Effect, Schema } from \"effect\";\n\nimport { DisconnectCause } from \"./BrowserEvent.ts\";\nimport * as Url from \"./Url.ts\";\n\n/** The operation did not finish in time. */\nexport class Timeout extends Schema.TaggedError<Timeout>()(\"Timeout\", {\n millis: Schema.Finite,\n}) {\n override get message() {\n return `timed out after ${this.millis} ms`;\n }\n}\n\n/**\n * The operation waited its turn behind others on its page and was not given one in time, or was\n * asked to fail fast: the page may be well, only busy.\n */\nexport class Busy extends Schema.TaggedError<Busy>()(\"Busy\", {\n waitedMillis: Schema.Finite,\n /** The operations ahead of it: those holding the page and those asked before it. */\n ahead: Schema.Int,\n}) {\n override get message() {\n const others = this.ahead === 1 ? \"operation\" : \"operations\";\n\n return `the page was busy: it waited ${this.waitedMillis} ms behind ${this.ahead} other ${others}`;\n }\n}\n\n/** Input is withheld by a scoped suspension; nothing was dispatched. */\nexport class Suspended extends Schema.TaggedError<Suspended>()(\"Suspended\", {}) {\n override get message() {\n return \"browser input is suspended\";\n }\n}\n\n/** The browser has as many pages open as `maxPages` allows, and none closed in time. */\nexport class Limit extends Schema.TaggedError<Limit>()(\"Limit\", {\n maxPages: Schema.Int,\n}) {\n override get message() {\n return `the browser already has ${this.maxPages} pages open, as many as it allows`;\n }\n}\n\n/** A ref from an earlier snapshot no longer names an element on the page. */\nexport class StaleRef extends Schema.TaggedError<StaleRef>()(\"StaleRef\", {\n ref: Schema.String,\n}) {\n override get message() {\n return `${this.ref} is not on the page any more`;\n }\n}\n\n/** What the operation looked for is not on the page. */\nexport class NotFound extends Schema.TaggedError<NotFound>()(\"NotFound\", {\n target: Schema.String,\n}) {\n override get message() {\n return `${this.target} was not found`;\n }\n}\n\n/** The element exists but cannot take this input: covered, disabled, hidden or the wrong kind. */\nexport class NotActionable extends Schema.TaggedError<NotActionable>()(\"NotActionable\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\n/** A navigation failed, for example on a DNS error or a refused connection. */\nexport class NavigationFailed extends Schema.TaggedError<NavigationFailed>()(\"NavigationFailed\", {\n url: Schema.String,\n detail: Schema.String,\n}) {\n override get message() {\n return `could not load ${this.url}: ${this.detail}`;\n }\n}\n\nconst closedBy = {\n page: \"the page was closed\",\n crashed: \"the page crashed\",\n connection: \"the connection to the browser was lost\",\n session: \"the browser's session ended\",\n released: \"the browser was released\",\n};\n\n/**\n * The page is gone: it was closed (`page`) or crashed, or its browser was lost for one of the\n * browser's `DisconnectCause`s.\n */\nexport class Closed extends Schema.TaggedError<Closed>()(\"Closed\", {\n cause: Schema.Literals([\"page\", \"crashed\", ...DisconnectCause.literals]),\n}) {\n override get message() {\n return closedBy[this.cause];\n }\n}\n\n/** The request itself is invalid, such as a ref that is not a ref or a point off the screen. */\nexport class InvalidRequest extends Schema.TaggedError<InvalidRequest>()(\"InvalidRequest\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\n/** The input policy refused the action before any input was sent. */\nexport class PolicyDenied extends Schema.TaggedError<PolicyDenied>()(\"PolicyDenied\", {\n detail: Schema.String,\n /** What made the policy deny, such as the failure of the judge it asked. */\n cause: Schema.optional(Schema.Defect()),\n}) {\n override get message() {\n return `the input policy denied this action: ${this.detail}`;\n }\n}\n\n/** The input policy did not release its hold within its own bound. */\nexport class PolicyTimeout extends Schema.TaggedError<PolicyTimeout>()(\"PolicyTimeout\", {\n millis: Schema.Finite,\n}) {\n override get message() {\n return `the input policy did not allow this action within ${this.millis} ms`;\n }\n}\n\n/** The requested event cursor fell behind the browser's bounded replay history. */\nexport class EventHistoryExpired extends Schema.TaggedError<EventHistoryExpired>()(\n \"EventHistoryExpired\",\n {\n after: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n oldest: Schema.Int.check(Schema.isGreaterThan(0)),\n latest: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n },\n) {\n override get message() {\n return `event history after ${this.after} expired; retained sequences are ${this.oldest}–${this.latest}`;\n }\n}\n\n/** The browser, the connection or the provider failed in a way the other reasons do not cover. */\nexport class Failed extends Schema.TaggedError<Failed>()(\"Failed\", {\n detail: Schema.String,\n}) {\n override get message() {\n return this.detail;\n }\n}\n\n/** Caller code threw in the page's main world. Its source and payload stay private. */\nexport class Threw extends Schema.TaggedError<Threw>()(\"Threw\", {}) {\n override get message() {\n return \"the page script threw\";\n }\n}\n\nexport const Reason = Schema.Union([\n Timeout,\n Busy,\n Suspended,\n Limit,\n StaleRef,\n NotFound,\n NotActionable,\n NavigationFailed,\n Closed,\n InvalidRequest,\n PolicyDenied,\n PolicyTimeout,\n EventHistoryExpired,\n Failed,\n Threw,\n]);\n\nexport type Reason = typeof Reason.Type;\n\nexport class BrowserError extends Schema.TaggedError<BrowserError>()(\"BrowserError\", {\n operation: Schema.String,\n reason: Reason,\n dispatched: Schema.Boolean,\n}) {\n override get message() {\n return `${this.operation} failed${this.dispatched ? \" after it was sent\" : \"\"}: ${this.reason.message}`;\n }\n}\n\n/**\n * What a failure leaves. `lost` is `\"page\"` when the page is gone and its browser stands, and\n * `\"session\"` when the browser is gone with its pages. `repeat` says whether the call can be made\n * again, on what still stands: `\"safe\"`, as nothing reached the browser; `\"check\"`, as it may have\n * taken effect, so look first, as a Plan expectation does; `\"pointless\"`, as it fails again unless\n * something changes, such as\n * a new ref; or `\"resume\"`, reading events again from a newer cursor.\n */\nexport interface Consequence {\n readonly lost: \"nothing\" | \"page\" | \"session\";\n readonly repeat: \"safe\" | \"check\" | \"pointless\" | \"resume\";\n}\n\n/** What `error` leaves, from its reason and whether it was dispatched alone. */\nexport const consequence = ({ reason, dispatched }: BrowserError): Consequence => {\n const repeat = dispatched ? \"check\" : \"safe\";\n\n switch (reason._tag) {\n case \"Closed\":\n return {\n lost: reason.cause === \"page\" || reason.cause === \"crashed\" ? \"page\" : \"session\",\n repeat,\n };\n case \"Limit\":\n case \"PolicyTimeout\":\n case \"Busy\":\n case \"Suspended\":\n case \"Timeout\":\n case \"Failed\":\n case \"NavigationFailed\":\n return { lost: \"nothing\", repeat };\n case \"EventHistoryExpired\":\n return { lost: \"nothing\", repeat: dispatched ? \"check\" : \"resume\" };\n case \"Threw\":\n case \"StaleRef\":\n case \"NotFound\":\n case \"NotActionable\":\n case \"InvalidRequest\":\n case \"PolicyDenied\":\n return { lost: \"nothing\", repeat: dispatched ? \"check\" : \"pointless\" };\n }\n};\n\n/** A failure before any of the operation's input reached the page. */\nexport const undispatched = (operation: string, reason: Reason) =>\n new BrowserError({ operation, reason, dispatched: false });\n\n/** Fail an operation before dispatch, preserving its typed reason. */\nexport const failWith = (operation: string, reason: Reason) =>\n Effect.fail(undispatched(operation, reason));\n\n/** Refuse an invalid request before sending anything. */\nexport const refuse = (operation: string, detail: string) =>\n failWith(operation, new InvalidRequest({ detail }));\n\n/** Translate a protocol/provider failure, redacting diagnostic addresses by default. */\nexport const reasonOf = (\n cause: unknown,\n timeoutMillis?: number,\n closed: Closed[\"cause\"] = \"connection\",\n redact: (message: string) => string = Url.redactWithin,\n): Reason => {\n const message =\n cause instanceof Error ? cause.message : typeof cause === \"string\" ? cause : \"unknown error\";\n\n if (\n /has been closed|Target closed|Session closed|browser has disconnected|Target page, context or browser/i.test(\n message,\n )\n )\n return new Closed({ cause: closed });\n if (cause instanceof Error && cause.name === \"TimeoutError\" && timeoutMillis !== undefined)\n return new Timeout({ millis: timeoutMillis });\n const line = redact(message).split(\"\\n\")[0] ?? \"unknown error\";\n\n return new Failed({ detail: line.replace(/^[\\w.]+: /, \"\") });\n};\n\n/** A native call whose action wrapper owns any later dispatch evidence. */\nexport const call = <A>(\n operation: string,\n run: () => Promise<A>,\n closedBy: () => Closed[\"cause\"],\n timeoutMillis?: number,\n) =>\n Effect.tryPromise({\n try: run,\n catch: (cause) => undispatched(operation, reasonOf(cause, timeoutMillis, closedBy())),\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,IAAa,UAAb,cAA6B,OAAO,YAAqB,CAAC,CAAC,WAAW,EACpE,QAAQ,OAAO,OACjB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,OAAO,mBAAmB,KAAK,OAAO;CACxC;AACF;;;;;AAMA,IAAa,OAAb,cAA0B,OAAO,YAAkB,CAAC,CAAC,QAAQ;CAC3D,cAAc,OAAO;;CAErB,OAAO,OAAO;AAChB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,MAAM,SAAS,KAAK,UAAU,IAAI,cAAc;EAEhD,OAAO,gCAAgC,KAAK,aAAa,aAAa,KAAK,MAAM,SAAS;CAC5F;AACF;;AAGA,IAAa,YAAb,cAA+B,OAAO,YAAuB,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;CAC9E,IAAa,UAAU;EACrB,OAAO;CACT;AACF;;AAGA,IAAa,QAAb,cAA2B,OAAO,YAAmB,CAAC,CAAC,SAAS,EAC9D,UAAU,OAAO,IACnB,CAAC,CAAC,CAAC;CACD,IAAa,UAAU;EACrB,OAAO,2BAA2B,KAAK,SAAS;CAClD;AACF;;AAGA,IAAa,WAAb,cAA8B,OAAO,YAAsB,CAAC,CAAC,Y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