effect-browser 0.3.0-beta.21 → 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 +130 -159
- package/dist/Action-24sLOubi.d.mts +110 -0
- package/dist/Action.d.mts +2 -0
- package/dist/Action.mjs +141 -0
- package/dist/Action.mjs.map +1 -0
- package/dist/ActionPort.d.mts +15 -0
- package/dist/ActionPort.mjs +101 -0
- package/dist/ActionPort.mjs.map +1 -0
- package/dist/Browser-Cq2K1FEA.mjs +4075 -0
- package/dist/Browser-Cq2K1FEA.mjs.map +1 -0
- package/dist/{Browser-CiXHT1yO.d.mts → Browser-wZhwZSlG.d.mts} +51 -13
- package/dist/Browser.d.mts +2 -2
- package/dist/Browser.mjs +1 -1
- package/dist/{BrowserError-Coy7EW1N.d.mts → BrowserError-BlcmLVzn.d.mts} +22 -7
- package/dist/BrowserError.d.mts +2 -2
- package/dist/BrowserError.mjs +46 -9
- package/dist/BrowserError.mjs.map +1 -1
- package/dist/{BrowserEvent-dq6FRT8w.d.mts → BrowserEvent-lLqJ3GJS.d.mts} +93 -37
- package/dist/BrowserEvent.d.mts +2 -2
- package/dist/BrowserEvent.mjs +29 -24
- package/dist/BrowserEvent.mjs.map +1 -1
- package/dist/{Change-DqING3tr.d.mts → Change-Ba7INmay.d.mts} +4 -6
- package/dist/Change.d.mts +2 -2
- package/dist/Change.mjs +97 -2
- package/dist/Change.mjs.map +1 -0
- package/dist/Clock.d.mts +57 -0
- package/dist/Clock.mjs +80 -0
- package/dist/Clock.mjs.map +1 -0
- package/dist/{Frame-DkNdjjjr.d.mts → Frame-UEH2hO5T.d.mts} +10 -3
- package/dist/Frame.d.mts +2 -2
- package/dist/Frame.mjs +10 -2
- package/dist/Frame.mjs.map +1 -1
- package/dist/{Motion-DND6I-64.d.mts → Geometry-DJx9qrYy.d.mts} +7 -10
- package/dist/Geometry.d.mts +2 -0
- package/dist/Geometry.mjs +32 -0
- package/dist/Geometry.mjs.map +1 -0
- package/dist/Matching.d.mts +37 -0
- package/dist/Matching.mjs +72 -0
- package/dist/Matching.mjs.map +1 -0
- package/dist/Page-BF5izr8R.mjs +795 -0
- package/dist/Page-BF5izr8R.mjs.map +1 -0
- package/dist/{Page-ku6j5t-v.d.mts → Page-CvsOEorc.d.mts} +158 -185
- package/dist/Page.d.mts +2 -2
- package/dist/Page.mjs +1 -1
- package/dist/Released-tURbFmal.d.mts +15 -0
- package/dist/{Snapshot-B34hZ4Jl.d.mts → Snapshot-CtBVOtuu.d.mts} +6 -1
- package/dist/Snapshot.d.mts +1 -1
- package/dist/Snapshot.mjs.map +1 -1
- package/dist/Stillness-CNlvayIo.mjs +136 -0
- package/dist/Stillness-CNlvayIo.mjs.map +1 -0
- package/dist/Style-AO4V7Czt.mjs +357 -0
- package/dist/Style-AO4V7Czt.mjs.map +1 -0
- package/dist/Style.d.mts +72 -0
- package/dist/Style.mjs +2 -0
- package/dist/Url.d.mts +26 -0
- package/dist/Url.mjs +74 -0
- package/dist/Url.mjs.map +1 -0
- package/dist/Window-CMddGMt1.d.mts +34 -0
- package/dist/Window.d.mts +2 -0
- package/dist/Window.mjs +35 -0
- package/dist/Window.mjs.map +1 -0
- package/dist/{cdp-DL7XfEj5.d.mts → connection-2KHI4_KN.d.mts} +4 -4
- package/dist/{cdp-BMpYMWYe.mjs → connection-BTeO0Hiz.mjs} +5 -6
- package/dist/connection-BTeO0Hiz.mjs.map +1 -0
- package/dist/index.d.mts +15 -18
- package/dist/index.mjs +11 -15
- package/dist/moment/Moment.d.mts +86 -0
- package/dist/{Moment.mjs → moment/Moment.mjs} +44 -38
- package/dist/moment/Moment.mjs.map +1 -0
- package/dist/{Plan-DJ4hEEna.d.mts → plan/index.d.mts} +169 -64
- package/dist/{Plan-BG1WifW2.mjs → plan/index.mjs} +122 -199
- package/dist/plan/index.mjs.map +1 -0
- package/dist/{Policy-BGWjbqCl.d.mts → policy/Policy.d.mts} +16 -20
- package/dist/{Policy.mjs → policy/Policy.mjs} +11 -21
- package/dist/policy/Policy.mjs.map +1 -0
- package/dist/presentation/Motion.d.mts +12 -0
- package/dist/{Motion.mjs → presentation/Motion.mjs} +4 -27
- package/dist/presentation/Motion.mjs.map +1 -0
- package/dist/presentation/Presentation.d.mts +30 -0
- package/dist/presentation/Presentation.mjs +105 -0
- package/dist/presentation/Presentation.mjs.map +1 -0
- package/dist/{Stage-NHp8N81k.d.mts → presentation/Stage.d.mts} +12 -15
- package/dist/{Stage.mjs → presentation/Stage.mjs} +68 -76
- package/dist/presentation/Stage.mjs.map +1 -0
- package/dist/presentation/feed.d.mts +20 -0
- package/dist/presentation/feed.mjs +18 -0
- package/dist/presentation/feed.mjs.map +1 -0
- package/dist/providers/Cdp.d.mts +9 -0
- package/dist/{Cdp.mjs → providers/Cdp.mjs} +3 -8
- package/dist/providers/Cdp.mjs.map +1 -0
- package/dist/{Chromium.d.mts → providers/Chromium.d.mts} +6 -7
- package/dist/{Chromium.mjs → providers/Chromium.mjs} +6 -15
- package/dist/providers/Chromium.mjs.map +1 -0
- package/dist/providers/Released.d.mts +2 -0
- package/dist/providers/Released.mjs +12 -0
- package/dist/providers/Released.mjs.map +1 -0
- package/dist/stillness/Stillness.d.mts +12 -0
- package/dist/stillness/Stillness.mjs +2 -0
- package/dist/supervisor/Supervisor.d.mts +104 -0
- package/dist/supervisor/Supervisor.mjs +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 -3
- package/dist/workerd/Cdp.mjs +2 -7
- package/dist/workerd/Cdp.mjs.map +1 -1
- package/package.json +86 -36
- package/src/Action.ts +127 -0
- package/src/ActionPort.ts +128 -0
- package/src/Browser.ts +352 -201
- package/src/BrowserError.ts +63 -6
- package/src/BrowserEvent.ts +26 -25
- package/src/Change.ts +0 -2
- package/src/{internal/pictures/clock.ts → Clock.ts} +17 -6
- package/src/Frame.ts +14 -0
- package/src/Geometry.ts +48 -0
- package/src/{internal/reading/match.inpage.ts → Matching.ts} +34 -4
- package/src/Page.ts +111 -92
- package/src/Snapshot.ts +5 -0
- package/src/{internal/input/style.ts → Style.ts} +121 -14
- package/src/Window.ts +30 -0
- package/src/index.ts +15 -6
- package/src/internal/input/actions.ts +61 -119
- package/src/internal/input/dispatch.ts +3 -3
- package/src/internal/input/gate.ts +21 -18
- package/src/internal/input/guard.inpage.ts +25 -58
- package/src/internal/input/guard.ts +11 -20
- package/src/internal/input/keyboard.ts +12 -3
- package/src/internal/input/perform.ts +78 -60
- package/src/internal/input/pointer.ts +4 -2
- package/src/internal/input/settle.ts +7 -5
- package/src/internal/input/targets.inpage.ts +1 -1
- package/src/internal/input/targets.ts +4 -9
- package/src/internal/page/bridge.ts +209 -113
- package/src/internal/page/context.ts +12 -59
- package/src/internal/page/dialogs.ts +58 -0
- package/src/internal/page/lane.ts +14 -15
- package/src/internal/page/navigation.ts +50 -42
- package/src/internal/page/openings.ts +11 -5
- package/src/internal/page/page.ts +44 -81
- package/src/internal/page/port.ts +125 -0
- package/src/internal/{input → page}/replies.ts +1 -1
- package/src/internal/page/request-owner.ts +269 -0
- package/src/internal/page/requests.ts +357 -0
- package/src/internal/page/scripts.ts +124 -0
- package/src/internal/pictures/capture.ts +255 -332
- package/src/internal/pictures/dimensions.ts +162 -0
- package/src/internal/pictures/frame.ts +68 -0
- package/src/internal/pictures/pictures.ts +57 -23
- package/src/internal/pictures/quiescence.ts +1 -1
- package/src/internal/pictures/state.ts +26 -0
- package/src/internal/pictures/transport.ts +21 -4
- package/src/internal/reading/controls.inpage.ts +5 -70
- package/src/internal/reading/expect.inpage.ts +13 -17
- package/src/internal/reading/names.inpage.ts +89 -45
- package/src/internal/reading/outline.inpage.ts +6 -7
- package/src/internal/reading/reading.ts +144 -176
- package/src/internal/reading/ready.inpage.ts +6 -17
- package/src/internal/reading/ready.ts +13 -135
- package/src/internal/reading/subjects.inpage.ts +83 -43
- package/src/internal/reading/walk.inpage.ts +33 -13
- package/src/internal/timeline/changes.ts +55 -6
- package/src/internal/timeline/events.ts +15 -5
- package/src/internal/timeline/history.inpage.ts +1 -1
- package/src/internal/timeline/record.inpage.ts +4 -1
- package/src/internal/timeline/window.ts +2 -1
- package/src/{Moment.ts → moment/Moment.ts} +13 -31
- package/src/{internal/timeline → moment}/words.ts +2 -2
- package/src/{internal/reading → plan}/choose.ts +3 -3
- package/src/plan/data.ts +117 -0
- package/src/plan/execute.ts +411 -0
- package/src/plan/index.ts +36 -0
- package/src/plan/record.ts +71 -0
- package/src/plan/targets.ts +71 -0
- package/src/{Policy.ts → policy/Policy.ts} +13 -10
- package/src/{Motion.ts → presentation/Motion.ts} +12 -46
- package/src/presentation/Presentation.ts +176 -0
- package/src/{Stage.ts → presentation/Stage.ts} +147 -112
- package/src/presentation/feed.ts +21 -0
- package/src/{Cdp.ts → providers/Cdp.ts} +2 -2
- package/src/{Chromium.ts → providers/Chromium.ts} +7 -10
- package/src/providers/Released.ts +13 -0
- package/src/{internal/cdp.ts → providers/connection.ts} +2 -2
- package/src/{internal/pictures/motion.ts → stillness/Pixels.ts} +1 -1
- package/src/stillness/Stillness.ts +166 -0
- package/src/supervisor/Supervisor.ts +170 -0
- package/src/supervisor/contract.ts +105 -0
- package/src/supervisor/lifecycle.ts +272 -0
- package/src/supervisor/runtime.ts +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 +2 -2
- package/dist/Browser-CxXUjxOp.mjs +0 -619
- package/dist/Browser-CxXUjxOp.mjs.map +0 -1
- package/dist/Cdp-CzCRnMlM.d.mts +0 -10
- package/dist/Cdp.d.mts +0 -11
- package/dist/Cdp.mjs.map +0 -1
- package/dist/Change-DNvztNLu.mjs +0 -138
- package/dist/Change-DNvztNLu.mjs.map +0 -1
- package/dist/Chromium.mjs.map +0 -1
- package/dist/Expect-u3P_ENLX.d.mts +0 -62
- package/dist/Expect.d.mts +0 -2
- package/dist/Expect.mjs +0 -114
- package/dist/Expect.mjs.map +0 -1
- package/dist/Moment.d.mts +0 -2
- package/dist/Moment.mjs.map +0 -1
- package/dist/Motion.d.mts +0 -2
- package/dist/Motion.mjs.map +0 -1
- package/dist/Page-BP02bmNv.mjs +0 -264
- package/dist/Page-BP02bmNv.mjs.map +0 -1
- package/dist/Plan-BG1WifW2.mjs.map +0 -1
- package/dist/Plan.d.mts +0 -2
- package/dist/Plan.mjs +0 -2
- package/dist/Policy.d.mts +0 -2
- package/dist/Policy.mjs.map +0 -1
- package/dist/Presentation-DxVikn9_.d.mts +0 -48
- package/dist/Presentation.d.mts +0 -2
- package/dist/Presentation.mjs +0 -118
- package/dist/Presentation.mjs.map +0 -1
- package/dist/Stage.d.mts +0 -2
- package/dist/Stage.mjs.map +0 -1
- package/dist/Supervisor-2mPjIYYs.mjs +0 -676
- package/dist/Supervisor-2mPjIYYs.mjs.map +0 -1
- package/dist/Supervisor-CfRxbaso.d.mts +0 -317
- package/dist/Supervisor.d.mts +0 -2
- package/dist/Supervisor.mjs +0 -2
- package/dist/cdp-BMpYMWYe.mjs.map +0 -1
- package/dist/context-EGhOqjNN.mjs +0 -335
- package/dist/context-EGhOqjNN.mjs.map +0 -1
- package/dist/page-PTM8m5wC.mjs +0 -4057
- package/dist/page-PTM8m5wC.mjs.map +0 -1
- package/dist/url-Bsp2y55M.mjs +0 -264
- package/dist/url-Bsp2y55M.mjs.map +0 -1
- package/dist/workerd/index.d.mts +0 -16
- package/dist/workerd/index.mjs +0 -17
- package/src/Expect.ts +0 -180
- package/src/Plan.ts +0 -674
- package/src/Presentation.ts +0 -196
- package/src/Supervisor.ts +0 -632
- package/src/internal/supervisor/lifecycle.ts +0 -484
- package/src/workerd/index.ts +0 -17
- /package/src/{internal/page/url.ts → Url.ts} +0 -0
- /package/src/{internal/pictures → stillness}/utilsBundle.d.ts +0 -0
|
@@ -3,206 +3,174 @@
|
|
|
3
3
|
* read takes its turn on the page and shares its work with identical reads, as `lane.ts`
|
|
4
4
|
* describes. The viewport's text as it was last read is kept, for `Page.state`.
|
|
5
5
|
*/
|
|
6
|
-
import { Duration, Effect,
|
|
6
|
+
import { Duration, Effect, Schedule, Schema } from "effect";
|
|
7
7
|
|
|
8
|
-
import { StaleRef
|
|
9
|
-
import {
|
|
8
|
+
import { StaleRef } from "../../BrowserError.ts";
|
|
9
|
+
import { request as askedOf, type FindRequest } from "../../Matching.ts";
|
|
10
|
+
import { type FindQuery, Found, Text, type TextOptions } from "../../Page.ts";
|
|
10
11
|
import { Snapshot, type SnapshotOptions } from "../../Snapshot.ts";
|
|
12
|
+
import * as Url from "../../Url.ts";
|
|
11
13
|
import { type Bridge, scriptCall } from "../page/bridge.ts";
|
|
12
14
|
import { contextGone, decodeWith, failWith, type PageContext, refuse } from "../page/context.ts";
|
|
13
|
-
import * as Url from "../page/url.ts";
|
|
14
|
-
import { type ConditionRequest, ConditionResultSchema } from "./controls.inpage.ts";
|
|
15
15
|
import type { Want } from "./expect.inpage.ts";
|
|
16
|
-
import type { FindRequest, Wanted } from "./match.inpage.ts";
|
|
17
16
|
import { type SnapshotRequest, SnapshotResultSchema } from "./outline.inpage.ts";
|
|
18
17
|
import { type TextRequest, TextResultSchema } from "./text.inpage.ts";
|
|
19
18
|
|
|
20
|
-
// What `find` reads back
|
|
21
|
-
const FindResults = Schema.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const counted = (next: number) => Ref.update(nextRef, (current) => Math.max(current, next));
|
|
49
|
-
const snapshots = lane.shared<Snapshot>("snapshot", true);
|
|
50
|
-
const finds = lane.shared<ReadonlyArray<Found>>("find", true);
|
|
51
|
-
const texts = lane.shared<Text>("text", true);
|
|
52
|
-
let viewed: Text | undefined;
|
|
53
|
-
|
|
54
|
-
const snapshot = (snapshotOptions: SnapshotOptions = {}) => {
|
|
55
|
-
const asked = {
|
|
56
|
-
full: snapshotOptions.full ?? false,
|
|
57
|
-
query: snapshotOptions.query ?? null,
|
|
58
|
-
within: snapshotOptions.within ?? null,
|
|
59
|
-
maxChars: snapshotOptions.maxChars ?? 12_000,
|
|
60
|
-
};
|
|
19
|
+
// What `find` reads back. The bridge envelope owns ref allocation across documents.
|
|
20
|
+
const FindResults = Schema.Union([
|
|
21
|
+
Schema.Struct({ found: Schema.Array(Found) }),
|
|
22
|
+
Schema.Struct({ invalid: Schema.String }),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const UntilResult = Schema.Union([
|
|
26
|
+
Schema.Struct({ met: Schema.Boolean, mark: Schema.String }),
|
|
27
|
+
Schema.Struct({ invalid: Schema.String }),
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
export const make = (page: PageContext, bridge: Bridge) =>
|
|
31
|
+
Effect.sync(() => {
|
|
32
|
+
const { now, span, owned, within, lane } = page;
|
|
33
|
+
const { evaluate } = bridge;
|
|
34
|
+
const snapshots = lane.shared<Snapshot>("snapshot", true);
|
|
35
|
+
const finds = lane.shared<ReadonlyArray<Found>>("find", true);
|
|
36
|
+
const texts = lane.shared<Text>("text", true);
|
|
37
|
+
let viewed: Text | undefined;
|
|
38
|
+
|
|
39
|
+
const snapshot = (snapshotOptions: SnapshotOptions = {}) => {
|
|
40
|
+
const asked = {
|
|
41
|
+
full: snapshotOptions.full ?? false,
|
|
42
|
+
query: snapshotOptions.query ?? null,
|
|
43
|
+
within: snapshotOptions.within ?? null,
|
|
44
|
+
maxChars: snapshotOptions.maxChars ?? 12_000,
|
|
45
|
+
boxes: snapshotOptions.boxes ?? false,
|
|
46
|
+
};
|
|
61
47
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
48
|
+
return snapshots(
|
|
49
|
+
JSON.stringify(asked),
|
|
50
|
+
Effect.gen(function* () {
|
|
51
|
+
const request: SnapshotRequest = asked;
|
|
66
52
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
53
|
+
const result = yield* evaluate("snapshot", scriptCall("snapshot", request)).pipe(
|
|
54
|
+
Effect.flatMap(decodeWith("snapshot", SnapshotResultSchema)),
|
|
55
|
+
);
|
|
70
56
|
|
|
71
|
-
|
|
72
|
-
|
|
57
|
+
if ("invalid" in result) return yield* refuse("snapshot", result.invalid);
|
|
58
|
+
const { text, truncated, url } = result.snapshot;
|
|
73
59
|
|
|
74
|
-
|
|
75
|
-
yield* Effect.annotateCurrentSpan({ chars: text.length, truncated });
|
|
60
|
+
yield* Effect.annotateCurrentSpan({ chars: text.length, truncated });
|
|
76
61
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
62
|
+
return new Snapshot({ ...result.snapshot, url: Url.redact(url) });
|
|
63
|
+
}).pipe(within("snapshot")),
|
|
64
|
+
).pipe(span("Page.snapshot", { full: asked.full }), owned);
|
|
65
|
+
};
|
|
81
66
|
|
|
82
|
-
|
|
83
|
-
|
|
67
|
+
const find = (query: FindQuery = {}) => {
|
|
68
|
+
const asked = askedOf(query, "viewport");
|
|
84
69
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
70
|
+
return finds(
|
|
71
|
+
JSON.stringify(asked),
|
|
72
|
+
Effect.gen(function* () {
|
|
73
|
+
const request: FindRequest = asked;
|
|
89
74
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
const result = yield* evaluate("find", scriptCall("find", request)).pipe(
|
|
76
|
+
Effect.flatMap(decodeWith("find", FindResults)),
|
|
77
|
+
);
|
|
93
78
|
|
|
94
|
-
|
|
95
|
-
yield* Effect.annotateCurrentSpan({ found: result.found.length });
|
|
96
|
-
|
|
97
|
-
return result.found;
|
|
98
|
-
}).pipe(within("find")),
|
|
99
|
-
).pipe(
|
|
100
|
-
// The query's words are the caller's, and may be anything; only its shape is traced.
|
|
101
|
-
span("Page.find", { scope: asked.scope, role: asked.role ?? "" }),
|
|
102
|
-
owned,
|
|
103
|
-
);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const text = (options: TextOptions = {}) => {
|
|
107
|
-
const scope = options.scope ?? "viewport";
|
|
108
|
-
|
|
109
|
-
const request: TextRequest = {
|
|
110
|
-
ref: scope === "viewport" ? null : scope,
|
|
111
|
-
maxChars: options.maxChars ?? 12_000,
|
|
112
|
-
unmask: options.unmask ?? false,
|
|
113
|
-
};
|
|
79
|
+
if ("invalid" in result) return yield* refuse("find", result.invalid);
|
|
114
80
|
|
|
115
|
-
|
|
116
|
-
scope !== "viewport" && !/^e\d+$/.test(scope)
|
|
117
|
-
? refuse("text", `${scope} is neither "viewport" nor a ref such as e12`)
|
|
118
|
-
: texts(
|
|
119
|
-
JSON.stringify(request),
|
|
120
|
-
Effect.gen(function* () {
|
|
121
|
-
const result = yield* evaluate("text", scriptCall("text", request)).pipe(
|
|
122
|
-
Effect.flatMap(decodeWith("text", TextResultSchema)),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
if (result === null) return yield* failWith("text", new StaleRef({ ref: scope }));
|
|
126
|
-
yield* Effect.annotateCurrentSpan({
|
|
127
|
-
chars: result.text.length,
|
|
128
|
-
truncated: result.truncated,
|
|
129
|
-
});
|
|
130
|
-
const shown = new Text({ ...result, url: Url.redact(result.url), at: now() });
|
|
131
|
-
|
|
132
|
-
if (request.ref === null) viewed = shown;
|
|
133
|
-
|
|
134
|
-
return shown;
|
|
135
|
-
}).pipe(within("text")),
|
|
136
|
-
)
|
|
137
|
-
).pipe(span("Page.text", { scope: scope === "viewport" ? "viewport" : "ref" }), owned);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// One call, which the page answers once the condition holds or at the deadline. It follows the
|
|
141
|
-
// action in flight, as a read does, but holds no later one back while it waits, and it waits on
|
|
142
|
-
// in a document that replaces the one it began in.
|
|
143
|
-
const waitFor = (condition: WaitCondition, timeout: Duration.Input = Duration.seconds(10)) => {
|
|
144
|
-
const request: ConditionRequest = {
|
|
145
|
-
selector: condition.selector ?? null,
|
|
146
|
-
text: condition.text ?? null,
|
|
147
|
-
state: condition.state ?? "visible",
|
|
148
|
-
};
|
|
81
|
+
yield* Effect.annotateCurrentSpan({ found: result.found.length });
|
|
149
82
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
Effect.flatMap(decodeWith("waitFor", ConditionResultSchema)),
|
|
156
|
-
Effect.flatMap((result) =>
|
|
157
|
-
"invalid" in result
|
|
158
|
-
? refuse("waitFor", result.invalid)
|
|
159
|
-
: result.met
|
|
160
|
-
? Effect.void
|
|
161
|
-
: unmet(),
|
|
162
|
-
),
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
return lane
|
|
166
|
-
.read("waitFor")(Effect.void)
|
|
167
|
-
.pipe(
|
|
168
|
-
Effect.andThen(Effect.retry(look, { while: contextGone })),
|
|
169
|
-
Effect.timeoutOrElse({ duration: timeout, orElse: unmet }),
|
|
170
|
-
span("Page.waitFor", { state: request.state }),
|
|
83
|
+
return result.found;
|
|
84
|
+
}).pipe(within("find")),
|
|
85
|
+
).pipe(
|
|
86
|
+
// The query's words are the caller's, and may be anything; only its shape is traced.
|
|
87
|
+
span("Page.find", { scope: asked.scope, role: asked.role ?? "" }),
|
|
171
88
|
owned,
|
|
172
89
|
);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
...askedOf(query, "document"),
|
|
183
|
-
firstRef: yield* Ref.get(nextRef),
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const text = (options: TextOptions = {}) => {
|
|
93
|
+
const scope = options.scope ?? "viewport";
|
|
94
|
+
|
|
95
|
+
const request: TextRequest = {
|
|
96
|
+
ref: scope === "viewport" ? null : scope,
|
|
97
|
+
maxChars: options.maxChars ?? 12_000,
|
|
98
|
+
unmask: options.unmask ?? false,
|
|
184
99
|
};
|
|
185
100
|
|
|
186
|
-
return
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
101
|
+
return (
|
|
102
|
+
scope !== "viewport" && !/^e\d+$/.test(scope)
|
|
103
|
+
? refuse("text", `${scope} is neither "viewport" nor a ref such as e12`)
|
|
104
|
+
: texts(
|
|
105
|
+
JSON.stringify(request),
|
|
106
|
+
Effect.gen(function* () {
|
|
107
|
+
const result = yield* evaluate("text", scriptCall("text", request)).pipe(
|
|
108
|
+
Effect.flatMap(decodeWith("text", TextResultSchema)),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (result === null) return yield* failWith("text", new StaleRef({ ref: scope }));
|
|
112
|
+
yield* Effect.annotateCurrentSpan({
|
|
113
|
+
chars: result.text.length,
|
|
114
|
+
truncated: result.truncated,
|
|
115
|
+
});
|
|
116
|
+
const shown = new Text({ ...result, url: Url.redact(result.url), at: now() });
|
|
117
|
+
|
|
118
|
+
if (request.ref === null) viewed = shown;
|
|
119
|
+
|
|
120
|
+
return shown;
|
|
121
|
+
}).pipe(within("text")),
|
|
122
|
+
)
|
|
123
|
+
).pipe(span("Page.text", { scope: scope === "viewport" ? "viewport" : "ref" }), owned);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// One call, which the page answers once `want` holds of what `query` matches, the whole document
|
|
127
|
+
// unless it says otherwise, or at the deadline, with the mark of what matched then. It follows
|
|
128
|
+
// the action in flight, and the page has the action timeout past the deadline
|
|
129
|
+
// to answer.
|
|
130
|
+
const until = (query: FindQuery, want: Want, millis: number) => {
|
|
131
|
+
if (!Number.isFinite(millis) || millis < 0)
|
|
132
|
+
return refuse("until", "the wait duration must be finite and nonnegative");
|
|
133
|
+
|
|
134
|
+
const look = Effect.gen(function* () {
|
|
135
|
+
const deadline = now() + millis;
|
|
136
|
+
const request: FindRequest = askedOf(query, "document");
|
|
137
|
+
|
|
138
|
+
return yield* Effect.suspend(() =>
|
|
139
|
+
evaluate("expect", scriptCall("until", request, want, Math.max(0, deadline - now()))),
|
|
140
|
+
).pipe(
|
|
141
|
+
Effect.flatMap(decodeWith("expect", UntilResult)),
|
|
142
|
+
Effect.filterOrElse(
|
|
143
|
+
(result) => "met" in result,
|
|
144
|
+
(result) => refuse("expect", result.invalid),
|
|
145
|
+
),
|
|
146
|
+
Effect.retry({
|
|
147
|
+
while: (error) => contextGone(error) && now() < deadline,
|
|
148
|
+
schedule: Schedule.spaced("10 millis"),
|
|
149
|
+
}),
|
|
150
|
+
// No stable document answered by this deadline. An unmet verdict carries no sampled
|
|
151
|
+
// mark; a zero-window baseline still fails rather than inventing comparison evidence.
|
|
152
|
+
Effect.catchIf(
|
|
153
|
+
(error) => millis > 0 && contextGone(error) && now() >= deadline,
|
|
154
|
+
() => Effect.succeed({ met: false, mark: "" }),
|
|
155
|
+
),
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return lane
|
|
160
|
+
.read("expect")(Effect.void)
|
|
161
|
+
.pipe(
|
|
162
|
+
Effect.andThen(look),
|
|
163
|
+
within("expect", Duration.sum(Duration.millis(millis), page.settings.actionTimeout)),
|
|
164
|
+
span("Page.expect", { want: typeof want === "string" ? want : "other" }),
|
|
165
|
+
owned,
|
|
166
|
+
);
|
|
167
|
+
};
|
|
200
168
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
169
|
+
/** The viewport's text as it was last read, if after `since`, as a document began. */
|
|
170
|
+
const viewedSince = (since: number) =>
|
|
171
|
+
viewed !== undefined && viewed.at > since ? viewed : undefined;
|
|
204
172
|
|
|
205
|
-
|
|
206
|
-
});
|
|
173
|
+
return { snapshot, find, text, until, viewedSince };
|
|
174
|
+
});
|
|
207
175
|
|
|
208
176
|
export type Reading = Effect.Success<ReturnType<typeof make>>;
|
|
@@ -6,14 +6,11 @@
|
|
|
6
6
|
* frame. So a canvas mounted blank, or a spinner alone, is still loading. A screen that only says
|
|
7
7
|
* "Loading…" in words reads as ready, and a WebGL canvas drawn once, without keeping its drawing,
|
|
8
8
|
* reads as blank. Asked for a quiet spell, where the page's changes are recorded, nothing in view
|
|
9
|
-
* may have changed for that long either.
|
|
10
|
-
* observes a full quiet interval from its first check in each document. After input, it waits a
|
|
11
|
-
* task and a frame. See `names.inpage.ts` for what a page-side part may use.
|
|
9
|
+
* may have changed for that long either. After input, it waits a task and a frame. See `names.inpage.ts` for what a page-side part may use.
|
|
12
10
|
*/
|
|
13
11
|
import { Schema } from "effect";
|
|
14
12
|
|
|
15
13
|
import type { History } from "../timeline/history.inpage.ts";
|
|
16
|
-
import type { Recorder } from "../timeline/record.inpage.ts";
|
|
17
14
|
import type { Texts } from "./text.inpage.ts";
|
|
18
15
|
import type { Walk } from "./walk.inpage.ts";
|
|
19
16
|
|
|
@@ -33,7 +30,7 @@ export const ReadinessSchema = Schema.Array(
|
|
|
33
30
|
|
|
34
31
|
export type Readiness = typeof ReadinessSchema.Type;
|
|
35
32
|
|
|
36
|
-
export const ready = (walked: Walk, texts: Texts, kept: History
|
|
33
|
+
export const ready = (walked: Walk, texts: Texts, kept: History) => {
|
|
37
34
|
const { inView, visible } = walked;
|
|
38
35
|
// A canvas is read through a small copy: reading it directly would give it a context of ours.
|
|
39
36
|
let copy: OffscreenCanvasRenderingContext2D | null | undefined;
|
|
@@ -88,7 +85,7 @@ export const ready = (walked: Walk, texts: Texts, kept: History, recorder: Recor
|
|
|
88
85
|
};
|
|
89
86
|
|
|
90
87
|
// In a frame, before it is drawn: a canvas drawn every frame still holds its drawing then.
|
|
91
|
-
const check = (quietMillis: number
|
|
88
|
+
const check = (quietMillis: number): Promise<Readiness> =>
|
|
92
89
|
painted().then((paints) => {
|
|
93
90
|
const waiting: Array<Readiness[number]> = [];
|
|
94
91
|
|
|
@@ -115,10 +112,7 @@ export const ready = (walked: Walk, texts: Texts, kept: History, recorder: Recor
|
|
|
115
112
|
if (document.fonts.status !== "loaded") waiting.push("fonts");
|
|
116
113
|
if (showing(document.querySelectorAll("[aria-busy=true]")).length > 0) waiting.push("busy");
|
|
117
114
|
if (!content()) waiting.push("content");
|
|
118
|
-
if (
|
|
119
|
-
Math.max(observed, kept.changing()) >
|
|
120
|
-
performance.timeOrigin + performance.now() - quietMillis
|
|
121
|
-
)
|
|
115
|
+
if (kept.changing() > performance.timeOrigin + performance.now() - quietMillis)
|
|
122
116
|
waiting.push("changing");
|
|
123
117
|
|
|
124
118
|
return waiting;
|
|
@@ -128,16 +122,11 @@ export const ready = (walked: Walk, texts: Texts, kept: History, recorder: Recor
|
|
|
128
122
|
* Check until the page is ready, or for `millis`, and say what it is still waiting for; with
|
|
129
123
|
* `quietMillis`, until nothing the record saw in view has changed for that long, too.
|
|
130
124
|
*/
|
|
131
|
-
const wait = async (millis: number, quietMillis = 0
|
|
125
|
+
const wait = async (millis: number, quietMillis = 0): Promise<Readiness> => {
|
|
132
126
|
const until = performance.now() + millis;
|
|
133
|
-
let observed = contentOnly ? undefined : Number.NEGATIVE_INFINITY;
|
|
134
127
|
|
|
135
128
|
for (;;) {
|
|
136
|
-
|
|
137
|
-
recorder.start();
|
|
138
|
-
if (kept.begun()) observed ??= performance.timeOrigin + performance.now();
|
|
139
|
-
}
|
|
140
|
-
const waiting = await check(quietMillis, observed ?? Number.POSITIVE_INFINITY);
|
|
129
|
+
const waiting = await check(quietMillis);
|
|
141
130
|
|
|
142
131
|
if (waiting.length === 0 || performance.now() >= until) return waiting;
|
|
143
132
|
const { promise, resolve } = Promise.withResolvers<void>();
|
|
@@ -1,41 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
* that checks in the page until nothing is left to wait for, or the time is up. A caller that also
|
|
4
|
-
* needs the screen still, such as after spinning a canvas game's reels, gives a quiet spell, and
|
|
5
|
-
* the capture must then show no frame that long. A capture's silence cannot prove the last paint
|
|
6
|
-
* arrived: a frame can be held on its way by a stalled connection, and Chromium sends frames only
|
|
7
|
-
* while few acknowledgements are unanswered. So the spell counts only while every acknowledgement
|
|
8
|
-
* is answered, and it ends with the page's evidence once more and, where the capture runs on a
|
|
9
|
-
* connection of its own, a round trip there: each answer comes behind every frame sent before it on
|
|
10
|
-
* its connection, and a frame that arrives first starts the spell again. Where the page's changes
|
|
11
|
-
* are recorded, its evidence includes them: nothing in view may have changed for the spell, which a
|
|
12
|
-
* DOM page's changes show better than its paint, and no stall on the way can hide. Content
|
|
13
|
-
* stillness starts that record itself and ignores capture silence. Foreground stillness lets
|
|
14
|
-
* frames keep coming but compares them, so that only motion outside what was moving before the
|
|
15
|
-
* page's latest input counts; it still waits out unanswered acknowledgements while no frame
|
|
16
|
-
* comes, and its last look follows the round trip too. Each new document starts a
|
|
17
|
-
* new observation, while retries of destroyed script contexts share the caller's deadline.
|
|
18
|
-
*/
|
|
19
|
-
import { Duration, Effect, Option, Schedule, Stream } from "effect";
|
|
1
|
+
/** Document readiness and content quiet, independent of screen-capture features. */
|
|
2
|
+
import { Duration, Effect, Schedule } from "effect";
|
|
20
3
|
|
|
21
|
-
import {
|
|
22
|
-
import type { Frame } from "../../Frame.ts";
|
|
4
|
+
import { Timeout, failWith, refuse } from "../../BrowserError.ts";
|
|
23
5
|
import type { ReadyOptions } from "../../Page.ts";
|
|
24
6
|
import { type Bridge, scriptCall } from "../page/bridge.ts";
|
|
25
|
-
import {
|
|
26
|
-
contextGone,
|
|
27
|
-
decodeWith,
|
|
28
|
-
failWith,
|
|
29
|
-
type PageContext,
|
|
30
|
-
undispatched,
|
|
31
|
-
} from "../page/context.ts";
|
|
32
|
-
import type * as Capture from "../pictures/capture.ts";
|
|
33
|
-
import * as Motion from "../pictures/motion.ts";
|
|
7
|
+
import { contextGone, decodeWith, type PageContext } from "../page/context.ts";
|
|
34
8
|
import { ReadinessSchema } from "./ready.inpage.ts";
|
|
35
9
|
|
|
36
10
|
export const make =
|
|
37
|
-
(page: PageContext, bridge: Bridge
|
|
11
|
+
(page: PageContext, bridge: Bridge) =>
|
|
38
12
|
(options: ReadyOptions = {}) => {
|
|
13
|
+
const quietMillis = options.quietMillis ?? 0;
|
|
14
|
+
|
|
15
|
+
if (!Number.isFinite(quietMillis) || quietMillis < 0)
|
|
16
|
+
return refuse("ready", "quietMillis must be finite and nonnegative");
|
|
39
17
|
const timeout = options.timeout ?? Duration.seconds(15);
|
|
40
18
|
|
|
41
19
|
// The page's own evidence, checked in the page until nothing is left or `until` has come.
|
|
@@ -43,12 +21,7 @@ export const make =
|
|
|
43
21
|
Effect.suspend(() =>
|
|
44
22
|
bridge.evaluate(
|
|
45
23
|
"ready",
|
|
46
|
-
scriptCall(
|
|
47
|
-
"ready",
|
|
48
|
-
Math.max(0, Math.round(until - page.now())),
|
|
49
|
-
options.quietMillis ?? 0,
|
|
50
|
-
options.still === "content",
|
|
51
|
-
),
|
|
24
|
+
scriptCall("ready", Math.max(0, Math.round(until - page.now())), quietMillis),
|
|
52
25
|
),
|
|
53
26
|
).pipe(
|
|
54
27
|
Effect.retry({ while: contextGone, schedule: Schedule.spaced(Duration.millis(10)) }),
|
|
@@ -60,108 +33,13 @@ export const make =
|
|
|
60
33
|
),
|
|
61
34
|
);
|
|
62
35
|
|
|
63
|
-
// A capture the wait starts sends its first frame late, over half a second from a hosted
|
|
64
|
-
// browser, so the spell counts from that frame (#202); Chrome sends one as a capture starts,
|
|
65
|
-
// even of a still page.
|
|
66
|
-
const quiet = (millis: number, until: number) =>
|
|
67
|
-
Effect.gen(function* () {
|
|
68
|
-
const running = yield* capture.active;
|
|
69
|
-
const foreground = options.still === "foreground";
|
|
70
|
-
let counts = yield* capture.stats();
|
|
71
|
-
let stirred = running ? page.now() : Number.POSITIVE_INFINITY;
|
|
72
|
-
let reference: Motion.Picture | undefined;
|
|
73
|
-
|
|
74
|
-
const decoded = (frame: Frame) =>
|
|
75
|
-
Effect.try({
|
|
76
|
-
try: () => Motion.picture(frame),
|
|
77
|
-
catch: (error) =>
|
|
78
|
-
undispatched("ready", new Failed({ detail: `no picture: ${String(error)}` })),
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// The background: what moved in up to eight frames of the document's 1.5 s before its
|
|
82
|
-
// latest input, as far back as the capture keeps them.
|
|
83
|
-
const { inputAt } = page.activity;
|
|
84
|
-
const document = Option.getOrUndefined(yield* capture.latest)?.document;
|
|
85
|
-
|
|
86
|
-
const before = (foreground ? yield* capture.recent : []).filter(
|
|
87
|
-
(frame) =>
|
|
88
|
-
frame.hostTime < inputAt &&
|
|
89
|
-
frame.hostTime >= inputAt - 1500 &&
|
|
90
|
-
frame.document === document,
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
const sampled = before.filter((_, index) => index % Math.ceil(before.length / 8) === 0);
|
|
94
|
-
const mask = Motion.background(yield* Effect.forEach(sampled, decoded));
|
|
95
|
-
|
|
96
|
-
// How long the screen has been still: since a frame, or an unanswered acknowledgement. In
|
|
97
|
-
// the foreground, since a frame moved outside the background, or acknowledgements went
|
|
98
|
-
// unanswered with no frame coming.
|
|
99
|
-
const look = Effect.gen(function* () {
|
|
100
|
-
const stats = yield* capture.stats();
|
|
101
|
-
const latest = Option.getOrUndefined(yield* capture.latest);
|
|
102
|
-
const arrived = stats.received !== counts.received;
|
|
103
|
-
const unseen = stats.accepted - counts.accepted;
|
|
104
|
-
|
|
105
|
-
counts = stats;
|
|
106
|
-
if (latest === undefined || !capture.current(latest)) stirred = page.now();
|
|
107
|
-
else if (!foreground ? arrived || stats.ackBacklog > 0 : !arrived && stats.ackBacklog > 0)
|
|
108
|
-
stirred = page.now();
|
|
109
|
-
else if (foreground && (unseen > 0 || reference === undefined)) {
|
|
110
|
-
// A move and its return between looks both count. Bound decoding; any frames lost
|
|
111
|
-
// from history, or beyond this batch, deny a quiet spell rather than hiding motion.
|
|
112
|
-
const frames = (yield* capture.recent).slice(-Math.max(1, Math.min(8, unseen)));
|
|
113
|
-
|
|
114
|
-
if (unseen > frames.length) stirred = page.now();
|
|
115
|
-
for (const frame of frames) {
|
|
116
|
-
const seen = yield* decoded(frame);
|
|
117
|
-
|
|
118
|
-
if (reference === undefined || Motion.stirs(reference, seen, mask)) {
|
|
119
|
-
reference = seen;
|
|
120
|
-
stirred = page.now();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return page.now() - stirred;
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// Decode at a fixed cadence: adding a delay after a full batch lets its backlog grow.
|
|
129
|
-
const spell = Effect.repeat(look, {
|
|
130
|
-
schedule: Schedule.fixed(Duration.millis(foreground ? 100 : 25)),
|
|
131
|
-
until: (still) => still >= millis,
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
const capturing = running
|
|
135
|
-
? Effect.never
|
|
136
|
-
: capture.stream().pipe(Stream.runDrain, Effect.andThen(Effect.never));
|
|
137
|
-
|
|
138
|
-
const still = Effect.gen(function* () {
|
|
139
|
-
for (;;) {
|
|
140
|
-
yield* spell;
|
|
141
|
-
const before = counts.received;
|
|
142
|
-
|
|
143
|
-
yield* Effect.all([settled(until), capture.sync], { concurrency: 2, discard: true });
|
|
144
|
-
if ((yield* look) >= millis && (foreground || counts.received === before)) return;
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
return yield* Effect.raceFirst(capturing, still);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
// The wait follows the action in flight, as a read does, but holds no later one back while it
|
|
152
|
-
// watches the page settle, which can take its whole timeout.
|
|
153
36
|
return page.lane
|
|
154
37
|
.read("ready")(Effect.void)
|
|
155
38
|
.pipe(
|
|
156
39
|
Effect.andThen(
|
|
157
|
-
Effect.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (options.still === "content") yield* bridge.registerRecorder("ready");
|
|
161
|
-
yield* settled(until);
|
|
162
|
-
if (options.quietMillis !== undefined && options.still !== "content")
|
|
163
|
-
yield* quiet(options.quietMillis, until);
|
|
164
|
-
}).pipe(page.within("ready", timeout)),
|
|
40
|
+
Effect.suspend(() => settled(page.now() + Duration.toMillis(timeout))).pipe(
|
|
41
|
+
page.within("ready", timeout),
|
|
42
|
+
),
|
|
165
43
|
),
|
|
166
44
|
page.span("Page.ready"),
|
|
167
45
|
page.owned,
|