@cbxss/eoka 0.1.0-beta.3 → 0.1.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/dist/browser.d.ts CHANGED
@@ -4,12 +4,15 @@ import { Operation } from './operations.js';
4
4
  import { Page, type PerformOptions } from './page.js';
5
5
  import { Recording } from './recording.js';
6
6
  import { type InstallProgress } from './browser-install.js';
7
+ import { type CloudflareOptions } from './cloudflare.js';
7
8
  export interface BrowserOptions {
8
9
  serverPath?: string;
9
10
  serverEnv?: NodeJS.ProcessEnv;
10
11
  signal?: AbortSignal;
11
12
  timeoutMs?: number;
12
13
  shutdownTimeoutMs?: number;
14
+ /** Watch every tab and click full-page Cloudflare challenge checkboxes. */
15
+ autoSolveCloudflare?: boolean | CloudflareOptions;
13
16
  }
14
17
  export interface LaunchOptions extends BrowserOptions {
15
18
  executablePath?: string;
package/dist/browser.js CHANGED
@@ -8,6 +8,7 @@ import { Page } from './page.js';
8
8
  import { Recording } from './recording.js';
9
9
  import { SidecarTransport } from './transport.js';
10
10
  import { installBrowser } from './browser-install.js';
11
+ import { CloudflareWatcher, resolveCloudflareOptions } from './cloudflare.js';
11
12
  import { resolveServerBinary } from './server-binary.js';
12
13
  function validateTimeout(value, name) {
13
14
  if (value !== undefined && (!Number.isFinite(value) || value <= 0 || value > 2_147_483_647)) {
@@ -192,6 +193,7 @@ export class Browser {
192
193
  #capabilities;
193
194
  #shutdownTimeoutMs;
194
195
  #closePromise;
196
+ #cloudflare;
195
197
  #pageOwners = new Set();
196
198
  #creationCleanupFailures = [];
197
199
  #runtimeCleanup;
@@ -296,7 +298,13 @@ export class Browser {
296
298
  throw new ProtocolError(`Managed browser version mismatch: expected ${expectedBrowserVersion}, received ${session.browserVersion}`, { requestState: 'acknowledged' });
297
299
  }
298
300
  checkAbort(options.signal, 'acknowledged');
299
- return new Browser(transport, session, options.shutdownTimeoutMs ?? 45_000, runtimeDir);
301
+ const browser = new Browser(transport, session, options.shutdownTimeoutMs ?? 45_000, runtimeDir);
302
+ const cloudflare = resolveCloudflareOptions(options.autoSolveCloudflare);
303
+ if (cloudflare !== undefined) {
304
+ browser.#cloudflare = new CloudflareWatcher(browser, cloudflare);
305
+ browser.#cloudflare.start();
306
+ }
307
+ return browser;
300
308
  }
301
309
  catch (primary) {
302
310
  try {
@@ -413,6 +421,7 @@ export class Browser {
413
421
  }
414
422
  close() {
415
423
  this.#closePromise ??= (async () => {
424
+ this.#cloudflare?.stop();
416
425
  this.#transport.quiesce();
417
426
  await Promise.all(this.#pageOwners);
418
427
  let transportFailure;
@@ -0,0 +1,45 @@
1
+ import type { CallOptions } from './client.js';
2
+ import type { Page } from './page.js';
3
+ /** Options for the browser-wide Cloudflare challenge watcher. */
4
+ export interface CloudflareOptions {
5
+ /** Poll interval in milliseconds. Defaults to 500. */
6
+ intervalMs?: number;
7
+ /** Deadline for each `solveTurnstile()` attempt. Defaults to 30000. */
8
+ timeoutMs?: number;
9
+ /** Called when a full-page challenge is detected, before the click. */
10
+ onChallenge?: (page: Page) => void;
11
+ /** Called after the challenge page has been left. */
12
+ onSolved?: (page: Page) => void;
13
+ /** Called for watcher or solve failures. A page is omitted when listing tabs fails. */
14
+ onError?: (error: unknown, page?: Page) => void;
15
+ }
16
+ export interface ResolvedCloudflareOptions {
17
+ intervalMs: number;
18
+ timeoutMs: number;
19
+ onChallenge?: (page: Page) => void;
20
+ onSolved?: (page: Page) => void;
21
+ onError?: (error: unknown, page?: Page) => void;
22
+ }
23
+ export interface CloudflareBrowser {
24
+ tabs(options?: CallOptions): Promise<readonly {
25
+ id: string;
26
+ }[]>;
27
+ page(id: string): Page;
28
+ }
29
+ /**
30
+ * Full-page Cloudflare challenge titles. A Turnstile widget embedded in a
31
+ * normal form has the same frame URL, so the title is the discriminator.
32
+ */
33
+ export declare function isCloudflareChallengeTitle(title: string): boolean;
34
+ export declare function resolveCloudflareOptions(value: boolean | CloudflareOptions | undefined): ResolvedCloudflareOptions | undefined;
35
+ /**
36
+ * Polls every tab for a full-page Cloudflare challenge and clicks its
37
+ * checkbox through `Page.solveTurnstile()`. The timer is unref'd, so it does
38
+ * not keep the Node process alive. `stop()` aborts an in-flight attempt.
39
+ */
40
+ export declare class CloudflareWatcher {
41
+ #private;
42
+ constructor(browser: CloudflareBrowser, options: ResolvedCloudflareOptions);
43
+ start(): void;
44
+ stop(): void;
45
+ }
@@ -0,0 +1,154 @@
1
+ import { ConfigurationError } from './errors.js';
2
+ const challengeTitle = /just a moment|attention required|checking your browser|verify you are human|please wait.*cloudflare/i;
3
+ /**
4
+ * Full-page Cloudflare challenge titles. A Turnstile widget embedded in a
5
+ * normal form has the same frame URL, so the title is the discriminator.
6
+ */
7
+ export function isCloudflareChallengeTitle(title) {
8
+ return challengeTitle.test(title);
9
+ }
10
+ export function resolveCloudflareOptions(value) {
11
+ if (value === undefined || value === false)
12
+ return undefined;
13
+ const options = value === true ? {} : value;
14
+ const intervalMs = options.intervalMs ?? 500;
15
+ const timeoutMs = options.timeoutMs ?? 30_000;
16
+ if (!Number.isFinite(intervalMs) || intervalMs < 100 || intervalMs > 60_000) {
17
+ throw new ConfigurationError('autoSolveCloudflare.intervalMs must be between 100 and 60000 milliseconds');
18
+ }
19
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > 2_147_483_647) {
20
+ throw new ConfigurationError('autoSolveCloudflare.timeoutMs must be finite, positive and at most 2147483647 milliseconds');
21
+ }
22
+ for (const name of ['onChallenge', 'onSolved', 'onError']) {
23
+ if (options[name] !== undefined && typeof options[name] !== 'function') {
24
+ throw new ConfigurationError(`autoSolveCloudflare.${name} must be a function`);
25
+ }
26
+ }
27
+ const resolved = { intervalMs, timeoutMs };
28
+ if (options.onChallenge !== undefined)
29
+ resolved.onChallenge = options.onChallenge;
30
+ if (options.onSolved !== undefined)
31
+ resolved.onSolved = options.onSolved;
32
+ if (options.onError !== undefined)
33
+ resolved.onError = options.onError;
34
+ return resolved;
35
+ }
36
+ /**
37
+ * Polls every tab for a full-page Cloudflare challenge and clicks its
38
+ * checkbox through `Page.solveTurnstile()`. The timer is unref'd, so it does
39
+ * not keep the Node process alive. `stop()` aborts an in-flight attempt.
40
+ */
41
+ export class CloudflareWatcher {
42
+ #browser;
43
+ #options;
44
+ #controller = new AbortController();
45
+ #pages = new Map();
46
+ #solving = new Set();
47
+ #timer;
48
+ #running = false;
49
+ #stopped = false;
50
+ constructor(browser, options) {
51
+ this.#browser = browser;
52
+ this.#options = options;
53
+ }
54
+ start() {
55
+ if (this.#stopped || this.#timer !== undefined)
56
+ return;
57
+ this.#timer = setInterval(() => { void this.#tick(); }, this.#options.intervalMs);
58
+ this.#timer.unref();
59
+ void this.#tick();
60
+ }
61
+ stop() {
62
+ if (this.#stopped)
63
+ return;
64
+ this.#stopped = true;
65
+ this.#controller.abort();
66
+ if (this.#timer !== undefined) {
67
+ clearInterval(this.#timer);
68
+ this.#timer = undefined;
69
+ }
70
+ }
71
+ async #tick() {
72
+ if (this.#running || this.#stopped)
73
+ return;
74
+ this.#running = true;
75
+ try {
76
+ const tabs = await this.#browser.tabs({ signal: this.#controller.signal });
77
+ const ids = new Set(tabs.map(tab => tab.id));
78
+ for (const id of this.#pages.keys()) {
79
+ if (!ids.has(id)) {
80
+ this.#pages.delete(id);
81
+ this.#solving.delete(id);
82
+ }
83
+ }
84
+ for (const id of ids) {
85
+ if (this.#stopped)
86
+ break;
87
+ await this.#check(id);
88
+ }
89
+ }
90
+ catch (error) {
91
+ if (!this.#stopped)
92
+ this.#notifyError(error);
93
+ }
94
+ finally {
95
+ this.#running = false;
96
+ }
97
+ }
98
+ async #check(id) {
99
+ if (this.#solving.has(id))
100
+ return;
101
+ let page = this.#pages.get(id);
102
+ if (page === undefined) {
103
+ page = this.#browser.page(id);
104
+ this.#pages.set(id, page);
105
+ }
106
+ let title;
107
+ try {
108
+ title = await page.title({ signal: this.#controller.signal });
109
+ }
110
+ catch (error) {
111
+ if (!this.#stopped)
112
+ this.#notifyError(error, page);
113
+ return;
114
+ }
115
+ if (this.#stopped || !isCloudflareChallengeTitle(title))
116
+ return;
117
+ this.#solving.add(id);
118
+ this.#notify('onChallenge', page);
119
+ try {
120
+ await page.solveTurnstile({ timeoutMs: this.#options.timeoutMs, signal: this.#controller.signal });
121
+ if (!this.#stopped)
122
+ this.#notify('onSolved', page);
123
+ }
124
+ catch (error) {
125
+ if (!this.#stopped)
126
+ this.#notifyError(error, page);
127
+ }
128
+ finally {
129
+ this.#solving.delete(id);
130
+ }
131
+ }
132
+ #notify(name, page) {
133
+ const callback = this.#options[name];
134
+ if (callback === undefined)
135
+ return;
136
+ try {
137
+ callback(page);
138
+ }
139
+ catch (error) {
140
+ this.#notifyError(error, page);
141
+ }
142
+ }
143
+ #notifyError(error, page) {
144
+ const callback = this.#options.onError;
145
+ if (callback === undefined)
146
+ return;
147
+ try {
148
+ callback(error, page);
149
+ }
150
+ catch {
151
+ // A failing observer must not stop the watcher.
152
+ }
153
+ }
154
+ }
@@ -1945,6 +1945,20 @@ export type MethodPageClickResult__ActionReceipt = {
1945
1945
  };
1946
1946
  export type MethodPageClickResult__DispatchState = (("not_sent" & string) | ("may_have_been_sent" & string) | ("acknowledged" & string));
1947
1947
  export type MethodPageClickResult__OperationState = (("running" | "finished" | "interrupted" | "expired") & string);
1948
+ export type MethodPageClickShadowParams = {
1949
+ "frameId"?: (string | null);
1950
+ "pageId": string;
1951
+ "selector": string;
1952
+ "timeoutMs"?: number;
1953
+ [key: string]: unknown;
1954
+ };
1955
+ export type MethodPageClickShadowResult = {
1956
+ "frameId": string;
1957
+ "selector": string;
1958
+ "x": number;
1959
+ "y": number;
1960
+ [key: string]: unknown;
1961
+ };
1948
1962
  export type MethodPageClickTextParams = {
1949
1963
  "operation_id": string;
1950
1964
  "options"?: MethodPageClickTextParams__ActionOptions;
@@ -3793,6 +3807,7 @@ export type MethodParams = {
3793
3807
  "operations.wait": MethodOperationsWaitParams;
3794
3808
  "page.capture_state": MethodPageCaptureStateParams;
3795
3809
  "page.click": MethodPageClickParams;
3810
+ "page.click_shadow": MethodPageClickShadowParams;
3796
3811
  "page.click_text": MethodPageClickTextParams;
3797
3812
  "page.close": MethodPageCloseParams;
3798
3813
  "page.content": MethodPageContentParams;
@@ -3855,6 +3870,7 @@ export type MethodResults = {
3855
3870
  "operations.wait": MethodOperationsWaitResult;
3856
3871
  "page.capture_state": MethodPageCaptureStateResult;
3857
3872
  "page.click": MethodPageClickResult;
3873
+ "page.click_shadow": MethodPageClickShadowResult;
3858
3874
  "page.click_text": MethodPageClickTextResult;
3859
3875
  "page.close": MethodPageCloseResult;
3860
3876
  "page.content": MethodPageContentResult;
@@ -3926,4 +3942,4 @@ export declare const protocolVersion: {
3926
3942
  readonly major: 1;
3927
3943
  readonly minor: 3;
3928
3944
  };
3929
- export declare const methodNames: readonly ["actions.perform", "agent.observe", "agent.step", "browser.close", "browser.close_tab", "browser.connect", "browser.launch", "browser.new_page", "browser.tabs", "operations.cancel", "operations.get", "operations.list", "operations.wait", "page.capture_state", "page.click", "page.click_text", "page.close", "page.content", "page.evaluate", "page.evaluate_in_frame", "page.execute", "page.exists", "page.fetch", "page.fetch_bounded", "page.fill", "page.frames", "page.get_attribute", "page.get_text", "page.goto", "page.hover", "page.human_click", "page.human_click_text", "page.human_fill", "page.key_down", "page.key_up", "page.mouse_down", "page.mouse_move", "page.mouse_up", "page.press_key", "page.release_all_inputs", "page.reset_viewport", "page.restore_state", "page.screenshot", "page.screenshot_to_file", "page.select", "page.set_viewport", "page.solve_captcha", "page.text", "page.title", "page.type_into", "page.url", "page.wait_for", "page.wait_for_text", "page.wait_for_visible", "recording.cancel", "recording.get", "recording.start", "recording.stop", "server.hello", "server.shutdown"];
3945
+ export declare const methodNames: readonly ["actions.perform", "agent.observe", "agent.step", "browser.close", "browser.close_tab", "browser.connect", "browser.launch", "browser.new_page", "browser.tabs", "operations.cancel", "operations.get", "operations.list", "operations.wait", "page.capture_state", "page.click", "page.click_shadow", "page.click_text", "page.close", "page.content", "page.evaluate", "page.evaluate_in_frame", "page.execute", "page.exists", "page.fetch", "page.fetch_bounded", "page.fill", "page.frames", "page.get_attribute", "page.get_text", "page.goto", "page.hover", "page.human_click", "page.human_click_text", "page.human_fill", "page.key_down", "page.key_up", "page.mouse_down", "page.mouse_move", "page.mouse_up", "page.press_key", "page.release_all_inputs", "page.reset_viewport", "page.restore_state", "page.screenshot", "page.screenshot_to_file", "page.select", "page.set_viewport", "page.solve_captcha", "page.text", "page.title", "page.type_into", "page.url", "page.wait_for", "page.wait_for_text", "page.wait_for_visible", "recording.cancel", "recording.get", "recording.start", "recording.stop", "server.hello", "server.shutdown"];
@@ -1,2 +1,2 @@
1
1
  export const protocolVersion = { "major": 1, "minor": 3 };
2
- export const methodNames = ["actions.perform", "agent.observe", "agent.step", "browser.close", "browser.close_tab", "browser.connect", "browser.launch", "browser.new_page", "browser.tabs", "operations.cancel", "operations.get", "operations.list", "operations.wait", "page.capture_state", "page.click", "page.click_text", "page.close", "page.content", "page.evaluate", "page.evaluate_in_frame", "page.execute", "page.exists", "page.fetch", "page.fetch_bounded", "page.fill", "page.frames", "page.get_attribute", "page.get_text", "page.goto", "page.hover", "page.human_click", "page.human_click_text", "page.human_fill", "page.key_down", "page.key_up", "page.mouse_down", "page.mouse_move", "page.mouse_up", "page.press_key", "page.release_all_inputs", "page.reset_viewport", "page.restore_state", "page.screenshot", "page.screenshot_to_file", "page.select", "page.set_viewport", "page.solve_captcha", "page.text", "page.title", "page.type_into", "page.url", "page.wait_for", "page.wait_for_text", "page.wait_for_visible", "recording.cancel", "recording.get", "recording.start", "recording.stop", "server.hello", "server.shutdown"];
2
+ export const methodNames = ["actions.perform", "agent.observe", "agent.step", "browser.close", "browser.close_tab", "browser.connect", "browser.launch", "browser.new_page", "browser.tabs", "operations.cancel", "operations.get", "operations.list", "operations.wait", "page.capture_state", "page.click", "page.click_shadow", "page.click_text", "page.close", "page.content", "page.evaluate", "page.evaluate_in_frame", "page.execute", "page.exists", "page.fetch", "page.fetch_bounded", "page.fill", "page.frames", "page.get_attribute", "page.get_text", "page.goto", "page.hover", "page.human_click", "page.human_click_text", "page.human_fill", "page.key_down", "page.key_up", "page.mouse_down", "page.mouse_move", "page.mouse_up", "page.press_key", "page.release_all_inputs", "page.reset_viewport", "page.restore_state", "page.screenshot", "page.screenshot_to_file", "page.select", "page.set_viewport", "page.solve_captcha", "page.text", "page.title", "page.type_into", "page.url", "page.wait_for", "page.wait_for_text", "page.wait_for_visible", "recording.cancel", "recording.get", "recording.start", "recording.stop", "server.hello", "server.shutdown"];
@@ -4198,6 +4198,65 @@
4198
4198
  "type": "object"
4199
4199
  }
4200
4200
  },
4201
+ "page.click_shadow": {
4202
+ "params": {
4203
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4204
+ "properties": {
4205
+ "frameId": {
4206
+ "type": [
4207
+ "string",
4208
+ "null"
4209
+ ]
4210
+ },
4211
+ "pageId": {
4212
+ "type": "string"
4213
+ },
4214
+ "selector": {
4215
+ "type": "string"
4216
+ },
4217
+ "timeoutMs": {
4218
+ "default": 10000,
4219
+ "format": "uint64",
4220
+ "maximum": 9007199254740991,
4221
+ "minimum": 0,
4222
+ "type": "integer"
4223
+ }
4224
+ },
4225
+ "required": [
4226
+ "pageId",
4227
+ "selector"
4228
+ ],
4229
+ "title": "ClickShadowParams",
4230
+ "type": "object"
4231
+ },
4232
+ "result": {
4233
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4234
+ "properties": {
4235
+ "frameId": {
4236
+ "type": "string"
4237
+ },
4238
+ "selector": {
4239
+ "type": "string"
4240
+ },
4241
+ "x": {
4242
+ "format": "double",
4243
+ "type": "number"
4244
+ },
4245
+ "y": {
4246
+ "format": "double",
4247
+ "type": "number"
4248
+ }
4249
+ },
4250
+ "required": [
4251
+ "frameId",
4252
+ "selector",
4253
+ "x",
4254
+ "y"
4255
+ ],
4256
+ "title": "ClickShadowResult",
4257
+ "type": "object"
4258
+ }
4259
+ },
4201
4260
  "page.click_text": {
4202
4261
  "params": {
4203
4262
  "$defs": {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Browser } from "./browser.js";
2
2
  export type { BrowserOptions, LaunchOptions, ConnectOptions } from "./browser.js";
3
+ export type { CloudflareOptions } from "./cloudflare.js";
3
4
  export { installBrowser } from "./browser-install.js";
4
5
  export type { InstallBrowserOptions, InstallProgress, BrowserInstallation } from "./browser-install.js";
5
6
  export { InstallationError } from "./install-errors.js";
package/dist/page.d.ts CHANGED
@@ -62,6 +62,26 @@ export declare class Page implements InvokeClient {
62
62
  waitForText(text: string, options?: PageWaitOptions): Promise<void>;
63
63
  evaluate(js: string, options?: CallOptions): Promise<unknown>;
64
64
  execute(js: string, options?: CallOptions): Promise<void>;
65
+ /** List every frame in the page, including cross-origin OOPIFs. */
66
+ frames(options?: CallOptions): Promise<MethodResults['page.frames']>;
67
+ /**
68
+ * Click an element inside a closed shadow root in the top frame or a child
69
+ * frame. `frameId` comes from `frames()`. The selector is searched through
70
+ * the frame's light DOM and every shadow root; the node's center is mapped
71
+ * to viewport coordinates and clicked with human-like movement.
72
+ */
73
+ clickShadow(selector: string, options?: {
74
+ frameId?: string;
75
+ resolveTimeoutMs?: number;
76
+ } & CallOptions): Promise<MethodResults['page.click_shadow']>;
77
+ /**
78
+ * Best-effort helper for interactive Cloudflare challenge pages: find the
79
+ * `challenges.cloudflare.com` frame, click its checkbox through the closed
80
+ * shadow root, and wait for the page to leave the challenge state.
81
+ */
82
+ solveTurnstile(options?: {
83
+ timeoutMs?: number;
84
+ } & CallOptions): Promise<void>;
65
85
  captureState(options?: CallOptions): Promise<BrowserState>;
66
86
  restoreState(state: BrowserState, options?: CallOptions): Promise<void>;
67
87
  fetch(url: string, fetchOptions?: FetchOptions, options?: CallOptions): Promise<MethodResults['page.fetch']>;
package/dist/page.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Buffer } from 'node:buffer';
2
2
  import { randomUUID } from 'node:crypto';
3
3
  import { resolve } from 'node:path';
4
+ import { ProtocolError } from './errors.js';
4
5
  import { Operation, OperationError, operationFailure, validateOperationRecord } from './operations.js';
5
6
  import { Recording, RecordingError, recordingFailure, requireCaptureCapability, validateRecordingRecord } from './recording.js';
6
7
  const recordingIdPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -137,6 +138,63 @@ export class Page {
137
138
  async execute(js, options) {
138
139
  await this.invoke('page.execute', { pageId: this.id, js }, options);
139
140
  }
141
+ /** List every frame in the page, including cross-origin OOPIFs. */
142
+ async frames(options) {
143
+ return this.invoke('page.frames', { pageId: this.id }, options);
144
+ }
145
+ /**
146
+ * Click an element inside a closed shadow root in the top frame or a child
147
+ * frame. `frameId` comes from `frames()`. The selector is searched through
148
+ * the frame's light DOM and every shadow root; the node's center is mapped
149
+ * to viewport coordinates and clicked with human-like movement.
150
+ */
151
+ async clickShadow(selector, options = {}) {
152
+ const { frameId, resolveTimeoutMs, ...callOptions } = options;
153
+ // `CallOptions.timeoutMs` is the RPC deadline; `resolveTimeoutMs` is the
154
+ // server-side resolution deadline. Derive an RPC deadline that cannot
155
+ // outlive a long resolution when the caller did not set one explicitly.
156
+ if (callOptions.timeoutMs === undefined && resolveTimeoutMs !== undefined) {
157
+ callOptions.timeoutMs = resolveTimeoutMs + 10_000;
158
+ }
159
+ return this.invoke('page.click_shadow', {
160
+ pageId: this.id,
161
+ selector,
162
+ ...(frameId === undefined ? {} : { frameId }),
163
+ ...(resolveTimeoutMs === undefined ? {} : { timeoutMs: resolveTimeoutMs }),
164
+ }, callOptions);
165
+ }
166
+ /**
167
+ * Best-effort helper for interactive Cloudflare challenge pages: find the
168
+ * `challenges.cloudflare.com` frame, click its checkbox through the closed
169
+ * shadow root, and wait for the page to leave the challenge state.
170
+ */
171
+ async solveTurnstile(options = {}) {
172
+ const { timeoutMs = 30_000, ...callOptions } = options;
173
+ const deadline = performance.now() + timeoutMs;
174
+ while (performance.now() < deadline) {
175
+ const frames = await this.frames(callOptions);
176
+ const challenge = frames.find(frame => frame.url.includes('challenges.cloudflare.com'));
177
+ if (challenge !== undefined) {
178
+ const remaining = Math.max(1, Math.floor(deadline - performance.now()));
179
+ try {
180
+ await this.clickShadow('input[type="checkbox"]', {
181
+ ...callOptions,
182
+ frameId: challenge.id,
183
+ resolveTimeoutMs: Math.min(remaining, 2_000),
184
+ });
185
+ }
186
+ catch (error) {
187
+ if (performance.now() >= deadline)
188
+ throw error;
189
+ }
190
+ }
191
+ else if (!(await this.title(callOptions)).includes('moment')) {
192
+ return;
193
+ }
194
+ await new Promise(resolve => setTimeout(resolve, 500));
195
+ }
196
+ throw new ProtocolError('Turnstile challenge did not resolve before the deadline');
197
+ }
140
198
  async captureState(options) {
141
199
  return (await this.invoke('page.capture_state', { pageId: this.id }, options)).state;
142
200
  }
@@ -1,63 +1,63 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "sdkVersion": "0.1.0-beta.3",
3
+ "sdkVersion": "0.1.0-beta.5",
4
4
  "installerVersion": "3.2.4",
5
5
  "server": {
6
- "version": "0.6.1",
6
+ "version": "0.6.2",
7
7
  "protocolVersion": "1.3",
8
8
  "platforms": {
9
9
  "linux-x64-gnu": {
10
10
  "packageName": "@cbxss/eoka-server-linux-x64-gnu",
11
- "packageVersion": "0.1.0-beta.3",
11
+ "packageVersion": "0.1.0-beta.5",
12
12
  "target": "x86_64-unknown-linux-gnu",
13
13
  "asset": "eoka-server-linux-amd64",
14
14
  "executablePath": "bin/eoka-server",
15
- "sha256": "445c2f1dfb84df9ad6d868d78b2ba67a1b107d1fc96ae3d7a1ce9fc97e8c2089",
16
- "size": 16968272,
15
+ "sha256": "0f84e0f05c7243cb0f2f0390df8ccf54a71bb9bdd3bd79ff28238ed4f866ccab",
16
+ "size": 17166424,
17
17
  "minimumGlibc": "2.35",
18
18
  "development": false
19
19
  },
20
20
  "linux-arm64-gnu": {
21
21
  "packageName": "@cbxss/eoka-server-linux-arm64-gnu",
22
- "packageVersion": "0.1.0-beta.3",
22
+ "packageVersion": "0.1.0-beta.5",
23
23
  "target": "aarch64-unknown-linux-gnu",
24
24
  "asset": "eoka-server-linux-arm64",
25
25
  "executablePath": "bin/eoka-server",
26
- "sha256": "291df6255ab1b98ffe1f0fc8c0473d508cdd2d26d46f0517b7fe060a8949ed78",
27
- "size": 16247368,
26
+ "sha256": "55fe53844f0e8dc5a7d8cd995b546be4162045aac51e63143af82f0f7932da68",
27
+ "size": 16418664,
28
28
  "minimumGlibc": "2.35",
29
29
  "development": false
30
30
  },
31
31
  "darwin-x64": {
32
32
  "packageName": "@cbxss/eoka-server-darwin-x64",
33
- "packageVersion": "0.1.0-beta.3",
33
+ "packageVersion": "0.1.0-beta.5",
34
34
  "target": "x86_64-apple-darwin",
35
35
  "asset": "eoka-server-darwin-amd64",
36
36
  "executablePath": "bin/eoka-server",
37
- "sha256": "e73e1048854a2671e63ff0ea86e30dd7d15df50f6328958fa35f0a71fb088ea8",
38
- "size": 15055664,
37
+ "sha256": "eda5a8b139d3a71647ab5ae72f3dca204fba3ac8ec0f76a296709e5173c574be",
38
+ "size": 15238912,
39
39
  "minimumGlibc": null,
40
40
  "development": false
41
41
  },
42
42
  "darwin-arm64": {
43
43
  "packageName": "@cbxss/eoka-server-darwin-arm64",
44
- "packageVersion": "0.1.0-beta.3",
44
+ "packageVersion": "0.1.0-beta.5",
45
45
  "target": "aarch64-apple-darwin",
46
46
  "asset": "eoka-server-darwin-arm64",
47
47
  "executablePath": "bin/eoka-server",
48
- "sha256": "faba395aef1347ddce39cb3ce1fa52029a801a172d19c1632c0256a15a83022c",
49
- "size": 14604368,
48
+ "sha256": "1e495252790f86d5e6ee6ed1d32208813b6c287065724cd22a6105b753ba61b2",
49
+ "size": 14750112,
50
50
  "minimumGlibc": null,
51
51
  "development": false
52
52
  },
53
53
  "win32-x64": {
54
54
  "packageName": "@cbxss/eoka-server-win32-x64",
55
- "packageVersion": "0.1.0-beta.3",
55
+ "packageVersion": "0.1.0-beta.5",
56
56
  "target": "x86_64-pc-windows-msvc",
57
57
  "asset": "eoka-server-windows-amd64.exe",
58
58
  "executablePath": "bin/eoka-server.exe",
59
- "sha256": "57829a23155279220964b4d3e07ab6d87c500818d92aed86c23d4fa4b59b74c4",
60
- "size": 14133248,
59
+ "sha256": "b78d479a72de095041091c4017126c1b8b9edf6ed5106e26ba10cb53e86e238c",
60
+ "size": 14304256,
61
61
  "minimumGlibc": null,
62
62
  "development": false
63
63
  }
package/dist/release.js CHANGED
@@ -29,7 +29,7 @@ export function validateReleaseManifest(value) {
29
29
  const chrome = object(manifest.chrome);
30
30
  const servers = object(server.platforms);
31
31
  const browsers = object(chrome.platforms);
32
- if (manifest.schemaVersion !== 1 || !exactNpmVersion(manifest.sdkVersion) || manifest.installerVersion !== '3.2.4' || server.version !== '0.6.1' || server.protocolVersion !== `${protocolVersion.major}.${protocolVersion.minor}` || chrome.buildId !== '155.0.8059.39')
32
+ if (manifest.schemaVersion !== 1 || !exactNpmVersion(manifest.sdkVersion) || manifest.installerVersion !== '3.2.4' || server.version !== '0.6.2' || server.protocolVersion !== `${protocolVersion.major}.${protocolVersion.minor}` || chrome.buildId !== '155.0.8059.39')
33
33
  throw new Error('Incompatible release versions');
34
34
  if (Object.keys(servers).length !== platformIds.length || Object.keys(browsers).length !== platformIds.length)
35
35
  throw new Error('Incomplete platform mapping');
@@ -8,4 +8,5 @@ export interface ServerBinaryResolution {
8
8
  source: 'explicit' | 'environment' | 'package';
9
9
  expectedServerVersion?: string;
10
10
  }
11
+ export declare function nodeEngineMismatch(range: string, version: string): boolean;
11
12
  export declare function resolveServerBinary(options?: ServerBinaryOptions): Promise<ServerBinaryResolution>;
@@ -14,6 +14,29 @@ function checkAbort(signal) {
14
14
  function isSingleton(value, expected) {
15
15
  return Array.isArray(value) && value.length === 1 && value[0] === expected;
16
16
  }
17
+ // npm skips an optional dependency whose engines range rejects the running
18
+ // Node, so a missing platform package often means the wrong Node version.
19
+ export function nodeEngineMismatch(range, version) {
20
+ const required = /^\^(\d+)\.(\d+)\.(\d+)$/.exec(range)?.slice(1).map(Number);
21
+ const current = /^v?(\d+)\.(\d+)\.(\d+)/.exec(version)?.slice(1).map(Number);
22
+ if (!required || !current || required[0] === 0)
23
+ return false;
24
+ if (current[0] !== required[0])
25
+ return true;
26
+ return current[1] < required[1] || (current[1] === required[1] && current[2] < required[2]);
27
+ }
28
+ function unsupportedNodeHint() {
29
+ let range;
30
+ try {
31
+ range = createRequire(import.meta.url)('../package.json').engines?.node;
32
+ }
33
+ catch {
34
+ return '';
35
+ }
36
+ if (typeof range !== 'string' || !nodeEngineMismatch(range, process.versions.node))
37
+ return '';
38
+ return ` npm skips it on unsupported Node versions: this is Node ${process.versions.node}, but @cbxss/eoka requires ${range}. Switch Node (for example \`mise use node@24\` or \`nvm install 24\`) and reinstall.`;
39
+ }
17
40
  export async function resolveServerBinary(options = {}) {
18
41
  const { signal } = options;
19
42
  checkAbort(signal);
@@ -41,7 +64,7 @@ export async function resolveServerBinary(options = {}) {
41
64
  packagePath = createRequire(import.meta.url).resolve(`${pin.packageName}/package.json`);
42
65
  }
43
66
  catch (cause) {
44
- throw new InstallationError('ServerPackageMissing', `The exact optional dependency ${pin.packageName}@${pin.packageVersion} is missing. Reinstall @cbxss/eoka with optional dependencies enabled (do not use --omit=optional), or install that exact platform package. There is no Cargo, PATH or network fallback.`, { cause });
67
+ throw new InstallationError('ServerPackageMissing', `The exact optional dependency ${pin.packageName}@${pin.packageVersion} is missing.${unsupportedNodeHint()} Reinstall @cbxss/eoka with optional dependencies enabled (do not use --omit=optional), or install that exact platform package. There is no Cargo, PATH or network fallback.`, { cause });
45
68
  }
46
69
  if (pin.sha256 === null || pin.size === null)
47
70
  throw new InstallationError('ReleaseNotPrepared', `The SDK has no staged server integrity pin for ${platform}. Use a prepared SDK plus its matching platform package, or set serverPath explicitly.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cbxss/eoka",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Node.js SDK with pinned Chrome installation and verified eoka sidecar resolution",
@@ -58,11 +58,11 @@
58
58
  "typescript": "5.9.3"
59
59
  },
60
60
  "optionalDependencies": {
61
- "@cbxss/eoka-server-linux-x64-gnu": "0.1.0-beta.3",
62
- "@cbxss/eoka-server-linux-arm64-gnu": "0.1.0-beta.3",
63
- "@cbxss/eoka-server-darwin-x64": "0.1.0-beta.3",
64
- "@cbxss/eoka-server-darwin-arm64": "0.1.0-beta.3",
65
- "@cbxss/eoka-server-win32-x64": "0.1.0-beta.3"
61
+ "@cbxss/eoka-server-linux-x64-gnu": "0.1.0-beta.5",
62
+ "@cbxss/eoka-server-linux-arm64-gnu": "0.1.0-beta.5",
63
+ "@cbxss/eoka-server-darwin-x64": "0.1.0-beta.5",
64
+ "@cbxss/eoka-server-darwin-arm64": "0.1.0-beta.5",
65
+ "@cbxss/eoka-server-win32-x64": "0.1.0-beta.5"
66
66
  },
67
67
  "repository": {
68
68
  "type": "git",