effect-browser 0.2.0-beta.9 → 0.3.0-beta.5
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 +705 -1184
- package/dist/Browser-CM65Uo7f.mjs +437 -0
- package/dist/Browser-CM65Uo7f.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-CNNOU1Tx.d.mts +112 -0
- package/dist/Plan-Dtrb-8im.mjs +311 -0
- package/dist/Plan-Dtrb-8im.mjs.map +1 -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-Banfm_zc.mjs +5097 -0
- package/dist/page-Banfm_zc.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 +350 -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 +607 -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
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { DialogShown, Disconnected, PageClosed, PageOpened, PageUntracked, RecordedEvent, SessionEnding } from "./BrowserEvent.mjs";
|
|
3
|
+
import { BrowserError, Closed, EventHistoryExpired, Failed, InvalidRequest, Limit } from "./BrowserError.mjs";
|
|
4
|
+
import { c as FailFast, i as redact } from "./url-CcL0K7S0.mjs";
|
|
5
|
+
import { i as failWith, s as undispatched, t as call } from "./context-DAYjATgC.mjs";
|
|
6
|
+
import { n as make$3, o as mapping } from "./page-Banfm_zc.mjs";
|
|
7
|
+
import { Cause, Clock, Context, DateTime, Deferred, Duration, Effect, Exit, Option, Queue, Scope, Semaphore, Stream } from "effect";
|
|
8
|
+
//#region src/internal/page/openings.ts
|
|
9
|
+
/** A page's input waits for the actual tabs it opened to finish the browser's registration. */
|
|
10
|
+
const make$2 = Effect.fnUntraced(function* (playwright, cdp, registrations, closedBy) {
|
|
11
|
+
const failed = (reason) => Exit.fail(new BrowserError({
|
|
12
|
+
operation: "newPage",
|
|
13
|
+
reason,
|
|
14
|
+
dispatched: false
|
|
15
|
+
}));
|
|
16
|
+
let active;
|
|
17
|
+
const gone = Deferred.makeUnsafe();
|
|
18
|
+
const windowOpened = () => {
|
|
19
|
+
if (active !== void 0) active.windows += 1;
|
|
20
|
+
};
|
|
21
|
+
const popup = (opened) => {
|
|
22
|
+
if (active === void 0) return;
|
|
23
|
+
const registered = registrations.get(opened);
|
|
24
|
+
active.registrations.push(registered === void 0 ? failed(new Failed({ detail: "the popup has no registration" })) : Deferred.await(registered));
|
|
25
|
+
Deferred.doneUnsafe(active.changed, Exit.void);
|
|
26
|
+
active.changed = Deferred.makeUnsafe();
|
|
27
|
+
};
|
|
28
|
+
const clear = Effect.sync(() => {
|
|
29
|
+
active = void 0;
|
|
30
|
+
});
|
|
31
|
+
yield* Effect.acquireRelease(Effect.sync(() => {
|
|
32
|
+
cdp.on("Page.windowOpen", windowOpened);
|
|
33
|
+
playwright.on("popup", popup);
|
|
34
|
+
}), () => Effect.sync(() => {
|
|
35
|
+
active = void 0;
|
|
36
|
+
cdp.off("Page.windowOpen", windowOpened);
|
|
37
|
+
playwright.off("popup", popup);
|
|
38
|
+
Deferred.doneUnsafe(gone, failed(new Closed({ cause: closedBy() })));
|
|
39
|
+
}));
|
|
40
|
+
return {
|
|
41
|
+
mark: () => {
|
|
42
|
+
const mark = {
|
|
43
|
+
windows: 0,
|
|
44
|
+
registrations: [],
|
|
45
|
+
changed: Deferred.makeUnsafe()
|
|
46
|
+
};
|
|
47
|
+
active = mark;
|
|
48
|
+
return mark;
|
|
49
|
+
},
|
|
50
|
+
clear,
|
|
51
|
+
settle: (mark) => Effect.gen(function* () {
|
|
52
|
+
while (mark.registrations.length < mark.windows) yield* Deferred.await(mark.changed);
|
|
53
|
+
yield* Effect.forEach(mark.registrations, (registration) => registration);
|
|
54
|
+
}).pipe(Effect.raceFirst(Deferred.await(gone)), Effect.ensuring(clear))
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/internal/timeline/events.ts
|
|
59
|
+
/**
|
|
60
|
+
* The browser's bounded event history and replay cursors. Readers share the same records and
|
|
61
|
+
* wakeup generation, so a delayed reader cannot block input or retain an unbounded private queue.
|
|
62
|
+
*/
|
|
63
|
+
/** The owning Browser validates capacity and closes this timeline with its scope. */
|
|
64
|
+
const make$1 = (capacity) => {
|
|
65
|
+
let records = [];
|
|
66
|
+
let sequence = 0;
|
|
67
|
+
let closed = false;
|
|
68
|
+
let changed = Deferred.makeUnsafe();
|
|
69
|
+
const wake = () => {
|
|
70
|
+
const previous = changed;
|
|
71
|
+
changed = Deferred.makeUnsafe();
|
|
72
|
+
Deferred.doneUnsafe(previous, Effect.void);
|
|
73
|
+
};
|
|
74
|
+
const publish = (event) => {
|
|
75
|
+
if (closed) return sequence;
|
|
76
|
+
sequence += 1;
|
|
77
|
+
const recorded = new RecordedEvent({
|
|
78
|
+
sequence,
|
|
79
|
+
event
|
|
80
|
+
});
|
|
81
|
+
records = records.length < capacity ? [...records, recorded] : [...records.slice(1), recorded];
|
|
82
|
+
wake();
|
|
83
|
+
return sequence;
|
|
84
|
+
};
|
|
85
|
+
const stream = (after) => Stream.unwrap(Effect.sync(() => {
|
|
86
|
+
let cursor = after ?? sequence;
|
|
87
|
+
if (!Number.isSafeInteger(cursor) || cursor < 0 || cursor > sequence) return Stream.fail(undispatched("events", new InvalidRequest({ detail: "the event cursor must be a nonnegative integer no greater than the latest sequence" })));
|
|
88
|
+
return Stream.fromEffectRepeat(Effect.gen(function* () {
|
|
89
|
+
while (true) {
|
|
90
|
+
const oldest = records[0]?.sequence ?? sequence + 1;
|
|
91
|
+
if (cursor < oldest - 1) return yield* undispatched("events", new EventHistoryExpired({
|
|
92
|
+
after: cursor,
|
|
93
|
+
oldest,
|
|
94
|
+
latest: sequence
|
|
95
|
+
}));
|
|
96
|
+
const next = records[cursor - oldest + 1];
|
|
97
|
+
if (next !== void 0) {
|
|
98
|
+
cursor = next.sequence;
|
|
99
|
+
return next;
|
|
100
|
+
}
|
|
101
|
+
if (closed) return yield* Cause.done();
|
|
102
|
+
const waiting = changed;
|
|
103
|
+
yield* Deferred.await(waiting);
|
|
104
|
+
}
|
|
105
|
+
}));
|
|
106
|
+
}));
|
|
107
|
+
return {
|
|
108
|
+
publish,
|
|
109
|
+
recent: Effect.sync(() => records),
|
|
110
|
+
stream,
|
|
111
|
+
close: Effect.sync(() => {
|
|
112
|
+
if (closed) return;
|
|
113
|
+
closed = true;
|
|
114
|
+
wake();
|
|
115
|
+
})
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/Browser.ts
|
|
120
|
+
/**
|
|
121
|
+
* A live browser: its pages and what happens in it.
|
|
122
|
+
*
|
|
123
|
+
* `Browser` is a service with one implementation, built by a provider over a Playwright browser
|
|
124
|
+
* context: `Chromium` launches one locally, `Cdp` connects to any DevTools endpoint and
|
|
125
|
+
* `effect-browserbase` allocates a hosted one. Code written against `Browser` runs on all three.
|
|
126
|
+
* A page is named by its CDP target id, so a new connection to the same browser finds it again.
|
|
127
|
+
*
|
|
128
|
+
* @since 0.3.0
|
|
129
|
+
*/
|
|
130
|
+
var Browser_exports = /* @__PURE__ */ __exportAll({
|
|
131
|
+
Browser: () => Browser,
|
|
132
|
+
make: () => make
|
|
133
|
+
});
|
|
134
|
+
var Browser = class extends Context.Service()("effect-browser/Browser") {};
|
|
135
|
+
/** The settings every page shares, and how many events the browser keeps, from its options. */
|
|
136
|
+
const settingsOf = Effect.fnUntraced(function* (options) {
|
|
137
|
+
const invalid = (detail) => undispatched("make", new InvalidRequest({ detail }));
|
|
138
|
+
const bound = (name, input, fallback) => {
|
|
139
|
+
const decoded = Duration.fromInput(input ?? fallback);
|
|
140
|
+
return Option.isSome(decoded) && Number.isFinite(Duration.toMillis(decoded.value)) && Duration.isPositive(decoded.value) ? Effect.succeed(decoded.value) : Effect.fail(invalid(`${name} must be finite and greater than zero`));
|
|
141
|
+
};
|
|
142
|
+
const settings = {
|
|
143
|
+
actionTimeout: yield* bound("actionTimeout", options.actionTimeout, Duration.seconds(10)),
|
|
144
|
+
navigationTimeout: yield* bound("navigationTimeout", options.navigationTimeout, Duration.seconds(30)),
|
|
145
|
+
frameHistory: yield* bound("frameHistory", options.frameHistory, Duration.seconds(5)),
|
|
146
|
+
guard: options.guard,
|
|
147
|
+
policyTimeout: yield* bound("policyTimeout", options.policyTimeout, Duration.minutes(5))
|
|
148
|
+
};
|
|
149
|
+
const eventHistory = options.eventHistory ?? 4096;
|
|
150
|
+
const { maxPages } = options;
|
|
151
|
+
if (!Number.isSafeInteger(eventHistory) || eventHistory < 1) return yield* invalid("eventHistory must be a positive safe integer");
|
|
152
|
+
if (maxPages !== void 0 && (!Number.isSafeInteger(maxPages) || maxPages < 1)) return yield* invalid("maxPages must be a positive safe integer");
|
|
153
|
+
return {
|
|
154
|
+
settings,
|
|
155
|
+
eventHistory,
|
|
156
|
+
maxPages
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
/**
|
|
160
|
+
* A provider that ends a session at `expiresAt` by its own clock can cut the connection a little
|
|
161
|
+
* before this host's clock gets there.
|
|
162
|
+
*/
|
|
163
|
+
const endMargin = Duration.seconds(5);
|
|
164
|
+
/**
|
|
165
|
+
* The browser's loss, once: its context closing from the other side, at or after the session's
|
|
166
|
+
* end or before it, or `lose`, as the owner's scope releases it. Playwright leaves the calls in
|
|
167
|
+
* flight on the library's own sessions unanswered when the connection drops, so `untilLost` fails
|
|
168
|
+
* each with the browser, as a closed page's call fails.
|
|
169
|
+
*/
|
|
170
|
+
const watchLoss = Effect.fnUntraced(function* (context, expiresAt, clock, disconnected) {
|
|
171
|
+
let lostBy;
|
|
172
|
+
const lost = yield* Deferred.make();
|
|
173
|
+
const inFlight = /* @__PURE__ */ new Set();
|
|
174
|
+
const gone = () => /* @__PURE__ */ new Error("Target page, context or browser has been closed");
|
|
175
|
+
const lose = (cause) => {
|
|
176
|
+
if (lostBy !== void 0) return;
|
|
177
|
+
lostBy = cause;
|
|
178
|
+
for (const reject of inFlight) reject(gone());
|
|
179
|
+
disconnected(cause);
|
|
180
|
+
Deferred.doneUnsafe(lost, Exit.succeed(cause));
|
|
181
|
+
};
|
|
182
|
+
const untilLost = (reply) => {
|
|
183
|
+
if (lostBy !== void 0) {
|
|
184
|
+
reply.catch(() => void 0);
|
|
185
|
+
return Promise.reject(gone());
|
|
186
|
+
}
|
|
187
|
+
return new Promise((resolve, reject) => {
|
|
188
|
+
inFlight.add(reject);
|
|
189
|
+
reply.then(resolve, reject).finally(() => inFlight.delete(reject));
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
const ended = () => expiresAt !== void 0 && clock.currentTimeMillisUnsafe() >= DateTime.toEpochMillis(expiresAt) - Duration.toMillis(endMargin);
|
|
193
|
+
const onClose = () => lose(ended() ? "session" : "connection");
|
|
194
|
+
context.on("close", onClose);
|
|
195
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => context.off("close", onClose)));
|
|
196
|
+
if (context.browser()?.isConnected() === false) onClose();
|
|
197
|
+
const native = (operation, run) => call(operation, run, () => lostBy ?? "page");
|
|
198
|
+
return {
|
|
199
|
+
lostBy: () => lostBy,
|
|
200
|
+
lost: Deferred.await(lost),
|
|
201
|
+
lose,
|
|
202
|
+
untilLost,
|
|
203
|
+
native
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
/**
|
|
207
|
+
* What a page's own Playwright events publish, its close and crash aside, while its scope is
|
|
208
|
+
* open. Dialogs are answered: alerts accepted, others dismissed. The page's own session tells its
|
|
209
|
+
* documents' commits and loads.
|
|
210
|
+
*/
|
|
211
|
+
const listen = (playwright, page, publish, now, on) => {
|
|
212
|
+
const dialog = (shown) => {
|
|
213
|
+
const kind = shown.type();
|
|
214
|
+
const answer = kind === "alert" || kind === "beforeunload" ? "accepted" : "dismissed";
|
|
215
|
+
const message = shown.message().slice(0, 500);
|
|
216
|
+
publish(new DialogShown({
|
|
217
|
+
at: now(),
|
|
218
|
+
page,
|
|
219
|
+
kind,
|
|
220
|
+
message,
|
|
221
|
+
answer
|
|
222
|
+
}));
|
|
223
|
+
(answer === "accepted" ? shown.accept() : shown.dismiss()).catch(() => void 0);
|
|
224
|
+
};
|
|
225
|
+
return Effect.acquireRelease(Effect.sync(() => {
|
|
226
|
+
playwright.on("close", on.close);
|
|
227
|
+
playwright.on("crash", on.crash);
|
|
228
|
+
playwright.on("dialog", dialog);
|
|
229
|
+
}), () => Effect.sync(() => {
|
|
230
|
+
playwright.off("close", on.close);
|
|
231
|
+
playwright.off("crash", on.crash);
|
|
232
|
+
playwright.off("dialog", dialog);
|
|
233
|
+
}));
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Register each page the site opens, such as a popup, as Playwright reports it, for as long as the
|
|
237
|
+
* scope is open. One that could not be tracked is published, unless it closed as it opened.
|
|
238
|
+
*/
|
|
239
|
+
const followOpened = Effect.fnUntraced(function* (context, register, publish, now, registrations) {
|
|
240
|
+
const opened = yield* Queue.unbounded();
|
|
241
|
+
const onPage = (playwright) => {
|
|
242
|
+
registrations.set(playwright, Deferred.makeUnsafe());
|
|
243
|
+
Queue.offerUnsafe(opened, playwright);
|
|
244
|
+
};
|
|
245
|
+
const untracked = (playwright) => (error) => Effect.sync(() => {
|
|
246
|
+
const url = redact(playwright.url());
|
|
247
|
+
if (!playwright.isClosed()) publish(new PageUntracked({
|
|
248
|
+
at: now(),
|
|
249
|
+
url,
|
|
250
|
+
detail: error.message
|
|
251
|
+
}));
|
|
252
|
+
});
|
|
253
|
+
context.on("page", onPage);
|
|
254
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => context.off("page", onPage)));
|
|
255
|
+
yield* Queue.take(opened).pipe(Effect.flatMap((playwright) => register(playwright).pipe(Effect.asVoid, Effect.onExit((exit) => Effect.sync(() => {
|
|
256
|
+
const done = registrations.get(playwright);
|
|
257
|
+
if (done !== void 0) Deferred.doneUnsafe(done, exit);
|
|
258
|
+
})), Effect.catch(untracked(playwright)))), Effect.forever, Effect.forkScoped);
|
|
259
|
+
});
|
|
260
|
+
/** Release something native, on the owner's clock, giving up after a second: cleanup only. */
|
|
261
|
+
const releaseNative = (clock) => (run) => Effect.tryPromise(run).pipe(Effect.interruptible, Effect.timeoutOrElse({
|
|
262
|
+
duration: Duration.seconds(1),
|
|
263
|
+
orElse: () => Effect.void
|
|
264
|
+
}), Effect.provideService(Clock.Clock, clock), Effect.ignore);
|
|
265
|
+
/** A page's own events among the browser's retained ones, and the openings of tabs it opened. */
|
|
266
|
+
const eventsOf = (recent, page) => Effect.map(recent, (records) => records.flatMap(({ event }) => "page" in event && event.page === page || event._tag === "PageOpened" && event.opener === page ? [event] : []));
|
|
267
|
+
/** A script as its documents run it: everywhere, or as a block where its `match` allows. */
|
|
268
|
+
const scoped = ({ match, source }) => match === void 0 ? source : `if (${String(match)}.test(location.href)) {\n${source}\n}`;
|
|
269
|
+
/**
|
|
270
|
+
* At most `maxPages` open pages, those a site opened included, which are never refused: an open
|
|
271
|
+
* past it waits for one to close, within `wait` on the owner's clock, then fails `Limit`, or fails
|
|
272
|
+
* at once under `FailFast`. An open counts until its page is tracked.
|
|
273
|
+
*/
|
|
274
|
+
const pageBudget = (maxPages, tracked, wait, clock) => {
|
|
275
|
+
let opening = 0;
|
|
276
|
+
let roomMade = Deferred.makeUnsafe();
|
|
277
|
+
const makeRoom = () => {
|
|
278
|
+
Deferred.doneUnsafe(roomMade, Exit.void);
|
|
279
|
+
roomMade = Deferred.makeUnsafe();
|
|
280
|
+
};
|
|
281
|
+
const full = (limit) => tracked() + opening >= limit;
|
|
282
|
+
const room = (limit) => Effect.gen(function* () {
|
|
283
|
+
const refused = undispatched("newPage", new Limit({ maxPages: limit }));
|
|
284
|
+
if ((yield* FailFast) && full(limit)) return yield* refused;
|
|
285
|
+
yield* Effect.gen(function* () {
|
|
286
|
+
while (full(limit)) yield* Deferred.await(roomMade);
|
|
287
|
+
opening += 1;
|
|
288
|
+
}).pipe(Effect.timeoutOrElse({
|
|
289
|
+
duration: wait,
|
|
290
|
+
orElse: () => Effect.fail(refused)
|
|
291
|
+
}), Effect.provideService(Clock.Clock, clock));
|
|
292
|
+
});
|
|
293
|
+
const open = (opened) => maxPages === void 0 ? opened : Effect.uninterruptibleMask((restore) => restore(room(maxPages)).pipe(Effect.andThen(restore(opened).pipe(Effect.ensuring(Effect.sync(() => {
|
|
294
|
+
opening -= 1;
|
|
295
|
+
makeRoom();
|
|
296
|
+
}))))));
|
|
297
|
+
return {
|
|
298
|
+
makeRoom,
|
|
299
|
+
open
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
/** A call sent now and awaited later, by whatever needs its answer. */
|
|
303
|
+
const sentNow = (sent) => {
|
|
304
|
+
sent.catch(() => void 0);
|
|
305
|
+
return sent;
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Build the service over a context the provider owns. The provider closes the context; this only
|
|
309
|
+
* tracks its pages and events, for as long as the surrounding scope is open. Each page's protocol
|
|
310
|
+
* session, capture and listeners end when that page closes or when the scope does, so a closed
|
|
311
|
+
* tab retains nothing and the context keeps none of them afterwards.
|
|
312
|
+
*/
|
|
313
|
+
const make = Effect.fn("Browser.make")(function* (context, info, options = {}) {
|
|
314
|
+
const clock = yield* Clock.Clock;
|
|
315
|
+
const now = () => Number(clock.monotonicTimeNanosUnsafe()) / 1e6;
|
|
316
|
+
const { settings, eventHistory, maxPages } = yield* settingsOf(options);
|
|
317
|
+
const mapping$1 = mapping(now);
|
|
318
|
+
const timeline = make$1(eventHistory);
|
|
319
|
+
yield* Effect.addFinalizer(() => timeline.close);
|
|
320
|
+
const publish = timeline.publish;
|
|
321
|
+
if (info.expiresAt !== void 0) publish(new SessionEnding({
|
|
322
|
+
at: now(),
|
|
323
|
+
expiresAt: info.expiresAt
|
|
324
|
+
}));
|
|
325
|
+
const { lostBy, lost, lose, untilLost, native } = yield* watchLoss(context, info.expiresAt, clock, (cause) => publish(new Disconnected({
|
|
326
|
+
at: now(),
|
|
327
|
+
cause
|
|
328
|
+
})));
|
|
329
|
+
const registry = /* @__PURE__ */ new Map();
|
|
330
|
+
const registrations = /* @__PURE__ */ new WeakMap();
|
|
331
|
+
const registering = yield* Semaphore.make(1);
|
|
332
|
+
const pagesScope = yield* Scope.fork(yield* Scope.Scope);
|
|
333
|
+
const release = releaseNative(clock);
|
|
334
|
+
const budget = pageBudget(maxPages, () => registry.size, settings.actionTimeout, clock);
|
|
335
|
+
const closing = yield* Queue.unbounded();
|
|
336
|
+
yield* Queue.take(closing).pipe(Effect.tap(({ page, cause }) => Effect.sync(() => {
|
|
337
|
+
if (lostBy() === void 0) publish(new PageClosed({
|
|
338
|
+
at: now(),
|
|
339
|
+
page,
|
|
340
|
+
cause
|
|
341
|
+
}));
|
|
342
|
+
})), Effect.flatMap(({ scope }) => Scope.close(scope, Exit.void)), Effect.forever, Effect.forkScoped);
|
|
343
|
+
const register = (playwright) => registering.withPermits(1)(Effect.gen(function* () {
|
|
344
|
+
const known = registry.get(playwright);
|
|
345
|
+
if (known !== void 0) return known;
|
|
346
|
+
if (playwright.isClosed()) return yield* failWith("newPage", new Failed({ detail: "the page closed as it opened" }));
|
|
347
|
+
const scope = yield* Scope.fork(pagesScope);
|
|
348
|
+
return yield* Effect.gen(function* () {
|
|
349
|
+
let crashed = false;
|
|
350
|
+
const closedBy = () => lostBy() ?? (crashed ? "crashed" : "page");
|
|
351
|
+
const cdp = yield* native("newPage", () => context.newCDPSession(playwright));
|
|
352
|
+
yield* Effect.addFinalizer(() => release(() => cdp.detach()));
|
|
353
|
+
const send = (method, params) => untilLost(cdp.send(method, params));
|
|
354
|
+
const focusing = sentNow(send("Emulation.setFocusEmulationEnabled", { enabled: true }));
|
|
355
|
+
const paging = sentNow(send("Page.enable"));
|
|
356
|
+
const { targetInfo } = yield* native("newPage", () => send("Target.getTargetInfo"));
|
|
357
|
+
const id = targetInfo.targetId;
|
|
358
|
+
const page = yield* make$3({
|
|
359
|
+
id,
|
|
360
|
+
session: info.id,
|
|
361
|
+
url: targetInfo.url,
|
|
362
|
+
playwright,
|
|
363
|
+
cdp,
|
|
364
|
+
untilLost,
|
|
365
|
+
settings,
|
|
366
|
+
clock,
|
|
367
|
+
mapping: mapping$1,
|
|
368
|
+
publish,
|
|
369
|
+
recentEvents: eventsOf(timeline.recent, id),
|
|
370
|
+
openings: yield* make$2(playwright, cdp, registrations, closedBy),
|
|
371
|
+
focused: call("focus", () => focusing, closedBy).pipe(Effect.asVoid),
|
|
372
|
+
paging: (operation) => call(operation, () => paging, closedBy).pipe(Effect.asVoid),
|
|
373
|
+
closedBy,
|
|
374
|
+
capture: info.capture
|
|
375
|
+
});
|
|
376
|
+
const close = () => {
|
|
377
|
+
if (registry.get(playwright) !== page) return;
|
|
378
|
+
registry.delete(playwright);
|
|
379
|
+
budget.makeRoom();
|
|
380
|
+
Queue.offerUnsafe(closing, {
|
|
381
|
+
scope,
|
|
382
|
+
page: id,
|
|
383
|
+
cause: crashed ? "crashed" : "page"
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
const crash = () => {
|
|
387
|
+
crashed = true;
|
|
388
|
+
playwright.close().catch(() => void 0);
|
|
389
|
+
};
|
|
390
|
+
registry.set(playwright, page);
|
|
391
|
+
publish(new PageOpened({
|
|
392
|
+
at: now(),
|
|
393
|
+
page: id,
|
|
394
|
+
url: redact(targetInfo.url),
|
|
395
|
+
opener: targetInfo.openerId
|
|
396
|
+
}));
|
|
397
|
+
yield* listen(playwright, id, publish, now, {
|
|
398
|
+
close,
|
|
399
|
+
crash
|
|
400
|
+
});
|
|
401
|
+
if (playwright.isClosed()) close();
|
|
402
|
+
return page;
|
|
403
|
+
}).pipe(Scope.provide(scope), Effect.onError(() => Scope.close(scope, Exit.void)));
|
|
404
|
+
}));
|
|
405
|
+
for (const script of options.initScripts ?? []) yield* native("initScripts", () => context.addInitScript({ content: scoped(script) }));
|
|
406
|
+
yield* followOpened(context, register, publish, now, registrations);
|
|
407
|
+
for (const existing of context.pages()) yield* register(existing);
|
|
408
|
+
const pages = Effect.sync(() => [...registry.values()]);
|
|
409
|
+
const newPage = Effect.fn("Browser.newPage")(function* (url) {
|
|
410
|
+
const page = yield* budget.open(native("newPage", () => context.newPage()).pipe(Effect.flatMap((playwright) => register(playwright).pipe(Effect.onError(() => release(() => playwright.close()))))));
|
|
411
|
+
if (url !== void 0) yield* page.goto(url).pipe(Effect.onError(() => page.close.pipe(Effect.ignore)));
|
|
412
|
+
return page;
|
|
413
|
+
});
|
|
414
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => lose("released")));
|
|
415
|
+
const service = {
|
|
416
|
+
id: info.id,
|
|
417
|
+
provider: info.provider,
|
|
418
|
+
expiresAt: info.expiresAt,
|
|
419
|
+
now: Effect.sync(now),
|
|
420
|
+
context,
|
|
421
|
+
pages,
|
|
422
|
+
page: (id) => Effect.map(pages, (open) => Option.fromNullishOr(open.find((page) => page.id === id))),
|
|
423
|
+
firstPage: pages.pipe(Effect.map((open) => Option.fromNullishOr(open[0])), Effect.flatMap(Option.match({
|
|
424
|
+
onNone: () => newPage(),
|
|
425
|
+
onSome: Effect.succeed
|
|
426
|
+
}))),
|
|
427
|
+
newPage,
|
|
428
|
+
disconnected: lost,
|
|
429
|
+
events: (eventOptions = {}) => timeline.stream(eventOptions.after),
|
|
430
|
+
recentEvents: timeline.recent.pipe(Effect.map((records) => records.map((record) => record.event)))
|
|
431
|
+
};
|
|
432
|
+
return Browser.of(service);
|
|
433
|
+
});
|
|
434
|
+
//#endregion
|
|
435
|
+
export { Browser_exports as n, make as r, Browser as t };
|
|
436
|
+
|
|
437
|
+
//# sourceMappingURL=Browser-CM65Uo7f.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Browser-CM65Uo7f.mjs","names":["make","make","Url.redact","mapping","BrowserClock.mapping","Timeline.make","PageImpl.make","Openings.make"],"sources":["../src/internal/page/openings.ts","../src/internal/timeline/events.ts","../src/Browser.ts"],"sourcesContent":["/** A page's input waits for the actual tabs it opened to finish the browser's registration. */\nimport { Deferred, Effect, Exit } from \"effect\";\nimport type { CDPSession, Page as PlaywrightPage } from \"playwright-core\";\n\nimport { BrowserError, Closed, Failed, type Reason } from \"../../BrowserError.ts\";\n\n/** How the browser's registration of each tab it was told of ended, once it has. */\nexport type Registrations = WeakMap<PlaywrightPage, Deferred.Deferred<void, BrowserError>>;\n\nexport interface Mark {\n windows: number;\n readonly registrations: Array<Effect.Effect<void, BrowserError>>;\n changed: Deferred.Deferred<void>;\n}\n\nexport const make = Effect.fnUntraced(function* (\n playwright: PlaywrightPage,\n cdp: CDPSession,\n registrations: Registrations,\n closedBy: () => Closed[\"cause\"],\n) {\n const failed = (reason: Reason) =>\n Exit.fail(new BrowserError({ operation: \"newPage\", reason, dispatched: false }));\n\n let active: Mark | undefined;\n const gone = Deferred.makeUnsafe<never, BrowserError>();\n\n const windowOpened = () => {\n if (active !== undefined) active.windows += 1;\n };\n\n const popup = (opened: PlaywrightPage) => {\n if (active === undefined) return;\n // Playwright emits the context's page event first, so its owner already has this exact\n // popup's registration. A window notification alone has no target id and cannot name it.\n const registered = registrations.get(opened);\n\n active.registrations.push(\n registered === undefined\n ? failed(new Failed({ detail: \"the popup has no registration\" }))\n : Deferred.await(registered),\n );\n Deferred.doneUnsafe(active.changed, Exit.void);\n active.changed = Deferred.makeUnsafe<void>();\n };\n\n const clear = Effect.sync(() => {\n active = undefined;\n });\n\n yield* Effect.acquireRelease(\n Effect.sync(() => {\n cdp.on(\"Page.windowOpen\", windowOpened);\n playwright.on(\"popup\", popup);\n }),\n () =>\n Effect.sync(() => {\n active = undefined;\n cdp.off(\"Page.windowOpen\", windowOpened);\n playwright.off(\"popup\", popup);\n Deferred.doneUnsafe(gone, failed(new Closed({ cause: closedBy() })));\n }),\n );\n\n return {\n mark: () => {\n const mark: Mark = { windows: 0, registrations: [], changed: Deferred.makeUnsafe<void>() };\n\n active = mark;\n\n return mark;\n },\n clear,\n settle: (mark: Mark) =>\n Effect.gen(function* () {\n // A blocked window or a tab that closes as it opens may never become a Playwright popup.\n // Discovery and registration both share the input's deadline, so an unresolved opening\n // fails with potentially dispatched input rather than claiming the tab has been tracked.\n while (mark.registrations.length < mark.windows) yield* Deferred.await(mark.changed);\n // A real popup has a known registration; its failure stays a failure, and its wait shares\n // the input's deadline rather than quietly returning before the browser tracks it.\n yield* Effect.forEach(mark.registrations, (registration) => registration);\n }).pipe(Effect.raceFirst(Deferred.await(gone)), Effect.ensuring(clear)),\n };\n});\n\nexport type Openings = Effect.Success<ReturnType<typeof make>>;\n","/**\n * The browser's bounded event history and replay cursors. Readers share the same records and\n * wakeup generation, so a delayed reader cannot block input or retain an unbounded private queue.\n */\nimport { Cause, Deferred, Effect, Stream } from \"effect\";\n\nimport { type BrowserError, EventHistoryExpired, InvalidRequest } from \"../../BrowserError.ts\";\nimport { type BrowserEvent, RecordedEvent } from \"../../BrowserEvent.ts\";\nimport { undispatched } from \"../page/context.ts\";\n\n/** The owning Browser validates capacity and closes this timeline with its scope. */\nexport const make = (capacity: number) => {\n let records: ReadonlyArray<RecordedEvent> = [];\n let sequence = 0;\n let closed = false;\n let changed = Deferred.makeUnsafe<void>();\n\n const wake = () => {\n const previous = changed;\n\n changed = Deferred.makeUnsafe<void>();\n Deferred.doneUnsafe(previous, Effect.void);\n };\n\n const publish = (event: BrowserEvent): number => {\n // Native callbacks may finish after their owning scope. They must not revive closed readers.\n if (closed) return sequence;\n sequence += 1;\n const recorded = new RecordedEvent({ sequence, event });\n\n records = records.length < capacity ? [...records, recorded] : [...records.slice(1), recorded];\n wake();\n\n return sequence;\n };\n\n const stream = (after?: number): Stream.Stream<RecordedEvent, BrowserError> =>\n Stream.unwrap(\n Effect.sync(() => {\n // This runs for each subscription, rather than when the reusable stream is constructed.\n let cursor = after ?? sequence;\n\n if (!Number.isSafeInteger(cursor) || cursor < 0 || cursor > sequence)\n return Stream.fail(\n undispatched(\n \"events\",\n new InvalidRequest({\n detail:\n \"the event cursor must be a nonnegative integer no greater than the latest sequence\",\n }),\n ),\n );\n\n return Stream.fromEffectRepeat(\n Effect.gen(function* () {\n while (true) {\n const oldest = records[0]?.sequence ?? sequence + 1;\n\n if (cursor < oldest - 1)\n return yield* undispatched(\n \"events\",\n new EventHistoryExpired({ after: cursor, oldest, latest: sequence }),\n );\n const next = records[cursor - oldest + 1];\n\n if (next !== undefined) {\n cursor = next.sequence;\n\n return next;\n }\n if (closed) return yield* Cause.done();\n // Capture the generation in the same synchronous read as the empty history check.\n // A publish before await completes this exact Deferred, so no wakeup can be missed.\n const waiting = changed;\n\n yield* Deferred.await(waiting);\n }\n }),\n );\n }),\n );\n\n return {\n publish,\n recent: Effect.sync(() => records),\n stream,\n close: Effect.sync(() => {\n if (closed) return;\n closed = true;\n wake();\n }),\n };\n};\n","/**\n * A live browser: its pages and what happens in it.\n *\n * `Browser` is a service with one implementation, built by a provider over a Playwright browser\n * context: `Chromium` launches one locally, `Cdp` connects to any DevTools endpoint and\n * `effect-browserbase` allocates a hosted one. Code written against `Browser` runs on all three.\n * A page is named by its CDP target id, so a new connection to the same browser finds it again.\n *\n * @since 0.3.0\n */\nimport {\n Clock,\n Context,\n DateTime,\n Deferred,\n Duration,\n Effect,\n Exit,\n Option,\n Queue,\n Scope,\n Semaphore,\n type Stream,\n} from \"effect\";\nimport type { BrowserContext, Dialog, Page as PlaywrightPage } from \"playwright-core\";\n\nimport { type BrowserError, Failed, InvalidRequest, Limit } from \"./BrowserError.ts\";\nimport {\n type BrowserEvent,\n DialogShown,\n Disconnected,\n type DisconnectCause,\n PageClosed,\n PageOpened,\n PageUntracked,\n type RecordedEvent,\n SessionEnding,\n} from \"./BrowserEvent.ts\";\nimport { call, failWith, type Settings, undispatched } from \"./internal/page/context.ts\";\nimport { FailFast } from \"./internal/page/lane.ts\";\nimport * as Openings from \"./internal/page/openings.ts\";\nimport * as PageImpl from \"./internal/page/page.ts\";\nimport * as Url from \"./internal/page/url.ts\";\nimport * as BrowserClock from \"./internal/pictures/clock.ts\";\nimport * as Timeline from \"./internal/timeline/events.ts\";\nimport type * as Page from \"./Page.ts\";\n\n/** A script that documents run before their own, such as a consent-banner remover. */\nexport interface InitScript {\n /**\n * The documents that run it, by a pattern their address (`location.href`) matches; every\n * document and frame when left out. Under a `match`, the source runs as a block, so its own\n * top-level `let`, `const` and classes stay its own.\n */\n readonly match?: RegExp | undefined;\n readonly source: string;\n}\n\nexport interface Options {\n /**\n * Bound on each action; finite and positive. Defaults to 10 seconds. What a presenter's view\n * takes to show an action, such as its glides and typing at a person's pace, does not count\n * against it.\n */\n readonly actionTimeout?: Duration.Input | undefined;\n /** Bound on each navigation; finite and positive. Defaults to 30 seconds. */\n readonly navigationTimeout?: Duration.Input | undefined;\n /**\n * How long each page keeps screencast frames for `recentFrames`, measured back from the newest;\n * finite and positive. Defaults to 5 seconds, a moment's default window.\n */\n readonly frameHistory?: Duration.Input | undefined;\n /** Events retained for replay and `recentEvents`. A positive safe integer, defaulting to 4,096. */\n readonly eventHistory?: number | undefined;\n /** Allow, deny or hold each input or navigation before it reaches the page. Defaults to allow. */\n readonly guard?: Page.InputGuard | undefined;\n /** A separate bound for policy holds, outside action timeouts. Defaults to 5 minutes. */\n readonly policyTimeout?: Duration.Input | undefined;\n /** Scripts that new documents run before their own, each where its `match` allows. */\n readonly initScripts?: ReadonlyArray<InitScript> | undefined;\n /**\n * The most pages the browser keeps open, those a site opens included, which are never refused. At\n * it, `newPage` waits for one to close, within the action timeout, then fails `Limit`; under\n * `Page.failFast` it fails at once. A positive safe integer; no limit when left out.\n */\n readonly maxPages?: number | undefined;\n}\n\nexport interface EventOptions {\n /** Resume after this sequence; 0 replays from the beginning if it is still retained. */\n readonly after?: number | undefined;\n}\n\n/**\n * A connection to the browser apart from the one that drives its pages, for their screencasts,\n * as a provider that reaches the browser over a network supplies it: a frame and its\n * acknowledgement then never wait behind a large message, such as an upload or a read's answer,\n * on the connection that drives the page. It is read-only. A page's session on it sends the\n * capture's commands alone, and the page's own session keeps its focus emulation, which keeps a\n * tab behind painting.\n */\nexport interface CaptureSource {\n /**\n * A session on the page's target, for the scope. `event` gets the session's events in the order\n * the browser sent them, its target's detach among them, until the scope closes; `lost` gets\n * the connection's failure, once, if it fails first. Its calls never throw: a failure rejects.\n */\n readonly attach: (\n target: string,\n listener: {\n readonly event: (method: string, params: unknown) => void;\n readonly lost: (error: BrowserError) => void;\n },\n ) => Effect.Effect<\n (\n method:\n | \"Page.enable\"\n | \"Page.getFrameTree\"\n | \"Page.startScreencast\"\n | \"Page.screencastFrameAck\"\n | \"Page.stopScreencast\",\n params?: Record<string, unknown>,\n ) => Promise<unknown>,\n BrowserError,\n Scope.Scope\n >;\n}\n\nexport interface Service {\n /** The provider's session id, or a local id. */\n readonly id: string;\n readonly provider: string;\n /** When the provider ends the session on its own, as a hosted session's timeout does. */\n readonly expiresAt: DateTime.Utc | undefined;\n /** Host monotonic milliseconds on the clock shared by this browser’s events and frames. */\n readonly now: Effect.Effect<number>;\n /** The Playwright context, for anything this API does not cover. Never give it to a model. */\n readonly context: BrowserContext;\n /** Open pages in the order this browser began tracking them. */\n readonly pages: Effect.Effect<ReadonlyArray<Page.Page>>;\n /** The open page with this id, its CDP target id, as stored before a reconnect. */\n readonly page: (id: string) => Effect.Effect<Option.Option<Page.Page>>;\n /** The first open page, opening one when there is none. */\n readonly firstPage: Effect.Effect<Page.Page, BrowserError>;\n readonly newPage: (url?: string) => Effect.Effect<Page.Page, BrowserError>;\n /**\n * Completes once the browser is lost to its owner, with why: its connection dropped, its\n * provider ended its session, or its owner's scope released it.\n */\n readonly disconnected: Effect.Effect<DisconnectCause>;\n /** Live events, or replay after a cursor. A reader that falls behind fails with EventHistoryExpired. */\n readonly events: (options?: EventOptions) => Stream.Stream<RecordedEvent, BrowserError>;\n /** The latest `eventHistory` events, oldest first. */\n readonly recentEvents: Effect.Effect<ReadonlyArray<BrowserEvent>>;\n}\n\nexport class Browser extends Context.Service<Browser, Service>()(\"effect-browser/Browser\") {}\n\n/** The settings every page shares, and how many events the browser keeps, from its options. */\nconst settingsOf = Effect.fnUntraced(function* (options: Options) {\n const invalid = (detail: string) => undispatched(\"make\", new InvalidRequest({ detail }));\n\n // Every bound guards a lock or a held key, so each must be a real, finite deadline.\n const bound = (name: string, input: Duration.Input | undefined, fallback: Duration.Duration) => {\n const decoded = Duration.fromInput(input ?? fallback);\n\n return Option.isSome(decoded) &&\n Number.isFinite(Duration.toMillis(decoded.value)) &&\n Duration.isPositive(decoded.value)\n ? Effect.succeed(decoded.value)\n : Effect.fail(invalid(`${name} must be finite and greater than zero`));\n };\n\n const settings: Settings = {\n actionTimeout: yield* bound(\"actionTimeout\", options.actionTimeout, Duration.seconds(10)),\n navigationTimeout: yield* bound(\n \"navigationTimeout\",\n options.navigationTimeout,\n Duration.seconds(30),\n ),\n frameHistory: yield* bound(\"frameHistory\", options.frameHistory, Duration.seconds(5)),\n guard: options.guard,\n policyTimeout: yield* bound(\"policyTimeout\", options.policyTimeout, Duration.minutes(5)),\n };\n\n const eventHistory = options.eventHistory ?? 4096;\n const { maxPages } = options;\n\n if (!Number.isSafeInteger(eventHistory) || eventHistory < 1)\n return yield* invalid(\"eventHistory must be a positive safe integer\");\n if (maxPages !== undefined && (!Number.isSafeInteger(maxPages) || maxPages < 1))\n return yield* invalid(\"maxPages must be a positive safe integer\");\n\n return { settings, eventHistory, maxPages };\n});\n\n/**\n * A provider that ends a session at `expiresAt` by its own clock can cut the connection a little\n * before this host's clock gets there.\n */\nconst endMargin = Duration.seconds(5);\n\n/**\n * The browser's loss, once: its context closing from the other side, at or after the session's\n * end or before it, or `lose`, as the owner's scope releases it. Playwright leaves the calls in\n * flight on the library's own sessions unanswered when the connection drops, so `untilLost` fails\n * each with the browser, as a closed page's call fails.\n */\nconst watchLoss = Effect.fnUntraced(function* (\n context: BrowserContext,\n expiresAt: DateTime.Utc | undefined,\n clock: Clock.Clock,\n disconnected: (cause: DisconnectCause) => void,\n) {\n let lostBy: DisconnectCause | undefined;\n const lost = yield* Deferred.make<DisconnectCause>();\n const inFlight = new Set<(cause: Error) => void>();\n const gone = () => new Error(\"Target page, context or browser has been closed\");\n\n const lose = (cause: DisconnectCause) => {\n if (lostBy !== undefined) return;\n lostBy = cause;\n for (const reject of inFlight) reject(gone());\n disconnected(cause);\n Deferred.doneUnsafe(lost, Exit.succeed(cause));\n };\n\n const untilLost = <A>(reply: Promise<A>): Promise<A> => {\n if (lostBy !== undefined) {\n void reply.catch(() => undefined);\n\n return Promise.reject(gone());\n }\n\n return new Promise<A>((resolve, reject) => {\n inFlight.add(reject);\n void reply.then(resolve, reject).finally(() => inFlight.delete(reject));\n });\n };\n\n const ended = () =>\n expiresAt !== undefined &&\n clock.currentTimeMillisUnsafe() >=\n DateTime.toEpochMillis(expiresAt) - Duration.toMillis(endMargin);\n\n const onClose = () => lose(ended() ? \"session\" : \"connection\");\n\n context.on(\"close\", onClose);\n yield* Effect.addFinalizer(() => Effect.sync(() => context.off(\"close\", onClose)));\n if (context.browser()?.isConnected() === false) onClose();\n\n const native = <A>(operation: string, run: () => Promise<A>) =>\n call(operation, run, () => lostBy ?? \"page\");\n\n return { lostBy: () => lostBy, lost: Deferred.await(lost), lose, untilLost, native };\n});\n\n/**\n * What a page's own Playwright events publish, its close and crash aside, while its scope is\n * open. Dialogs are answered: alerts accepted, others dismissed. The page's own session tells its\n * documents' commits and loads.\n */\nconst listen = (\n playwright: PlaywrightPage,\n page: string,\n publish: (event: BrowserEvent) => number,\n now: () => number,\n on: { readonly close: () => void; readonly crash: () => void },\n) => {\n const dialog = (shown: Dialog) => {\n const kind = shown.type();\n const answer = kind === \"alert\" || kind === \"beforeunload\" ? \"accepted\" : \"dismissed\";\n const message = shown.message().slice(0, 500);\n\n publish(new DialogShown({ at: now(), page, kind, message, answer }));\n (answer === \"accepted\" ? shown.accept() : shown.dismiss()).catch(() => undefined);\n };\n\n return Effect.acquireRelease(\n Effect.sync(() => {\n playwright.on(\"close\", on.close);\n playwright.on(\"crash\", on.crash);\n playwright.on(\"dialog\", dialog);\n }),\n () =>\n Effect.sync(() => {\n playwright.off(\"close\", on.close);\n playwright.off(\"crash\", on.crash);\n playwright.off(\"dialog\", dialog);\n }),\n );\n};\n\n/**\n * Register each page the site opens, such as a popup, as Playwright reports it, for as long as the\n * scope is open. One that could not be tracked is published, unless it closed as it opened.\n */\nconst followOpened = Effect.fnUntraced(function* (\n context: BrowserContext,\n register: (playwright: PlaywrightPage) => Effect.Effect<Page.Page, BrowserError>,\n publish: (event: BrowserEvent) => number,\n now: () => number,\n registrations: Openings.Registrations,\n) {\n const opened = yield* Queue.unbounded<PlaywrightPage>();\n\n const onPage = (playwright: PlaywrightPage) => {\n registrations.set(playwright, Deferred.makeUnsafe<void, BrowserError>());\n Queue.offerUnsafe(opened, playwright);\n };\n\n const untracked = (playwright: PlaywrightPage) => (error: BrowserError) =>\n Effect.sync(() => {\n const url = Url.redact(playwright.url());\n\n if (!playwright.isClosed())\n publish(new PageUntracked({ at: now(), url, detail: error.message }));\n });\n\n context.on(\"page\", onPage);\n yield* Effect.addFinalizer(() => Effect.sync(() => context.off(\"page\", onPage)));\n yield* Queue.take(opened).pipe(\n Effect.flatMap((playwright) =>\n register(playwright).pipe(\n Effect.asVoid,\n Effect.onExit((exit) =>\n Effect.sync(() => {\n const done = registrations.get(playwright);\n\n if (done !== undefined) Deferred.doneUnsafe(done, exit);\n }),\n ),\n Effect.catch(untracked(playwright)),\n ),\n ),\n Effect.forever,\n Effect.forkScoped,\n );\n});\n\n/** Release something native, on the owner's clock, giving up after a second: cleanup only. */\nconst releaseNative = (clock: Clock.Clock) => (run: () => Promise<unknown>) =>\n Effect.tryPromise(run).pipe(\n Effect.interruptible,\n Effect.timeoutOrElse({ duration: Duration.seconds(1), orElse: () => Effect.void }),\n Effect.provideService(Clock.Clock, clock),\n Effect.ignore,\n );\n\n/** A page's own events among the browser's retained ones, and the openings of tabs it opened. */\nconst eventsOf = (recent: Effect.Effect<ReadonlyArray<RecordedEvent>>, page: string) =>\n Effect.map(recent, (records) =>\n records.flatMap(({ event }) =>\n (\"page\" in event && event.page === page) ||\n (event._tag === \"PageOpened\" && event.opener === page)\n ? [event]\n : [],\n ),\n );\n\n/** A script as its documents run it: everywhere, or as a block where its `match` allows. */\nconst scoped = ({ match, source }: InitScript) =>\n match === undefined ? source : `if (${String(match)}.test(location.href)) {\\n${source}\\n}`;\n\n/**\n * At most `maxPages` open pages, those a site opened included, which are never refused: an open\n * past it waits for one to close, within `wait` on the owner's clock, then fails `Limit`, or fails\n * at once under `FailFast`. An open counts until its page is tracked.\n */\nconst pageBudget = (\n maxPages: number | undefined,\n tracked: () => number,\n wait: Duration.Duration,\n clock: Clock.Clock,\n) => {\n let opening = 0;\n // Completed as a page closes or an open ends, so the opens waiting look again.\n let roomMade = Deferred.makeUnsafe<void>();\n\n const makeRoom = () => {\n Deferred.doneUnsafe(roomMade, Exit.void);\n roomMade = Deferred.makeUnsafe<void>();\n };\n\n const full = (limit: number) => tracked() + opening >= limit;\n\n const room = (limit: number) =>\n Effect.gen(function* () {\n const refused = undispatched(\"newPage\", new Limit({ maxPages: limit }));\n\n if ((yield* FailFast) && full(limit)) return yield* refused;\n yield* Effect.gen(function* () {\n while (full(limit)) yield* Deferred.await(roomMade);\n opening += 1;\n }).pipe(\n Effect.timeoutOrElse({ duration: wait, orElse: () => Effect.fail(refused) }),\n Effect.provideService(Clock.Clock, clock),\n );\n });\n\n const open = <A, E, R>(opened: Effect.Effect<A, E, R>) =>\n maxPages === undefined\n ? opened\n : Effect.uninterruptibleMask((restore) =>\n restore(room(maxPages)).pipe(\n Effect.andThen(\n restore(opened).pipe(\n Effect.ensuring(\n Effect.sync(() => {\n opening -= 1;\n makeRoom();\n }),\n ),\n ),\n ),\n ),\n );\n\n return { makeRoom, open };\n};\n\n/** A call sent now and awaited later, by whatever needs its answer. */\nconst sentNow = <A>(sent: Promise<A>) => {\n void sent.catch(() => undefined);\n\n return sent;\n};\n\n/**\n * Build the service over a context the provider owns. The provider closes the context; this only\n * tracks its pages and events, for as long as the surrounding scope is open. Each page's protocol\n * session, capture and listeners end when that page closes or when the scope does, so a closed\n * tab retains nothing and the context keeps none of them afterwards.\n */\nexport const make = Effect.fn(\"Browser.make\")(function* (\n context: BrowserContext,\n info: {\n readonly id: string;\n readonly provider: string;\n readonly expiresAt?: DateTime.Utc | undefined;\n /** Where pages' screencasts run, if not on each page's own session. */\n readonly capture?: CaptureSource | undefined;\n },\n options: Options = {},\n) {\n const clock = yield* Clock.Clock;\n const now = () => Number(clock.monotonicTimeNanosUnsafe()) / 1e6;\n const { settings, eventHistory, maxPages } = yield* settingsOf(options);\n // Measured on first need: the first capture of any page measures it, and input never waits.\n const mapping = BrowserClock.mapping(now);\n\n const timeline = Timeline.make(eventHistory);\n\n yield* Effect.addFinalizer(() => timeline.close);\n const publish = timeline.publish;\n\n if (info.expiresAt !== undefined)\n publish(new SessionEnding({ at: now(), expiresAt: info.expiresAt }));\n\n const { lostBy, lost, lose, untilLost, native } = yield* watchLoss(\n context,\n info.expiresAt,\n clock,\n (cause) => publish(new Disconnected({ at: now(), cause })),\n );\n\n const registry = new Map<PlaywrightPage, Page.Page>();\n const registrations: Openings.Registrations = new WeakMap();\n const registering = yield* Semaphore.make(1);\n // The pages' scopes close after the browser is marked released, so what fails as they close\n // says why.\n const pagesScope = yield* Scope.fork(yield* Scope.Scope);\n\n const release = releaseNative(clock);\n const budget = pageBudget(maxPages, () => registry.size, settings.actionTimeout, clock);\n\n // Each tab's scope closes with the tab or the browser. A dropped connection closes every page,\n // then the context, and `Disconnected` stands for all of them: the queue hands a close to its\n // fiber in a later turn, once Playwright has reported the context's.\n const closing = yield* Queue.unbounded<{\n readonly scope: Scope.Closeable;\n readonly page: string;\n readonly cause: PageClosed[\"cause\"];\n }>();\n\n yield* Queue.take(closing).pipe(\n Effect.tap(({ page, cause }) =>\n Effect.sync(() => {\n if (lostBy() === undefined) publish(new PageClosed({ at: now(), page, cause }));\n }),\n ),\n Effect.flatMap(({ scope }) => Scope.close(scope, Exit.void)),\n Effect.forever,\n Effect.forkScoped,\n );\n\n const register = (playwright: PlaywrightPage) =>\n registering.withPermits(1)(\n Effect.gen(function* () {\n const known = registry.get(playwright);\n\n if (known !== undefined) return known;\n if (playwright.isClosed())\n return yield* failWith(\"newPage\", new Failed({ detail: \"the page closed as it opened\" }));\n const scope = yield* Scope.fork(pagesScope);\n\n return yield* Effect.gen(function* () {\n let crashed = false;\n const closedBy = () => lostBy() ?? (crashed ? \"crashed\" : \"page\");\n const cdp = yield* native(\"newPage\", () => context.newCDPSession(playwright));\n\n yield* Effect.addFinalizer(() => release(() => cdp.detach()));\n // The page's name, its target id, costs one round trip, which the calls that keep it\n // painting behind other tabs and report its documents share. A renderer busy with its\n // first script answers those two late, so what needs them waits, and registering does not.\n const send: typeof cdp.send = (method, params) => untilLost(cdp.send(method, params));\n const focusing = sentNow(send(\"Emulation.setFocusEmulationEnabled\", { enabled: true }));\n const paging = sentNow(send(\"Page.enable\"));\n const { targetInfo } = yield* native(\"newPage\", () => send(\"Target.getTargetInfo\"));\n const id = targetInfo.targetId;\n\n const page = yield* PageImpl.make({\n id,\n session: info.id,\n url: targetInfo.url,\n playwright,\n cdp,\n untilLost,\n settings,\n clock,\n mapping,\n publish,\n recentEvents: eventsOf(timeline.recent, id),\n openings: yield* Openings.make(playwright, cdp, registrations, closedBy),\n focused: call(\"focus\", () => focusing, closedBy).pipe(Effect.asVoid),\n paging: (operation) => call(operation, () => paging, closedBy).pipe(Effect.asVoid),\n closedBy,\n capture: info.capture,\n });\n\n const close = () => {\n if (registry.get(playwright) !== page) return;\n registry.delete(playwright);\n budget.makeRoom();\n Queue.offerUnsafe(closing, { scope, page: id, cause: crashed ? \"crashed\" : \"page\" });\n };\n\n // Playwright drives a crashed page no more and its calls never return, so it is closed:\n // they fail at once, `Closed` because it crashed.\n const crash = () => {\n crashed = true;\n void playwright.close().catch(() => undefined);\n };\n\n registry.set(playwright, page);\n publish(\n new PageOpened({\n at: now(),\n page: id,\n url: Url.redact(targetInfo.url),\n opener: targetInfo.openerId,\n }),\n );\n yield* listen(playwright, id, publish, now, { close, crash });\n if (playwright.isClosed()) close();\n\n return page;\n }).pipe(\n Scope.provide(scope),\n Effect.onError(() => Scope.close(scope, Exit.void)),\n );\n }),\n );\n\n // Playwright registers its init scripts as it sets up each page, before a popup's first document\n // runs, and they cost no call per document.\n for (const script of options.initScripts ?? [])\n yield* native(\"initScripts\", () => context.addInitScript({ content: scoped(script) }));\n yield* followOpened(context, register, publish, now, registrations);\n for (const existing of context.pages()) yield* register(existing);\n\n const pages = Effect.sync(() => [...registry.values()]);\n\n const newPage = Effect.fn(\"Browser.newPage\")(function* (url?: string) {\n const page = yield* budget.open(\n native(\"newPage\", () => context.newPage()).pipe(\n Effect.flatMap((playwright) =>\n register(playwright).pipe(Effect.onError(() => release(() => playwright.close()))),\n ),\n ),\n );\n\n // A rejected or interrupted navigation must not leave the newly allocated blank tab behind.\n if (url !== undefined)\n yield* page.goto(url).pipe(Effect.onError(() => page.close.pipe(Effect.ignore)));\n\n return page;\n });\n\n // Added last, so it runs first as the owner's scope closes.\n yield* Effect.addFinalizer(() => Effect.sync(() => lose(\"released\")));\n\n const service: Service = {\n id: info.id,\n provider: info.provider,\n expiresAt: info.expiresAt,\n now: Effect.sync(now),\n context,\n pages,\n page: (id) =>\n Effect.map(pages, (open) => Option.fromNullishOr(open.find((page) => page.id === id))),\n firstPage: pages.pipe(\n Effect.map((open) => Option.fromNullishOr(open[0])),\n Effect.flatMap(Option.match({ onNone: () => newPage(), onSome: Effect.succeed })),\n ),\n newPage,\n disconnected: lost,\n events: (eventOptions = {}) => timeline.stream(eventOptions.after),\n recentEvents: timeline.recent.pipe(\n Effect.map((records) => records.map((record) => record.event)),\n ),\n };\n\n return Browser.of(service);\n});\n"],"mappings":";;;;;;;;;AAeA,MAAaA,SAAO,OAAO,WAAW,WACpC,YACA,KACA,eACA,UACA;CACA,MAAM,UAAU,WACd,KAAK,KAAK,IAAI,aAAa;EAAE,WAAW;EAAW;EAAQ,YAAY;CAAM,CAAC,CAAC;CAEjF,IAAI;CACJ,MAAM,OAAO,SAAS,WAAgC;CAEtD,MAAM,qBAAqB;EACzB,IAAI,WAAW,KAAA,GAAW,OAAO,WAAW;CAC9C;CAEA,MAAM,SAAS,WAA2B;EACxC,IAAI,WAAW,KAAA,GAAW;EAG1B,MAAM,aAAa,cAAc,IAAI,MAAM;EAE3C,OAAO,cAAc,KACnB,eAAe,KAAA,IACX,OAAO,IAAI,OAAO,EAAE,QAAQ,gCAAgC,CAAC,CAAC,IAC9D,SAAS,MAAM,UAAU,CAC/B;EACA,SAAS,WAAW,OAAO,SAAS,KAAK,IAAI;EAC7C,OAAO,UAAU,SAAS,WAAiB;CAC7C;CAEA,MAAM,QAAQ,OAAO,WAAW;EAC9B,SAAS,KAAA;CACX,CAAC;CAED,OAAO,OAAO,eACZ,OAAO,WAAW;EAChB,IAAI,GAAG,mBAAmB,YAAY;EACtC,WAAW,GAAG,SAAS,KAAK;CAC9B,CAAC,SAEC,OAAO,WAAW;EAChB,SAAS,KAAA;EACT,IAAI,IAAI,mBAAmB,YAAY;EACvC,WAAW,IAAI,SAAS,KAAK;EAC7B,SAAS,WAAW,MAAM,OAAO,IAAI,OAAO,EAAE,OAAO,SAAS,EAAE,CAAC,CAAC,CAAC;CACrE,CAAC,CACL;CAEA,OAAO;EACL,YAAY;GACV,MAA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WAAW,MAAM,KACf,OAAO,KAAK,SAAS,OAAO,cAAc,KAAK,EAAE,CAAC,GAClD,OAAO,QAAQ,OAAO,MAAM;GAAE,cAAc,QAAQ;GAAG,QAAQ,OAAO;EAAQ,CAAC,CAAC,CAClF;EACA;EACA,cAAc;EACd,SAAS,eAAe,CAAC,MAAM,SAAS,OAAO,aAAa,KAAK;EACjE,cAAc,SAAS,OAAO,KAC5B,OAAO,KAAK,YAAY,QAAQ,KAAK,WAAW,OAAO,KAAK,CAAC,CAC/D;CACF;CAEA,OAAO,QAAQ,GAAG,OAAO;AAC3B,CAAC"}
|
package/dist/Browser.d.mts
CHANGED
|
@@ -1,3 +1,115 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { t as BrowserError } from "./BrowserError-DXXIA6Rk.mjs";
|
|
2
|
+
import { c as DisconnectCause, i as BrowserEvent, v as RecordedEvent } from "./BrowserEvent-DzdNdvoh.mjs";
|
|
3
|
+
import { c as InputGuard, d as Page_d_exports, u as Page$1 } from "./Page-DYTdVhYa.mjs";
|
|
4
|
+
import { Context, DateTime, Duration, Effect, Option, Scope, Stream } from "effect";
|
|
5
|
+
import { BrowserContext } from "playwright-core";
|
|
6
|
+
declare namespace Browser_d_exports {
|
|
7
|
+
export { Browser, CaptureSource, EventOptions, InitScript, Options, Service, 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
|
+
/**
|
|
53
|
+
* A connection to the browser apart from the one that drives its pages, for their screencasts,
|
|
54
|
+
* as a provider that reaches the browser over a network supplies it: a frame and its
|
|
55
|
+
* acknowledgement then never wait behind a large message, such as an upload or a read's answer,
|
|
56
|
+
* on the connection that drives the page. It is read-only. A page's session on it sends the
|
|
57
|
+
* capture's commands alone, and the page's own session keeps its focus emulation, which keeps a
|
|
58
|
+
* tab behind painting.
|
|
59
|
+
*/
|
|
60
|
+
export interface CaptureSource {
|
|
61
|
+
/**
|
|
62
|
+
* A session on the page's target, for the scope. `event` gets the session's events in the order
|
|
63
|
+
* the browser sent them, its target's detach among them, until the scope closes; `lost` gets
|
|
64
|
+
* the connection's failure, once, if it fails first. Its calls never throw: a failure rejects.
|
|
65
|
+
*/
|
|
66
|
+
readonly attach: (target: string, listener: {
|
|
67
|
+
readonly event: (method: string, params: unknown) => void;
|
|
68
|
+
readonly lost: (error: BrowserError) => void;
|
|
69
|
+
}) => Effect.Effect<(method: "Page.enable" | "Page.getFrameTree" | "Page.startScreencast" | "Page.screencastFrameAck" | "Page.stopScreencast", params?: Record<string, unknown>) => Promise<unknown>, BrowserError, Scope.Scope>;
|
|
70
|
+
}
|
|
71
|
+
export interface Service {
|
|
72
|
+
/** The provider's session id, or a local id. */
|
|
73
|
+
readonly id: string;
|
|
74
|
+
readonly provider: string;
|
|
75
|
+
/** When the provider ends the session on its own, as a hosted session's timeout does. */
|
|
76
|
+
readonly expiresAt: DateTime.Utc | undefined;
|
|
77
|
+
/** Host monotonic milliseconds on the clock shared by this browser’s events and frames. */
|
|
78
|
+
readonly now: Effect.Effect<number>;
|
|
79
|
+
/** The Playwright context, for anything this API does not cover. Never give it to a model. */
|
|
80
|
+
readonly context: BrowserContext;
|
|
81
|
+
/** Open pages in the order this browser began tracking them. */
|
|
82
|
+
readonly pages: Effect.Effect<ReadonlyArray<Page$1>>;
|
|
83
|
+
/** The open page with this id, its CDP target id, as stored before a reconnect. */
|
|
84
|
+
readonly page: (id: string) => Effect.Effect<Option.Option<Page$1>>;
|
|
85
|
+
/** The first open page, opening one when there is none. */
|
|
86
|
+
readonly firstPage: Effect.Effect<Page$1, BrowserError>;
|
|
87
|
+
readonly newPage: (url?: string) => Effect.Effect<Page$1, BrowserError>;
|
|
88
|
+
/**
|
|
89
|
+
* Completes once the browser is lost to its owner, with why: its connection dropped, its
|
|
90
|
+
* provider ended its session, or its owner's scope released it.
|
|
91
|
+
*/
|
|
92
|
+
readonly disconnected: Effect.Effect<DisconnectCause>;
|
|
93
|
+
/** Live events, or replay after a cursor. A reader that falls behind fails with EventHistoryExpired. */
|
|
94
|
+
readonly events: (options?: EventOptions) => Stream.Stream<RecordedEvent, BrowserError>;
|
|
95
|
+
/** The latest `eventHistory` events, oldest first. */
|
|
96
|
+
readonly recentEvents: Effect.Effect<ReadonlyArray<BrowserEvent>>;
|
|
97
|
+
}
|
|
98
|
+
declare const Browser_base: Context.ServiceClass<Browser, "effect-browser/Browser", Service>;
|
|
99
|
+
export declare class Browser extends Browser_base {}
|
|
100
|
+
/**
|
|
101
|
+
* Build the service over a context the provider owns. The provider closes the context; this only
|
|
102
|
+
* tracks its pages and events, for as long as the surrounding scope is open. Each page's protocol
|
|
103
|
+
* session, capture and listeners end when that page closes or when the scope does, so a closed
|
|
104
|
+
* tab retains nothing and the context keeps none of them afterwards.
|
|
105
|
+
*/
|
|
106
|
+
export declare const make: (context: BrowserContext, info: {
|
|
107
|
+
readonly id: string;
|
|
108
|
+
readonly provider: string;
|
|
109
|
+
readonly expiresAt?: DateTime.Utc | undefined;
|
|
110
|
+
/** Where pages' screencasts run, if not on each page's own session. */
|
|
111
|
+
readonly capture?: CaptureSource | undefined;
|
|
112
|
+
}, options?: Options | undefined) => Effect.Effect<Service, BrowserError, Scope.Scope>;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { Browser_d_exports as t };
|
|
115
|
+
//# sourceMappingURL=Browser.d.mts.map
|