@cbxss/eoka 0.1.0-beta.1 → 0.1.0-beta.10

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.
@@ -19,7 +19,16 @@ export interface InstallationMarker {
19
19
  inventory: InventoryEntry[];
20
20
  }
21
21
  export declare function fingerprint(entries: InventoryEntry[]): string;
22
- export declare function inventoryTree(root: string): Promise<InventoryEntry[]>;
22
+ export interface InventoryOptions {
23
+ /**
24
+ * Root-relative, `/`-separated directory to skip while it is empty. Chrome
25
+ * creates `extensions/` next to its executable on every startup
26
+ * (component-extension staging) even with `--disable-component-update`; it
27
+ * is not part of the pinned archive, so it must not read as tampering.
28
+ */
29
+ ignoreEmptyDirectory?: string;
30
+ }
31
+ export declare function inventoryTree(root: string, options?: InventoryOptions): Promise<InventoryEntry[]>;
23
32
  export declare function validateExecutable(root: string, relative: string): Promise<void>;
24
33
  export declare function createMarker(root: string, buildId: string, platform: string, pin: ChromePlatformRelease, executablePath: string): Promise<void>;
25
34
  export declare function verifyInstallation(root: string, buildId: string, platform: string, pin: ChromePlatformRelease, executablePath: string): Promise<boolean>;
@@ -11,7 +11,7 @@ function inside(root, target) {
11
11
  const relative = path.relative(root, target);
12
12
  return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
13
13
  }
14
- export async function inventoryTree(root) {
14
+ export async function inventoryTree(root, options = {}) {
15
15
  const rootInfo = await lstat(root);
16
16
  if (!rootInfo.isDirectory() || rootInfo.isSymbolicLink())
17
17
  throw new InstallationError('IntegrityMismatch', 'Browser installation root is not a regular directory');
@@ -26,6 +26,8 @@ export async function inventoryTree(root) {
26
26
  const absolute = path.join(directory, name);
27
27
  const info = await lstat(absolute);
28
28
  const mode = info.mode & 0o555;
29
+ if (relative === options.ignoreEmptyDirectory && info.isDirectory() && (await readdir(absolute)).length === 0)
30
+ continue;
29
31
  if (info.isSymbolicLink()) {
30
32
  const target = await readlink(absolute);
31
33
  try {
@@ -88,7 +90,11 @@ export async function verifyInstallation(root, buildId, platform, pin, executabl
88
90
  if (marker.schema !== 1 || marker.buildId !== buildId || marker.platform !== platform || marker.archiveSha256 !== pin.sha256 || marker.archiveUrl !== pin.url || marker.executablePath !== executablePath || !Array.isArray(marker.inventory) || marker.inventorySha256 !== fingerprint(marker.inventory))
89
91
  throw new Error('Installation inventory does not match the pinned release');
90
92
  await validateExecutable(root, executablePath);
91
- const actual = await inventoryTree(root);
93
+ // The marker is always written from a strict inventory (createMarker).
94
+ // Chrome's archive never ships `extensions/`; the leniency only covers the
95
+ // empty directory it creates beside the executable after the first launch.
96
+ const runtimeExtensions = path.posix.join(path.posix.dirname(executablePath), 'extensions');
97
+ const actual = await inventoryTree(root, { ignoreEmptyDirectory: runtimeExtensions });
92
98
  if (fingerprint(actual) !== marker.inventorySha256)
93
99
  throw new Error('Browser distribution resources have changed');
94
100
  return true;
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
+ /** Have the server watch every tab and solve full-page Cloudflare challenges. */
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 { 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)) {
@@ -288,6 +289,12 @@ export class Browser {
288
289
  if (expectedServerVersion !== undefined && transport.hello.serverVersion !== expectedServerVersion) {
289
290
  throw new ProtocolError(`Packaged server version mismatch: expected ${expectedServerVersion}, received ${transport.hello.serverVersion}`, { requestState: 'acknowledged' });
290
291
  }
292
+ const cloudflare = resolveCloudflareOptions(options.autoSolveCloudflare);
293
+ if (cloudflare !== undefined) {
294
+ if (!transport.hasCapability('cloudflareAutoSolve'))
295
+ throw new ConfigurationError('autoSolveCloudflare requires a server with the cloudflareAutoSolve capability');
296
+ params = { ...params, autoSolveCloudflare: cloudflare };
297
+ }
291
298
  const session = await transport.invoke(method, params, localOptions(options, deadline));
292
299
  if (!session || !['owned', 'borrowed'].includes(session.ownership) || typeof session.browserVersion !== 'string' || !session.browserVersion.trim() || (method === 'browser.connect' && session.ownership !== 'borrowed')) {
293
300
  throw new ProtocolError('Invalid browser session ownership or browserVersion', { requestState: 'acknowledged' });
@@ -0,0 +1,12 @@
1
+ /** Options for the server-side Cloudflare challenge watcher. */
2
+ export interface CloudflareOptions {
3
+ /** Poll interval in milliseconds. Defaults to 500. */
4
+ intervalMs?: number;
5
+ /** Deadline for each challenge solve. Defaults to 30000. */
6
+ timeoutMs?: number;
7
+ }
8
+ export interface ResolvedCloudflareOptions {
9
+ intervalMs: number;
10
+ timeoutMs: number;
11
+ }
12
+ export declare function resolveCloudflareOptions(value: boolean | CloudflareOptions | undefined): ResolvedCloudflareOptions | undefined;
@@ -0,0 +1,19 @@
1
+ import { ConfigurationError } from './errors.js';
2
+ export function resolveCloudflareOptions(value) {
3
+ if (value === undefined || value === false)
4
+ return undefined;
5
+ const options = value === true ? {} : value;
6
+ for (const name of Object.keys(options)) {
7
+ if (name !== 'intervalMs' && name !== 'timeoutMs')
8
+ throw new ConfigurationError(`autoSolveCloudflare.${name} is not supported; the server solves challenges and reports them in its log`);
9
+ }
10
+ const intervalMs = options.intervalMs ?? 500;
11
+ const timeoutMs = options.timeoutMs ?? 30_000;
12
+ if (!Number.isInteger(intervalMs) || intervalMs < 100 || intervalMs > 60_000) {
13
+ throw new ConfigurationError('autoSolveCloudflare.intervalMs must be an integer between 100 and 60000 milliseconds');
14
+ }
15
+ if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 120_000) {
16
+ throw new ConfigurationError('autoSolveCloudflare.timeoutMs must be an integer between 1 and 120000 milliseconds');
17
+ }
18
+ return { intervalMs, timeoutMs };
19
+ }