omowright 0.2.0 → 0.3.0

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.
Files changed (174) hide show
  1. package/README.md +24 -22
  2. package/TOOLS.md +6 -6
  3. package/dist/agent-tabs.d.ts +56 -0
  4. package/dist/aria-hidden.d.ts +1 -0
  5. package/dist/aside/cli-binary.d.ts +7 -0
  6. package/dist/aside/cli-contract.d.ts +9 -0
  7. package/dist/aside/errors.d.ts +8 -0
  8. package/dist/aside/line-transport.d.ts +11 -0
  9. package/dist/aside/mcp-transport.d.ts +11 -0
  10. package/dist/aside/onboard.d.ts +76 -0
  11. package/dist/aside/session-types.d.ts +68 -0
  12. package/dist/aside/session.d.ts +20 -0
  13. package/{bin/omowright-cloak.mjs → dist/bin/omowright-cloak.js} +28 -31
  14. package/dist/bridge-schemas.d.ts +326 -0
  15. package/dist/bridge-transport.d.ts +144 -0
  16. package/dist/browser-context.d.ts +4024 -0
  17. package/dist/browser-process.d.ts +10 -0
  18. package/dist/bsk/browser-signals.d.ts +23 -0
  19. package/dist/bsk/browsers.d.ts +46 -0
  20. package/dist/bsk/connect.d.ts +23 -0
  21. package/dist/bsk/daemon-info.d.ts +16 -0
  22. package/dist/bsk/external-extension.d.ts +74 -0
  23. package/dist/bsk/identify-browser.d.ts +48 -0
  24. package/dist/bsk/install-cli.d.ts +37 -0
  25. package/dist/bsk/ipc-client.d.ts +45 -0
  26. package/dist/bsk/onboard.d.ts +96 -0
  27. package/dist/bsk/reply-fields.d.ts +3 -0
  28. package/dist/bsk/screenshot.d.ts +24 -0
  29. package/dist/bsk/session.d.ts +142 -0
  30. package/dist/bsk/snapshot.d.ts +16 -0
  31. package/dist/bsk/targets.d.ts +20 -0
  32. package/dist/captcha-wait.d.ts +17 -0
  33. package/dist/captcha.d.ts +46 -0
  34. package/dist/cdp-errors.d.ts +38 -0
  35. package/dist/cdp-methods.d.ts +10 -0
  36. package/dist/cdp-protocol.d.ts +459 -0
  37. package/dist/chrome-profile.d.ts +77 -0
  38. package/dist/chrome.d.ts +130 -0
  39. package/dist/cloak-profile.d.ts +43 -0
  40. package/dist/connection.d.ts +4024 -0
  41. package/dist/console-events.d.ts +22 -0
  42. package/dist/cookies.d.ts +42 -0
  43. package/dist/core.d.ts +10810 -0
  44. package/dist/cua.d.ts +56 -0
  45. package/dist/dialog-policy.d.ts +43 -0
  46. package/dist/ego/bindings.d.ts +68 -0
  47. package/dist/ego/cdp-client.d.ts +28 -0
  48. package/dist/ego/client.d.ts +8 -0
  49. package/dist/ego/errors.d.ts +7 -0
  50. package/dist/emulate.d.ts +62 -0
  51. package/dist/engines.d.ts +59 -0
  52. package/dist/events.d.ts +93 -0
  53. package/dist/frames-snapshot.d.ts +58 -0
  54. package/dist/har.d.ts +88 -0
  55. package/dist/human-handoff.d.ts +30 -0
  56. package/{src/index.js → dist/index.d.ts} +11 -55
  57. package/dist/index.js +39262 -0
  58. package/dist/injected.d.ts +1 -0
  59. package/dist/instance-lock.d.ts +5 -0
  60. package/dist/instances.d.ts +45 -0
  61. package/dist/internal-capability.d.ts +1 -0
  62. package/dist/launch-endpoint.d.ts +34 -0
  63. package/dist/layers.d.ts +31 -0
  64. package/dist/llm.d.ts +1349 -0
  65. package/dist/lock-backend-win32-xbcm60vz.js +57 -0
  66. package/dist/lock-backend-win32.d.ts +3 -0
  67. package/dist/lock-backend.d.ts +6 -0
  68. package/dist/native-host-win32.d.ts +38 -0
  69. package/dist/network-events.d.ts +66 -0
  70. package/dist/network-snoop.d.ts +56 -0
  71. package/dist/nul-frames.d.ts +4 -0
  72. package/dist/open-shadow-query.d.ts +1 -0
  73. package/dist/owner-only.d.ts +15 -0
  74. package/dist/page-bundle.js +1587 -0
  75. package/dist/page-events.d.ts +25 -0
  76. package/dist/page-routes.d.ts +30 -0
  77. package/dist/page-setup.d.ts +55 -0
  78. package/dist/pipe.d.ts +71 -0
  79. package/dist/process-start-time.d.ts +2 -0
  80. package/dist/read-property.d.ts +2 -0
  81. package/dist/routes.d.ts +60 -0
  82. package/dist/running-browser.d.ts +39 -0
  83. package/dist/scroll-collect.d.ts +36 -0
  84. package/dist/serial-emitter.d.ts +5 -0
  85. package/dist/shared-connections.d.ts +11 -0
  86. package/dist/snapshot-diff.d.ts +57 -0
  87. package/dist/text-matching.d.ts +21 -0
  88. package/dist/trace.d.ts +59 -0
  89. package/dist/url-match.d.ts +7 -0
  90. package/dist/viewport.d.ts +26 -0
  91. package/dist/ws.d.ts +62 -0
  92. package/package.json +47 -26
  93. package/presets/agent-events/SKILL.md +1 -1
  94. package/presets/captcha/SKILL.md +1 -3
  95. package/presets/chrome/SKILL.md +2 -2
  96. package/presets/cloak-bridge/SKILL.md +11 -11
  97. package/presets/network/SKILL.md +15 -13
  98. package/presets/visual-browse/SKILL.md +14 -10
  99. package/skills/omowright/SKILL.md +77 -47
  100. package/skills/omowright/references/aside.md +50 -0
  101. package/skills/omowright/references/browserskill.md +29 -32
  102. package/skills/omowright/references/ego.md +24 -0
  103. package/skills/omowright/references/eval-kernel.md +44 -23
  104. package/skills/omowright/references/frames-layers-human.md +16 -7
  105. package/skills/omowright/references/quickstart.md +3 -3
  106. package/skills/omowright/references/stealth.md +7 -7
  107. package/src/agent-tabs.js +0 -179
  108. package/src/aria-hidden.js +0 -47
  109. package/src/bridge-schemas.js +0 -44
  110. package/src/bridge-transport.js +0 -83
  111. package/src/browser-context.js +0 -105
  112. package/src/browser-process.js +0 -127
  113. package/src/bsk/browser-signals.js +0 -90
  114. package/src/bsk/browsers.js +0 -114
  115. package/src/bsk/connect.js +0 -75
  116. package/src/bsk/daemon-info.js +0 -100
  117. package/src/bsk/external-extension.js +0 -110
  118. package/src/bsk/identify-browser.js +0 -88
  119. package/src/bsk/install-cli.js +0 -81
  120. package/src/bsk/ipc-client.js +0 -236
  121. package/src/bsk/onboard.js +0 -140
  122. package/src/bsk/screenshot.js +0 -49
  123. package/src/bsk/session.js +0 -131
  124. package/src/bsk/snapshot.js +0 -56
  125. package/src/bsk/targets.js +0 -25
  126. package/src/captcha-wait.js +0 -79
  127. package/src/captcha.js +0 -142
  128. package/src/cdp-errors.js +0 -23
  129. package/src/cdp-methods.js +0 -69
  130. package/src/chrome-profile.js +0 -176
  131. package/src/chrome.js +0 -194
  132. package/src/cloak-profile.js +0 -266
  133. package/src/connection.js +0 -234
  134. package/src/console-events.js +0 -12
  135. package/src/cookies.js +0 -39
  136. package/src/core.js +0 -1702
  137. package/src/cua.js +0 -74
  138. package/src/dialog-policy.js +0 -80
  139. package/src/emulate.js +0 -127
  140. package/src/events.js +0 -111
  141. package/src/frames-snapshot.js +0 -138
  142. package/src/har.js +0 -103
  143. package/src/human-handoff.js +0 -124
  144. package/src/injected.js +0 -3
  145. package/src/instance-lock.js +0 -74
  146. package/src/instances.js +0 -490
  147. package/src/internal-capability.js +0 -1
  148. package/src/launch-endpoint.js +0 -185
  149. package/src/layers.js +0 -138
  150. package/src/llm.js +0 -201
  151. package/src/lock-backend-win32.js +0 -54
  152. package/src/lock-backend.js +0 -81
  153. package/src/native-host-win32.js +0 -201
  154. package/src/network-events.js +0 -223
  155. package/src/network-snoop.js +0 -229
  156. package/src/nul-frames.js +0 -28
  157. package/src/open-shadow-query.js +0 -101
  158. package/src/owner-only.js +0 -196
  159. package/src/page-bundle.js +0 -1478
  160. package/src/page-events.js +0 -45
  161. package/src/page-routes.js +0 -94
  162. package/src/page-setup.js +0 -239
  163. package/src/pipe.js +0 -418
  164. package/src/process-start-time.js +0 -64
  165. package/src/routes.js +0 -256
  166. package/src/running-browser.js +0 -85
  167. package/src/scroll-collect.js +0 -73
  168. package/src/serial-emitter.js +0 -17
  169. package/src/shared-connections.js +0 -285
  170. package/src/snapshot-diff.js +0 -75
  171. package/src/text-matching.js +0 -101
  172. package/src/trace.js +0 -183
  173. package/src/url-match.js +0 -148
  174. package/src/viewport.js +0 -12
package/src/routes.js DELETED
@@ -1,256 +0,0 @@
1
- /**
2
- * Request interception via the CDP Fetch domain.
3
- *
4
- * Enabling Fetch changes request timing and blocking patterns that bot
5
- * defenses can fingerprint. Keep interception off by default and scope
6
- * patterns tightly.
7
- */
8
-
9
- const controllers = new WeakMap();
10
-
11
- function globToRegExp(glob) {
12
- let source = "";
13
- for (const char of glob) {
14
- if (char === "*") source += ".*";
15
- else if (char === "?") source += ".";
16
- else if ("\\^$+{}[]()|.".includes(char)) source += `\\${char}`;
17
- else source += char;
18
- }
19
- return new RegExp(`^${source}$`);
20
- }
21
-
22
- function hasGlobChars(value) {
23
- return value.includes("*") || value.includes("?");
24
- }
25
-
26
- function matches(match, request) {
27
- if (typeof match === "function") {
28
- return Boolean(match({
29
- url: request.url,
30
- method: request.method,
31
- resourceType: request.resourceType,
32
- headers: request.headers,
33
- }));
34
- }
35
- if (match instanceof RegExp) return match.test(request.url);
36
- if (typeof match === "string") {
37
- if (hasGlobChars(match)) return globToRegExp(match).test(request.url);
38
- return request.url.includes(match);
39
- }
40
- return false;
41
- }
42
-
43
- function sameMatch(left, right) {
44
- if (left === right) return true;
45
- if (left instanceof RegExp && right instanceof RegExp) return left.source === right.source && left.flags === right.flags;
46
- return false;
47
- }
48
-
49
- function toHeaderEntries(headers) {
50
- if (!headers) return [];
51
- if (Array.isArray(headers)) {
52
- return headers.map(header => ({ name: String(header.name), value: String(header.value ?? "") }));
53
- }
54
- return Object.entries(headers).map(([name, value]) => ({ name, value: String(value ?? "") }));
55
- }
56
-
57
- function encodeBody(body) {
58
- if (body == null) return "";
59
- if (Buffer.isBuffer(body)) return body.toString("base64");
60
- if (body instanceof Uint8Array) return Buffer.from(body).toString("base64");
61
- return Buffer.from(String(body)).toString("base64");
62
- }
63
-
64
- function buildContinue(requestId, { url, method, headers, postData } = {}) {
65
- const params = { requestId };
66
- if (url !== undefined) params.url = url;
67
- if (method !== undefined) params.method = method;
68
- if (headers !== undefined) params.headers = toHeaderEntries(headers);
69
- if (postData !== undefined) params.postData = encodeBody(postData);
70
- return params;
71
- }
72
-
73
- function buildFulfill(requestId, { status = 200, headers = {}, contentType, body = "" } = {}) {
74
- const responseHeaders = toHeaderEntries(headers);
75
- if (contentType != null && String(contentType).length > 0) {
76
- const hasType = responseHeaders.some(header => header.name.toLowerCase() === "content-type");
77
- if (!hasType) responseHeaders.push({ name: "content-type", value: String(contentType) });
78
- }
79
- return {
80
- requestId,
81
- responseCode: status,
82
- responseHeaders,
83
- body: encodeBody(body),
84
- };
85
- }
86
-
87
- export function createRoutes(page) {
88
- if (!page?.cdp) throw new TypeError("createRoutes requires a page with cdp");
89
- if (controllers.has(page)) return controllers.get(page);
90
-
91
- const entries = [];
92
- const warned = new WeakSet();
93
- const settledIds = new Set();
94
- let enabled = false;
95
- let sessionId;
96
- let unsubscribe = null;
97
- let lifecycle = Promise.resolve();
98
- let activeRequests = 0;
99
-
100
- function warnOnce(handler, error) {
101
- if (typeof handler === "function") {
102
- if (warned.has(handler)) return;
103
- warned.add(handler);
104
- }
105
- if (error) console.warn("[routes] route handler failed; continuing request", error);
106
- else console.warn("[routes] route handler did not settle the request; continuing");
107
- }
108
-
109
- async function handlePaused(params, meta) {
110
- if (!sessionId || meta?.sessionId !== sessionId) return;
111
- const requestId = params?.requestId;
112
- if (!requestId || settledIds.has(requestId)) return;
113
- settledIds.add(requestId);
114
- activeRequests += 1;
115
-
116
- const request = {
117
- url: params.request?.url ?? "",
118
- method: params.request?.method ?? "GET",
119
- headers: params.request?.headers ?? {},
120
- postData: params.request?.postData,
121
- resourceType: params.resourceType,
122
- };
123
-
124
- let settled = false;
125
- const settle = (method, cdpParams) => {
126
- if (settled) return Promise.resolve();
127
- settled = true;
128
- settledIds.add(requestId);
129
- return page.cdp.send(method, cdpParams, sessionId);
130
- };
131
-
132
- const candidates = entries.slice();
133
- let index = 0;
134
- async function dispatch() {
135
- while (index < candidates.length) {
136
- const entry = candidates[index++];
137
- if (!entries.includes(entry) || !matches(entry.match, request)) continue;
138
- if (--entry.remaining === 0) entries.splice(entries.indexOf(entry), 1);
139
- let acted = false;
140
- let fallbackPromise;
141
- const route = {
142
- request,
143
- continue(overrides = {}) {
144
- acted = true;
145
- return settle("Fetch.continueRequest", buildContinue(requestId, overrides));
146
- },
147
- fulfill(options = {}) {
148
- acted = true;
149
- return settle("Fetch.fulfillRequest", buildFulfill(requestId, options));
150
- },
151
- abort(errorReason = "Failed") {
152
- acted = true;
153
- return settle("Fetch.failRequest", { requestId, errorReason });
154
- },
155
- fallback() {
156
- if (acted || settled) return Promise.resolve();
157
- acted = true;
158
- fallbackPromise = dispatch();
159
- return fallbackPromise;
160
- },
161
- };
162
- try {
163
- await entry.handler(route);
164
- await fallbackPromise;
165
- } catch (error) {
166
- warnOnce(entry.handler, error);
167
- }
168
- if (!acted && !settled) warnOnce(entry.handler);
169
- break;
170
- }
171
- if (!settled) await settle("Fetch.continueRequest", { requestId });
172
- }
173
- try {
174
- await dispatch();
175
- } catch (error) {
176
- warnOnce(undefined, error);
177
- if (!settled) await settle("Fetch.continueRequest", { requestId });
178
- } finally {
179
- activeRequests -= 1;
180
- if (entries.length === 0 && activeRequests === 0) await syncFetch();
181
- }
182
- }
183
-
184
- function onPaused(params, meta) {
185
- void handlePaused(params, meta).catch(error => {
186
- console.warn("[routes] requestPaused handling failed", error);
187
- });
188
- }
189
-
190
- function syncFetch() {
191
- const operation = lifecycle.then(async () => {
192
- if (entries.length > 0) {
193
- if (enabled) return;
194
- sessionId = await page.resolveSessionId();
195
- if (!unsubscribe) unsubscribe = page.cdp.on("Fetch.requestPaused", onPaused);
196
- try {
197
- await page.cdp.send("Fetch.enable", { patterns: [{ urlPattern: "*", requestStage: "Request" }] }, sessionId);
198
- } catch (error) {
199
- unsubscribe();
200
- unsubscribe = null;
201
- throw error;
202
- }
203
- enabled = true;
204
- } else if (enabled) {
205
- await page.cdp.send("Fetch.disable", {}, sessionId);
206
- enabled = false;
207
- unsubscribe();
208
- unsubscribe = null;
209
- settledIds.clear();
210
- }
211
- });
212
- lifecycle = operation.catch(() => {});
213
- return operation;
214
- }
215
-
216
- async function route(match, handler, { times = Infinity, prepend = false } = {}) {
217
- if (typeof handler !== "function") throw new TypeError("handler must be a function");
218
- if (times !== Infinity && (!Number.isInteger(times) || times < 1)) throw new TypeError("times must be a positive integer");
219
- const entry = { match, handler, remaining: times };
220
- if (prepend) entries.unshift(entry);
221
- else entries.push(entry);
222
- try {
223
- await syncFetch();
224
- } catch (error) {
225
- const index = entries.indexOf(entry);
226
- if (index !== -1) entries.splice(index, 1);
227
- throw error;
228
- }
229
- }
230
-
231
- async function unroute(match, handler) {
232
- if (match === undefined) entries.length = 0;
233
- else {
234
- for (let index = entries.length - 1; index >= 0; index -= 1) {
235
- if (sameMatch(entries[index].match, match) && (handler === undefined || entries[index].handler === handler)) entries.splice(index, 1);
236
- }
237
- }
238
- await syncFetch();
239
- }
240
-
241
- async function dispose() {
242
- entries.length = 0;
243
- await syncFetch();
244
- }
245
-
246
- const controller = {
247
- route,
248
- unroute,
249
- dispose,
250
- get enabled() {
251
- return enabled;
252
- },
253
- };
254
- controllers.set(page, controller);
255
- return controller;
256
- }
@@ -1,85 +0,0 @@
1
- // Find a Chromium browser the user already runs with remote debugging turned on
2
- // (chrome://inspect/#remote-debugging on Chrome 144+, or --remote-debugging-port)
3
- // and attach to it over CDP, without a browser extension in the way.
4
- // Idea adapted from vercel-labs/agent-browser (Apache-2.0), cli/src/native/cdp/chrome.rs
5
- // `auto_connect_cdp`: read DevToolsActivePort and use its exact WebSocket path, which
6
- // asks the user once instead of once per discovery probe. Written fresh for this file.
7
- import { readFile } from "node:fs/promises";
8
- import { connect as connectTcp } from "node:net";
9
- import path from "node:path";
10
- import { catalogBrowsers } from "./bsk/browsers.js";
11
- import { connect } from "./connection.js";
12
-
13
- const DEFAULT_PORT_CHECK_MS = 1_000;
14
-
15
- export class RunningBrowserError extends Error {
16
- constructor(code, message, candidates = []) {
17
- super(message);
18
- this.name = "RunningBrowserError";
19
- this.code = code;
20
- this.candidates = candidates;
21
- }
22
- }
23
-
24
- export async function readDevToolsActivePort(userDataDir) {
25
- const text = await readFile(path.join(userDataDir, "DevToolsActivePort"), "utf8").catch(() => null);
26
- if (text === null) return null;
27
- const [portLine, wsPath = ""] = text.split(/\r?\n/);
28
- const port = Number(portLine.trim());
29
- if (!Number.isInteger(port) || port <= 0 || port > 65_535) return null;
30
- const pathPart = wsPath.trim();
31
- return { port, wsPath: pathPart.startsWith("/devtools/browser") ? pathPart : null };
32
- }
33
-
34
- // A bare TCP connect: it tells a live port from a stale file without opening a
35
- // WebSocket, so it never raises Chrome's "Allow remote debugging?" prompt.
36
- function portIsListening(port, timeoutMs) {
37
- return new Promise((resolve) => {
38
- const socket = connectTcp({ host: "127.0.0.1", port });
39
- const done = (live) => {
40
- socket.destroy();
41
- resolve(live);
42
- };
43
- socket.setTimeout(timeoutMs, () => done(false));
44
- socket.once("connect", () => done(true));
45
- socket.once("error", () => done(false));
46
- });
47
- }
48
-
49
- function candidateDirs({ browser, userDataDirs, catalog }) {
50
- if (userDataDirs) return userDataDirs.map((dir) => ({ id: path.basename(dir), label: dir, userDataDir: dir }));
51
- const rows = catalog().filter((row) => row.hasProfile);
52
- return browser ? rows.filter((row) => row.id === browser) : rows;
53
- }
54
-
55
- // Never deletes or edits anything in the profile: a stale DevToolsActivePort is skipped,
56
- // because the user-data folder is the user's real browser profile.
57
- export async function findRunningBrowser({ browser, userDataDirs, portCheckMs = DEFAULT_PORT_CHECK_MS, catalog = catalogBrowsers } = {}) {
58
- const live = [];
59
- for (const candidate of candidateDirs({ browser, userDataDirs, catalog })) {
60
- const active = await readDevToolsActivePort(candidate.userDataDir);
61
- if (!active || !active.wsPath) continue;
62
- if (!(await portIsListening(active.port, portCheckMs))) continue;
63
- live.push({ ...candidate, port: active.port, wsUrl: `ws://127.0.0.1:${active.port}${active.wsPath}` });
64
- }
65
- if (live.length === 1) return live[0];
66
- if (live.length === 0) {
67
- throw new RunningBrowserError(
68
- "not_found",
69
- "No running browser has remote debugging on. Ask the user to open chrome://inspect/#remote-debugging and allow it, then retry.",
70
- );
71
- }
72
- throw new RunningBrowserError(
73
- "choose_browser",
74
- `More than one browser has remote debugging on (${live.map((row) => row.id).join(", ")}); pass { browser: "<id>" }.`,
75
- live,
76
- );
77
- }
78
-
79
- // Chrome holds the WebSocket handshake while it asks the user, so this call waits until
80
- // the user allows or denies the prompt; one shared connection per browser keeps it to one prompt.
81
- export async function connectRunningBrowser(options = {}) {
82
- const found = await findRunningBrowser(options);
83
- const browser = await connect(found.wsUrl, options.connect ?? {});
84
- return { browser, found };
85
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * Scroll-driven collection over a network snoop (see ./network-snoop.js).
3
- */
4
- async function viewportOf(page) {
5
- return page.viewportSize() ?? await page.evaluate(() => ({ width: innerWidth, height: innerHeight }));
6
- }
7
-
8
- async function scrollOnce(page, mode) {
9
- if (mode === "end") {
10
- await page.evaluate(() => scrollTo(0, document.scrollingElement.scrollHeight));
11
- return;
12
- }
13
- const viewport = await viewportOf(page);
14
- await page.mouse.move(Math.floor(viewport.width / 2), Math.floor(viewport.height / 2));
15
- await page.mouse.wheel(0, Math.floor(viewport.height * 0.9));
16
- }
17
-
18
- /**
19
- * Scrolls a page while draining JSON responses out of a snoop.
20
- *
21
- * Yields every extracted item and returns { rounds, total, stoppedBecause } when it stops.
22
- */
23
- export async function* collectWhileScrolling(page, snoop, options = {}) {
24
- const {
25
- minItems = Infinity,
26
- maxScrolls = 10,
27
- extract = json => (Array.isArray(json) ? json : []),
28
- scroll = "wheel",
29
- settleMs = 800,
30
- } = options;
31
- if (scroll !== "wheel" && scroll !== "end") throw new TypeError(`Unknown scroll mode: ${String(scroll)}`);
32
-
33
- let rounds = 0;
34
- let total = 0;
35
- let lastHeight = null;
36
- let unchanged = 0;
37
- let stoppedBecause = "maxScrolls";
38
-
39
- for (;;) {
40
- for (const json of snoop.popJson()) {
41
- for (const item of extract(json)) {
42
- total += 1;
43
- yield item;
44
- }
45
- }
46
- if (total >= minItems) {
47
- stoppedBecause = "minItems";
48
- break;
49
- }
50
- if (rounds >= maxScrolls) {
51
- stoppedBecause = "maxScrolls";
52
- break;
53
- }
54
-
55
- const height = await page.evaluate(() => document.scrollingElement.scrollHeight);
56
- if (lastHeight !== null && height === lastHeight) {
57
- unchanged += 1;
58
- if (unchanged >= 2) {
59
- stoppedBecause = "noGrowth";
60
- break;
61
- }
62
- } else {
63
- unchanged = 0;
64
- }
65
- lastHeight = height;
66
-
67
- await scrollOnce(page, scroll);
68
- rounds += 1;
69
- await new Promise(resolve => setTimeout(resolve, settleMs));
70
- }
71
-
72
- return { rounds, total, stoppedBecause };
73
- }
@@ -1,17 +0,0 @@
1
- // Event emitter for the pipe transport: listeners run one after another, in
2
- // registration order, and emit() resolves once the last one has settled.
3
- export class SerialEmitter {
4
- #listeners = new Map();
5
- on(event, fn) {
6
- const list = this.#listeners.get(event) ?? [];
7
- list.push(fn);
8
- this.#listeners.set(event, list);
9
- return () => {
10
- const cur = this.#listeners.get(event) ?? [];
11
- this.#listeners.set(event, cur.filter(f => f !== fn));
12
- };
13
- }
14
- async emit(event, data) {
15
- for (const fn of this.#listeners.get(event) ?? []) await fn(data);
16
- }
17
- }