@orkestrel/browser 0.0.14 → 0.0.16

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.
@@ -1,22 +1,31 @@
1
- import { BrowserContextInterface } from '@orkestrel/browser';
2
- import { BrowserContextOptions } from '@orkestrel/browser';
1
+ import type { BrowserContextInterface } from '@orkestrel/browser';
2
+ import type { BrowserContextOptions } from '@orkestrel/browser';
3
3
  import { BrowserError } from '@orkestrel/browser';
4
- import { BrowserPageInterface } from '@orkestrel/browser';
5
- import { BrowserPageOptions } from '@orkestrel/browser';
6
- import { BrowserViewport } from '@orkestrel/browser';
7
- import { CDPTarget } from '@orkestrel/browser';
8
- import { CDPTransportEventMap } from '@orkestrel/browser';
9
- import { CDPTransportEventMap as CDPTransportEventMap_2 } from '@orkestrel/browser';
10
- import { CDPTransportInterface } from '@orkestrel/browser';
11
- import { CDPTransportInterface as CDPTransportInterface_2 } from '@orkestrel/browser';
12
- import { ChildProcess } from 'node:child_process';
13
- import { EmitterErrorHandler } from '@orkestrel/emitter';
14
- import { EmitterHooks } from '@orkestrel/emitter';
15
- import { EmitterInterface } from '@orkestrel/emitter';
16
- import { ScreenshotWriterInterface } from '@orkestrel/browser';
4
+ import type { BrowserPageInterface } from '@orkestrel/browser';
5
+ import type { BrowserPageOptions } from '@orkestrel/browser';
6
+ import type { BrowserViewport } from '@orkestrel/browser';
7
+ import type { BrowserWriterInterface } from '@orkestrel/browser';
8
+ import type { CDPTarget } from '@orkestrel/browser';
9
+ import type { CDPTransportEventMap } from '@orkestrel/browser';
10
+ import type { CDPTransportInterface } from '@orkestrel/browser';
11
+ import type { ChildProcess } from 'node:child_process';
12
+ import type { EmitterErrorHandler } from '@orkestrel/emitter';
13
+ import type { EmitterHooks } from '@orkestrel/emitter';
14
+ import type { EmitterInterface } from '@orkestrel/emitter';
15
+ import type { Result } from '@orkestrel/contract';
17
16
 
18
17
  /**
19
18
  * Discovers, launches, connects to, and owns Chromium-family browser sessions.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { Browser } from '@orkestrel/browser/server'
23
+ *
24
+ * const browser = new Browser({ headless: true })
25
+ * await browser.connect()
26
+ * const page = await browser.create({ url: 'https://example.com' })
27
+ * await browser.destroy()
28
+ * ```
20
29
  */
21
30
  export declare class Browser implements BrowserInterface {
22
31
  #private;
@@ -26,7 +35,6 @@ export declare class Browser implements BrowserInterface {
26
35
  get status(): BrowserStatus;
27
36
  get connection(): BrowserConnection | undefined;
28
37
  get owned(): boolean | undefined;
29
- get connected(): boolean;
30
38
  get pid(): number | undefined;
31
39
  discover(): Promise<BrowserDiscoveryResult>;
32
40
  connect(): Promise<void>;
@@ -40,83 +48,135 @@ export declare class Browser implements BrowserInterface {
40
48
  close(): Promise<void>;
41
49
  }
42
50
 
43
- /** Path appended to the CDP host to list open targets (pages, workers, etc). */
51
+ /**
52
+ * Names the path appended to the CDP host to list open targets — pages, workers, and every
53
+ * other target category Chromium reports — `'/json/list'`.
54
+ */
44
55
  export declare const BROWSER_CDP_LIST_PATH = "/json/list";
45
56
 
46
- /** Protocol prefix for CDP discovery requests. */
57
+ /** Names the protocol prefix for CDP discovery requests, `'http'`. */
47
58
  export declare const BROWSER_CDP_PROTOCOL = "http";
48
59
 
49
- /** Path appended to the CDP host to fetch version metadata (endpoint discovery). */
60
+ /**
61
+ * Names the path appended to the CDP host to fetch version metadata, `'/json/version'`, which
62
+ * is where endpoint discovery reads.
63
+ */
50
64
  export declare const BROWSER_CDP_VERSION_PATH = "/json/version";
51
65
 
52
- /** Default CDP port probed for an existing browser and used for launches. */
66
+ /**
67
+ * Sets the default CDP port probed for an existing browser and used for launches, `9222`.
68
+ */
53
69
  export declare const BROWSER_DEFAULT_CDP_PORT = 9222;
54
70
 
55
- /** Default host probed for an existing browser and used for launches (avoids `localhost` resolving to `::1` when Chromium binds `127.0.0.1`). */
71
+ /**
72
+ * Sets the default host probed for an existing browser and used for launches, `'127.0.0.1'`,
73
+ * which avoids `localhost` resolving to `::1` when Chromium binds `127.0.0.1`.
74
+ */
56
75
  export declare const BROWSER_DEFAULT_HOST = "127.0.0.1";
57
76
 
58
77
  /**
59
- * Case-insensitive substrings identifying an executable path/name's browser
78
+ * Lists the case-insensitive substrings identifying an executable path/name's browser
60
79
  * engine, checked by `parseBrowserEngine` in the order `edge` → `chromium` → `chrome`.
61
80
  */
62
81
  export declare const BROWSER_ENGINE_HINTS: Readonly<Record<BrowserEngine, readonly string[]>>;
63
82
 
64
- /** Environment variables checked (in order) for an explicit browser executable path override. */
83
+ /**
84
+ * Lists the environment variables checked, in order, for an explicit browser executable path
85
+ * override: `PLAYWRIGHT_EXECUTABLE_PATH`, then `CHROME_PATH`.
86
+ */
65
87
  export declare const BROWSER_ENV_PATH_KEYS: readonly string[];
66
88
 
67
- /** Command names probed on PATH when no well-known executable path exists. */
89
+ /** Lists the command names probed on PATH when no well-known executable path exists. */
68
90
  export declare const BROWSER_EXECUTABLE_NAMES: readonly string[];
69
91
 
70
- /** Well-known Chrome/Chromium/Edge executable paths with no platform-specific root, keyed by `process.platform`. */
92
+ /**
93
+ * Lists the well-known Chrome/Chromium/Edge executable paths with no platform-specific root,
94
+ * keyed by `process.platform`, leaving `win32` empty because its roots come from
95
+ * `BROWSER_WINDOWS_SUFFIXES`.
96
+ */
71
97
  export declare const BROWSER_EXECUTABLE_PATHS: Readonly<Record<string, readonly string[]>>;
72
98
 
73
- /** Flag enabling headless mode on a launched browser process. */
99
+ /**
100
+ * Names the flag that enables headless mode on a launched browser process, `'--headless=new'`.
101
+ */
74
102
  export declare const BROWSER_HEADLESS_ARG = "--headless=new";
75
103
 
76
- /** Bound for each launched-process exit window during TERM-to-KILL teardown. */
104
+ /**
105
+ * Bounds each launched-process exit window during TERM-to-KILL teardown at `3_000`
106
+ * milliseconds.
107
+ */
77
108
  export declare const BROWSER_KILL_GRACE_MS = 3000;
78
109
 
79
- /** Flags always passed to a launched browser process, alongside the caller's own. */
110
+ /** Lists the flags always passed to a launched browser process, alongside the caller's own. */
80
111
  export declare const BROWSER_LAUNCH_ARGS: readonly string[];
81
112
 
82
- /** Bound for the `discover: false` port-occupancy probe before launching — short, since it only needs to detect an already-listening CDP endpoint, not perform full discovery. */
113
+ /**
114
+ * Bounds the `discover: false` port-occupancy probe before launching at `200` milliseconds,
115
+ * which is short because the probe only needs to detect an already-listening CDP endpoint
116
+ * rather than perform full discovery.
117
+ */
83
118
  export declare const BROWSER_PORT_PROBE_TIMEOUT_MS = 200;
84
119
 
85
- /** Machine-readable error-context cause for an owned browser process exiting. */
120
+ /**
121
+ * Names the machine-readable error-context cause for an owned browser process exiting,
122
+ * `'process-exit'`.
123
+ */
86
124
  export declare const BROWSER_PROCESS_EXIT_CAUSE = "process-exit";
87
125
 
88
- /** Prefix for isolated browser profiles created beneath the operating-system temp directory. */
126
+ /**
127
+ * Names the prefix for isolated browser profiles created beneath the operating-system temp
128
+ * directory, `'orkestrel-browser-'`.
129
+ */
89
130
  export declare const BROWSER_PROFILE_PREFIX = "orkestrel-browser-";
90
131
 
91
- /** Per-OS default Playwright browser cache directory, relative to the home directory (win32 uses `LOCALAPPDATA` directly). */
132
+ /** Names the per-OS default Playwright browser cache directory, relative to the home directory (win32 uses `LOCALAPPDATA` directly). */
92
133
  export declare const BROWSER_STORE_CACHE_DIRS: Readonly<Record<string, string>>;
93
134
 
94
- /** Well-known Playwright browser store base directories checked in addition to `PLAYWRIGHT_BROWSERS_PATH`. */
135
+ /**
136
+ * Lists the well-known Playwright browser store base directories checked in addition to
137
+ * `PLAYWRIGHT_BROWSERS_PATH`, starting with `/opt/pw-browsers`.
138
+ */
95
139
  export declare const BROWSER_STORE_DEFAULT_DIRS: readonly string[];
96
140
 
97
- /** Environment variable naming an additional Playwright browser store base directory. */
141
+ /**
142
+ * Names the environment variable that carries an additional Playwright browser store base
143
+ * directory, `'PLAYWRIGHT_BROWSERS_PATH'`.
144
+ */
98
145
  export declare const BROWSER_STORE_ENV_KEY = "PLAYWRIGHT_BROWSERS_PATH";
99
146
 
100
- /** Glob pattern (relative to a store base) matching a versioned Chromium binary, keyed by `process.platform`. */
147
+ /** Names the glob pattern (relative to a store base) matching a versioned Chromium binary, keyed by `process.platform`. */
101
148
  export declare const BROWSER_STORE_GLOBS: Readonly<Record<string, string>>;
102
149
 
103
- /** Name of the top-level Chromium symlink/binary Playwright maintains inside a browser store base. */
150
+ /**
151
+ * Names the top-level Chromium symlink or binary Playwright maintains inside a browser store
152
+ * base, `'chromium'`.
153
+ */
104
154
  export declare const BROWSER_STORE_LINK_NAME = "chromium";
105
155
 
106
- /** Machine-readable error-context cause for a CDP transport disconnecting while its browser remains alive. */
156
+ /**
157
+ * Names the machine-readable error-context cause for a CDP transport disconnecting while its
158
+ * browser remains alive, `'transport-loss'`.
159
+ */
107
160
  export declare const BROWSER_TRANSPORT_LOSS_CAUSE = "transport-loss";
108
161
 
109
- /** Brief defer applied once when a transport loss is observed on an owned process, giving a near-simultaneous process-exit event (which libuv may reap slightly later than the socket close) first say over the diagnosis. */
162
+ /**
163
+ * Defers once for `50` milliseconds when a transport loss is observed on an owned process,
164
+ * giving a near-simultaneous process-exit event, which libuv may reap slightly later than the
165
+ * socket close, first say over the diagnosis.
166
+ */
110
167
  export declare const BROWSER_TRANSPORT_LOSS_DEFER_MS = 50;
111
168
 
112
- /** Fallback Windows install roots used when the corresponding environment variable is absent. */
169
+ /**
170
+ * Lists the fallback Windows install roots used when `PROGRAMFILES`, `PROGRAMFILES(X86)`, or
171
+ * `LOCALAPPDATA` is absent.
172
+ */
113
173
  export declare const BROWSER_WINDOWS_ROOT_FALLBACKS: Readonly<Record<string, string>>;
114
174
 
115
- /** Windows install-root-relative suffixes for Chrome/Edge/Chromium, joined against each candidate root (`PROGRAMFILES`, `PROGRAMFILES(X86)`, `LOCALAPPDATA`). */
175
+ /** Lists the Windows install-root-relative suffixes for Chrome/Edge/Chromium, joined against each candidate root (`PROGRAMFILES`, `PROGRAMFILES(X86)`, `LOCALAPPDATA`). */
116
176
  export declare const BROWSER_WINDOWS_SUFFIXES: readonly string[];
117
177
 
118
178
  /**
119
- * CDP (Chrome DevTools Protocol) connection configuration.
179
+ * Configures the CDP (Chrome DevTools Protocol) connection.
120
180
  *
121
181
  * @remarks
122
182
  * - `port` — port number to probe for an existing CDP endpoint (default `9222`)
@@ -137,47 +197,46 @@ export declare interface BrowserCDPOptions {
137
197
  readonly discover?: boolean;
138
198
  }
139
199
 
140
- /** How the browser connection was established. */
200
+ /** Names how the browser connection was established. */
141
201
  export declare type BrowserConnection = 'cdp' | 'launch' | 'persistent';
142
202
 
143
203
  /**
144
- * A CDP connection, discovery, or launch attempt failed.
204
+ * Reports that a CDP connection, discovery, or launch attempt failed, under the code
205
+ * `BROWSER_CONNECTION_ERROR`.
145
206
  */
146
207
  export declare class BrowserConnectionError extends BrowserError {
147
208
  constructor(message: string, context?: Readonly<Record<string, unknown>>);
148
209
  }
149
210
 
150
211
  /**
151
- * An operation was attempted after the Browser was destroyed.
212
+ * Reports that an operation was attempted after the browser wrapper was destroyed, under the
213
+ * code `BROWSER_DESTROYED_ERROR`.
152
214
  */
153
215
  export declare class BrowserDestroyedError extends BrowserError {
154
216
  constructor(context?: Readonly<Record<string, unknown>>);
155
217
  }
156
218
 
157
219
  /**
158
- * Result of passive browser discovery.
220
+ * Describes the result of passive browser discovery.
159
221
  *
160
222
  * @remarks
161
223
  * Returned by `discover()` to report whether an existing browser is
162
- * reachable via CDP without actually connecting to it.
224
+ * reachable through CDP without actually connecting to it. A defined
225
+ * `endpoint` is the whole answer — no separate flag repeats it.
163
226
  *
164
- * - `found` — true when a browser responded on the CDP endpoint
165
- * - `endpoint` — the CDP WebSocket URL when found
227
+ * - `endpoint` — the CDP WebSocket URL, or undefined when nothing answered
166
228
  * - `browser` — browser product name reported by the endpoint
167
- * - `connection` — the connection mode that would be used
168
229
  */
169
230
  export declare interface BrowserDiscoveryResult {
170
- readonly found: boolean;
171
231
  readonly endpoint: string | undefined;
172
232
  readonly browser: string | undefined;
173
- readonly connection: BrowserConnection | undefined;
174
233
  }
175
234
 
176
- /** Supported browser engine (raw CDP targets Chromium-family browsers only). */
235
+ /** Names a supported browser engine (raw CDP targets Chromium-family browsers only). */
177
236
  export declare type BrowserEngine = 'chromium' | 'chrome' | 'edge';
178
237
 
179
238
  /**
180
- * Event map for a {@link BrowserInterface}.
239
+ * Maps the events a {@link BrowserInterface} emits.
181
240
  *
182
241
  * @remarks
183
242
  * - `idle` — no active connection (initial state, or after disconnect)
@@ -187,7 +246,8 @@ export declare type BrowserEngine = 'chromium' | 'chrome' | 'edge';
187
246
  * an external disconnect (process exit or transport loss); always preceded
188
247
  * by a coded `error` describing the cause
189
248
  * - `launch` — a new browser process was launched, carrying the engine
190
- * - `page` — a new page was created via the `create()` shortcut
249
+ * - `page` — a new page was created through the `create()` shortcut
250
+ * - `context` — an isolated browser context was created, carrying the context
191
251
  * - `error` — a connection or launch fault
192
252
  * - `destroy` — the browser and all resources were torn down
193
253
  */
@@ -204,13 +264,13 @@ export declare type BrowserEventMap = {
204
264
  };
205
265
 
206
266
  /**
207
- * Browser wrapper with discovery, connection management, and lifecycle control.
267
+ * Wraps a browser with discovery, connection management, and lifecycle control.
208
268
  *
209
269
  * @remarks
210
270
  * Encapsulates the full raw-CDP browser lifecycle behind a clean interface:
211
271
  *
212
272
  * **Connection strategy** (executed by `connect()`):
213
- * 1. If `cdp.endpoint` is set, connect directly via CDP
273
+ * 1. If `cdp.endpoint` is set, connect directly through CDP
214
274
  * 2. Probe `localhost:{cdp.port}` for an existing browser (passive discovery)
215
275
  * 3. If found, connect over CDP (preserves the existing browser session)
216
276
  * 4. Otherwise, launch a new browser process with raw-CDP flags
@@ -234,9 +294,9 @@ export declare type BrowserEventMap = {
234
294
  * pages/contexts, then kills and awaits the process serving the CDP endpoint
235
295
  * plus its POSIX process group. On an adopted browser it sends
236
296
  * `Browser.close`. On a merely
237
- * attached browser this is a LOCAL DETACH ONLY because other clients may
297
+ * attached browser this is a local detach only, because other clients may
238
298
  * share its targets. Idempotent.
239
- * - `close` — graceful REMOTE shutdown: best-effort sends CDP `Browser.close`
299
+ * - `close` — graceful remote shutdown: best-effort sends CDP `Browser.close`
240
300
  * (works whether attached or owned), and when owned also awaits the exit of
241
301
  * the process serving the CDP endpoint plus its POSIX process-group drain
242
302
  * (escalating to a kill only if needed), then performs the same local cleanup
@@ -246,6 +306,8 @@ export declare type BrowserEventMap = {
246
306
  * **Page management:**
247
307
  * - `context(index?)` → one context or first
248
308
  * - `contexts()` → all contexts
309
+ * - `isolate` — create and register an isolated CDP context with validated
310
+ * proxy, download, origin, and emulation options
249
311
  * - `create(options?)` → shortcut to open a page in the default context
250
312
  */
251
313
  export declare interface BrowserInterface {
@@ -254,16 +316,15 @@ export declare interface BrowserInterface {
254
316
  readonly status: BrowserStatus;
255
317
  readonly connection: BrowserConnection | undefined;
256
318
  /**
257
- * Whether this instance is responsible for terminating the represented browser.
319
+ * Reports whether this instance is responsible for terminating the represented browser.
258
320
  *
259
321
  * @remarks
260
322
  * `true` for launched and explicitly adopted sessions, `false` for an
261
323
  * active attachment, and `undefined` when no session is represented.
262
324
  */
263
325
  readonly owned: boolean | undefined;
264
- readonly connected: boolean;
265
326
  /**
266
- * The process serving this session's CDP endpoint, if any, while it is
327
+ * Reports the process serving this session's CDP endpoint, if any, while it is
267
328
  * believed alive.
268
329
  *
269
330
  * @remarks
@@ -276,28 +337,68 @@ export declare interface BrowserInterface {
276
337
  * until `destroy()` or an observed process exit clears it.
277
338
  */
278
339
  readonly pid: number | undefined;
340
+ /**
341
+ * Probes CDP passively, changing no connection state and neither launching nor attaching,
342
+ * and emits a `discover` event with the result.
343
+ */
279
344
  discover(): Promise<BrowserDiscoveryResult>;
345
+ /**
346
+ * Establishes a connection through the endpoint, then discovery, then a launch.
347
+ * Idempotent.
348
+ */
280
349
  connect(): Promise<void>;
281
- /** Assume responsibility for terminating the currently connected browser. */
350
+ /** Assumes responsibility for terminating the connected browser. */
282
351
  adopt(): void;
352
+ /**
353
+ * Detaches the client-side transport while the remote browser keeps running. A merely
354
+ * attached CDP session forgets the endpoint and its ownership becomes `undefined`. A
355
+ * launched or explicitly adopted session retains ownership and its endpoint, so the same
356
+ * instance can reconnect and stays responsible for eventual termination. Transport loss
357
+ * while an owned browser remains alive is resumable the same way.
358
+ */
283
359
  disconnect(): Promise<void>;
360
+ /** Returns one context by index, or the first. */
284
361
  context(index?: number): BrowserContextInterface | undefined;
362
+ /** Returns every context. */
285
363
  contexts(): readonly BrowserContextInterface[];
364
+ /**
365
+ * Creates and registers an isolated CDP context with validated proxy, download, origin,
366
+ * and emulation options.
367
+ */
286
368
  isolate(options?: BrowserContextOptions): Promise<BrowserContextInterface>;
369
+ /** Opens a page in the default context. */
287
370
  create(options?: BrowserPageOptions): Promise<BrowserPageInterface>;
371
+ /**
372
+ * Releases local resources. A launched browser has the process serving its CDP endpoint
373
+ * terminated and its exit awaited — on POSIX that terminate reaches the launch's whole
374
+ * process group and awaits its drain, and on Windows it terminates one process by
375
+ * identifier, the spawned process or the one a launcher handed the endpoint to — which
376
+ * leaves the profile unlocked before cleanup. An adopted attachment is sent CDP
377
+ * `Browser.close`. A merely attached browser is detached locally and nothing more, because
378
+ * other clients may share its targets. Idempotent.
379
+ */
288
380
  destroy(): Promise<void>;
381
+ /**
382
+ * Shuts the remote browser down: sends CDP `Browser.close` best-effort whether attached or
383
+ * owned, and for an owned browser also awaits the exit of the process serving the CDP
384
+ * endpoint plus its POSIX process-group drain, escalating to a kill only where needed.
385
+ * Then closes every tracked context and page, sending remote `Target.closeTarget` and
386
+ * `disposeBrowserContext` whatever the ownership, before releasing the CDP client. This is
387
+ * the way to shut down a browser the instance does not own and still wants terminated.
388
+ */
289
389
  close(): Promise<void>;
290
390
  }
291
391
 
292
392
  /**
293
- * An operation requiring an active connection was attempted while disconnected.
393
+ * Reports that an operation requiring an active connection was attempted while disconnected,
394
+ * under the code `BROWSER_NOT_CONNECTED_ERROR`.
294
395
  */
295
396
  export declare class BrowserNotConnectedError extends BrowserError {
296
397
  constructor(context?: Readonly<Record<string, unknown>>);
297
398
  }
298
399
 
299
400
  /**
300
- * Options for creating a Browser.
401
+ * Describes the options for creating a `Browser` instance.
301
402
  *
302
403
  * @remarks
303
404
  * - `on` — initial event listeners wired at construction
@@ -334,7 +435,7 @@ export declare interface BrowserOptions {
334
435
  }
335
436
 
336
437
  /**
337
- * Resolved browser profile directory used for a Chromium-family launch.
438
+ * Describes the resolved browser profile directory used for a Chromium-family launch.
338
439
  *
339
440
  * @remarks
340
441
  * `temporary` is true only for an isolated profile created by
@@ -346,30 +447,44 @@ export declare interface BrowserProfileResult {
346
447
  readonly temporary: boolean;
347
448
  }
348
449
 
349
- /** Lifecycle status of a browser wrapper. */
450
+ /** Names the lifecycle status of a browser wrapper. */
350
451
  export declare type BrowserStatus = 'idle' | 'connecting' | 'connected' | 'disconnected' | 'error';
351
452
 
352
- /** Classify a `/json/version` `Browser` string into a {@link BrowserEngine} (`Edg/` → edge, `Chrome/` → chrome, else chromium). */
453
+ /** Classifies a `/json/version` `Browser` string into a {@link BrowserEngine} (`Edg/` → edge, `Chrome/` → chrome, else chromium). */
353
454
  export declare function browserToEngine(browser?: string): BrowserEngine;
354
455
 
456
+ /** Builds the default well-known install-path candidates for a platform, deriving Windows roots from env vars. */
457
+ export declare function buildInstallPaths(platform: string, env: Readonly<Record<string, string | undefined>>): readonly string[];
458
+
459
+ /** Builds the default Playwright browser store base directories to search for a managed Chromium. */
460
+ export declare function buildStoreBases(env: Readonly<Record<string, string | undefined>>, platform: string): readonly string[];
461
+
462
+ /** Derives Windows install roots from env vars, falling back to well-known literals when absent. */
463
+ export declare function buildWindowsRoots(env: Readonly<Record<string, string | undefined>>): readonly string[];
464
+
355
465
  /**
356
- * Create a raw-CDP Browser façade.
466
+ * Creates a raw-CDP `BrowserInterface` façade with discovery, connection, and lifecycle
467
+ * management.
357
468
  *
358
469
  * @param options - Connection, launch, and viewport configuration
359
470
  * @returns A {@link BrowserInterface}
360
471
  *
361
- * @example
472
+ * @example Connect to a browser and drive a page
362
473
  * ```ts
363
- * import { createBrowser } from '@src/server'
364
- *
365
- * const browser = createBrowser()
366
- * await browser.connect()
474
+ * import { createBrowser } from '@orkestrel/browser/server'
475
+ *
476
+ * const browser = createBrowser({ headless: true })
477
+ * await browser.connect() // CDP endpoint discovery → connect, else launch
478
+ * const page = await browser.create({ url: 'https://example.com' })
479
+ * await page.click('#accept')
480
+ * const shot = await page.screenshot({ path: './out.png' })
481
+ * await browser.destroy()
367
482
  * ```
368
483
  */
369
484
  export declare function createBrowser(options?: BrowserOptions): BrowserInterface;
370
485
 
371
486
  /**
372
- * Resolve a persistent caller profile or create an isolated temporary one.
487
+ * Resolves a persistent caller profile or creates an isolated temporary one.
373
488
  *
374
489
  * @param path - Optional caller-owned persistent user-data directory
375
490
  * @returns The resolved profile and whether the library owns its lifecycle
@@ -377,56 +492,84 @@ export declare function createBrowser(options?: BrowserOptions): BrowserInterfac
377
492
  export declare function createBrowserProfile(path?: string): Promise<BrowserProfileResult>;
378
493
 
379
494
  /**
380
- * Create a Node `WebSocket`-backed CDP transport.
495
+ * Creates a filesystem-backed `BrowserWriterInterface` that persists bytes through
496
+ * `node:fs/promises`.
381
497
  *
382
- * @param options - The CDP WebSocket debugger URL (and optional timeout)
383
- * @returns A {@link CDPTransportInterface}
498
+ * @returns A {@link BrowserWriterInterface} that persists bytes through `node:fs/promises`
384
499
  */
385
- export declare function createCDPTransport(options: WebSocketCDPTransportOptions): CDPTransportInterface_2;
500
+ export declare function createBrowserWriter(): BrowserWriterInterface;
386
501
 
387
502
  /**
388
- * Create a filesystem-backed screenshot writer.
503
+ * Creates a Node `WebSocket`-backed `CDPTransportInterface` for the given CDP debugger URL.
389
504
  *
390
- * @returns A {@link ScreenshotWriterInterface} that persists bytes via `node:fs/promises`
505
+ * @param options - The CDP WebSocket debugger URL (and optional timeout)
506
+ * @returns A {@link CDPTransportInterface}
391
507
  */
392
- export declare function createScreenshotWriter(): ScreenshotWriterInterface;
393
-
394
- /** Build the default well-known install-path candidates for a platform, deriving Windows roots from env vars. */
395
- export declare function defaultInstallPaths(platform: string, env: Readonly<Record<string, string | undefined>>): readonly string[];
396
-
397
- /** Build the default Playwright browser store base directories to search for a managed Chromium. */
398
- export declare function defaultStoreBases(env: Readonly<Record<string, string | undefined>>, platform: string): readonly string[];
508
+ export declare function createCDPTransport(options: WebSocketCDPTransportOptions): CDPTransportInterface;
399
509
 
400
510
  /**
401
- * Fetch the current CDP target list from a browser's `/json/list` endpoint.
511
+ * Fetches the current CDP target list from a browser's `/json/list` endpoint, as a `Result`
512
+ * carrying either the targets or a coded `BrowserConnectionError`.
513
+ *
514
+ * @remarks
515
+ * The endpoint is a network boundary, so an unreachable host, a non-2xx
516
+ * response, and a body that is not a JSON array each come back as a failed
517
+ * `Result` carrying a coded `BrowserConnectionError`. An entry missing a
518
+ * required string field is skipped rather than failing the whole list.
402
519
  *
403
520
  * @param port - Port the browser exposes its CDP endpoint on
404
521
  * @param timeout - Request timeout in milliseconds
405
522
  * @param host - Host the browser exposes its CDP endpoint on (default `127.0.0.1`)
406
- * @returns Normalized CDP targets
523
+ * @returns The normalized CDP targets, or the fault that stopped the request
524
+ *
525
+ * @example
526
+ * ```ts
527
+ * import { fetchCDPTargets } from '@orkestrel/browser/server'
528
+ *
529
+ * const result = await fetchCDPTargets(9222, 2000)
530
+ * if (result.success) log(result.value.length)
531
+ * else log(result.error.code)
532
+ * ```
407
533
  */
408
- export declare function fetchCDPTargets(port: number, timeout: number, host?: string): Promise<readonly CDPTarget[]>;
409
-
410
- /** Check the env-override keys (`PLAYWRIGHT_EXECUTABLE_PATH`, `CHROME_PATH`) in order, returning every one that exists. */
411
- export declare function findAllEnvOverrides(env: Readonly<Record<string, string | undefined>>): readonly string[];
412
-
413
- /** Return every candidate path that exists on disk, in the given order. */
414
- export declare function findAllInstallPaths(paths: readonly string[]): readonly string[];
534
+ export declare function fetchCDPTargets(port: number, timeout: number, host?: string): Promise<Result<readonly CDPTarget[], BrowserError>>;
415
535
 
416
- /** Search one store base for the top-level `chromium` link and every `chromium-*` install, highest revision first. */
417
- export declare function findAllInStore(base: string, platform: string): readonly string[];
536
+ /**
537
+ * Persists captured browser bytes to the filesystem through `node:fs/promises`.
538
+ *
539
+ * @remarks
540
+ * Creates every missing parent directory of the target path before writing, so
541
+ * a caller may name a nested destination that does not exist yet.
542
+ *
543
+ * @example
544
+ * ```ts
545
+ * import { FileBrowserWriter } from '@orkestrel/browser/server'
546
+ *
547
+ * const writer = new FileBrowserWriter()
548
+ * await writer.write('shots/hero.png', new Uint8Array([137, 80, 78, 71]))
549
+ * ```
550
+ */
551
+ export declare class FileBrowserWriter implements BrowserWriterInterface {
552
+ /**
553
+ * Writes the captured bytes to a path, creating its parent directories.
554
+ *
555
+ * @param path - Destination file path
556
+ * @param data - Captured bytes to persist
557
+ * @returns A promise resolving once the bytes are on disk
558
+ */
559
+ write(path: string, data: Uint8Array): Promise<void>;
560
+ }
418
561
 
419
- /** Check the env-override keys (`PLAYWRIGHT_EXECUTABLE_PATH`, `CHROME_PATH`) in order for an existing file. */
420
- export declare function findEnvOverride(env: Readonly<Record<string, string | undefined>>): string | undefined;
562
+ /** Checks the env-override keys (`PLAYWRIGHT_EXECUTABLE_PATH`, `CHROME_PATH`) in order and returns every one that exists. */
563
+ export declare function findEnvOverrides(env: Readonly<Record<string, string | undefined>>): readonly string[];
421
564
 
422
- /** Return the first candidate path that exists on disk. */
423
- export declare function findInstallPath(paths: readonly string[]): string | undefined;
565
+ /** Returns every candidate path that exists on disk, in the given order. */
566
+ export declare function findInstallPaths(paths: readonly string[]): readonly string[];
424
567
 
425
- /** Search one store base for the top-level `chromium` link, else the highest-revision `chromium-*` install. */
426
- export declare function findInStore(base: string, platform: string): string | undefined;
568
+ /** Searches one store base for the top-level `chromium` link and every `chromium-*` install, highest revision first. */
569
+ export declare function findStorePaths(base: string, platform: string): readonly string[];
427
570
 
428
571
  /**
429
- * Locate a Chrome/Chromium/Edge executable on this machine — the first entry
572
+ * Locates a Chrome/Chromium/Edge executable on this machine — the first entry
430
573
  * of {@link findSystemBrowsers}.
431
574
  *
432
575
  * @param options - Overrides for the candidate sources; see {@link SystemBrowserOptions}
@@ -435,7 +578,7 @@ export declare function findInStore(base: string, platform: string): string | un
435
578
  export declare function findSystemBrowser(options?: SystemBrowserOptions): SystemBrowser | undefined;
436
579
 
437
580
  /**
438
- * Enumerate every Chrome/Chromium/Edge executable discoverable on this
581
+ * Enumerates every Chrome/Chromium/Edge executable discoverable on this
439
582
  * machine, deduplicated by normalized absolute path.
440
583
  *
441
584
  * @remarks
@@ -449,7 +592,7 @@ export declare function findSystemBrowser(options?: SystemBrowserOptions): Syste
449
592
  * and the per-OS Playwright cache directory) — the top-level `chromium`
450
593
  * link/binary, then the highest-revision `chromium-*` install found
451
594
  *
452
- * Each candidate is classified into a {@link BrowserEngine} via
595
+ * Each candidate is classified into a {@link BrowserEngine} through
453
596
  * `parseBrowserEngine` (unclassifiable candidates default to `'chromium'`),
454
597
  * and `options.engine` (when given) narrows the result to that engine.
455
598
  *
@@ -459,31 +602,31 @@ export declare function findSystemBrowser(options?: SystemBrowserOptions): Syste
459
602
  export declare function findSystemBrowsers(options?: SystemBrowserOptions): readonly SystemBrowser[];
460
603
 
461
604
  /**
462
- * Narrow an unknown value to BrowserConnectionError.
605
+ * Narrows an unknown value to a `BrowserConnectionError`.
463
606
  *
464
607
  * @param value - Value to check
465
- * @returns True when value is a BrowserConnectionError instance
608
+ * @returns True if value is a BrowserConnectionError instance; false otherwise
466
609
  */
467
610
  export declare function isBrowserConnectionError(value: unknown): value is BrowserConnectionError;
468
611
 
469
612
  /**
470
- * Narrow an unknown value to BrowserDestroyedError.
613
+ * Narrows an unknown value to a `BrowserDestroyedError`.
471
614
  *
472
615
  * @param value - Value to check
473
- * @returns True when value is a BrowserDestroyedError instance
616
+ * @returns True if value is a BrowserDestroyedError instance; false otherwise
474
617
  */
475
618
  export declare function isBrowserDestroyedError(value: unknown): value is BrowserDestroyedError;
476
619
 
477
620
  /**
478
- * Narrow an unknown value to BrowserNotConnectedError.
621
+ * Narrows an unknown value to a `BrowserNotConnectedError`.
479
622
  *
480
623
  * @param value - Value to check
481
- * @returns True when value is a BrowserNotConnectedError instance
624
+ * @returns True if value is a BrowserNotConnectedError instance; false otherwise
482
625
  */
483
626
  export declare function isBrowserNotConnectedError(value: unknown): value is BrowserNotConnectedError;
484
627
 
485
628
  /**
486
- * Launch a browser process with raw-CDP debugging flags.
629
+ * Launches a browser process with raw-CDP debugging flags.
487
630
  *
488
631
  * @remarks
489
632
  * POSIX launches own an isolated process group so lifecycle teardown can
@@ -503,11 +646,11 @@ export declare function isBrowserNotConnectedError(value: unknown): value is Bro
503
646
  */
504
647
  export declare function launchBrowserProcess(executable: string, port: number, headless: boolean, profile?: string, extra?: readonly string[]): ChildProcess;
505
648
 
506
- /** Normalize an executable path for cross-source deduplication (case-insensitive on Windows). */
649
+ /** Normalizes an executable path for cross-source deduplication (case-insensitive on Windows). */
507
650
  export declare function normalizeExecutablePath(path: string, platform: string): string;
508
651
 
509
652
  /**
510
- * Classify an executable path/name into a {@link BrowserEngine} by
653
+ * Classifies an executable path/name into a {@link BrowserEngine} by
511
654
  * case-insensitive hint, checked in the order edge → chromium → chrome.
512
655
  *
513
656
  * @param executable - Executable path or command name to classify
@@ -515,11 +658,8 @@ export declare function normalizeExecutablePath(path: string, platform: string):
515
658
  */
516
659
  export declare function parseBrowserEngine(executable: string): BrowserEngine | undefined;
517
660
 
518
- /** Probe PATH (`which`/`where`) for every resolvable command name, in the given order. */
519
- export declare function probeAllPathNames(names: readonly string[], platform: string): readonly string[];
520
-
521
- /** Probe PATH (`which`/`where`) for the first resolvable command name. */
522
- export declare function probePathNames(names: readonly string[], platform: string): string | undefined;
661
+ /** Probes PATH (`which`/`where`) for every resolvable command name, in the given order. */
662
+ export declare function probePathNames(names: readonly string[], platform: string): readonly string[];
523
663
 
524
664
  /**
525
665
  * Returns the first non-empty line of a command's output, without its
@@ -541,7 +681,7 @@ export declare function probePathNames(names: readonly string[], platform: strin
541
681
  export declare function readFirstLine(output: string): string | undefined;
542
682
 
543
683
  /**
544
- * Remove a library-owned isolated browser profile.
684
+ * Removes a library-owned isolated browser profile.
545
685
  *
546
686
  * @remarks
547
687
  * The path must remain a direct child of the operating-system temp directory
@@ -553,7 +693,7 @@ export declare function readFirstLine(output: string): string | undefined;
553
693
  export declare function removeBrowserProfile(profile: BrowserProfileResult): Promise<void>;
554
694
 
555
695
  /**
556
- * One discovered browser executable on this machine.
696
+ * Represents one discovered browser executable on this machine.
557
697
  *
558
698
  * @remarks
559
699
  * Returned by `findSystemBrowsers`/`findSystemBrowser` — pairs the resolved
@@ -565,7 +705,7 @@ export declare type SystemBrowser = {
565
705
  };
566
706
 
567
707
  /**
568
- * Options overriding `findSystemBrowsers`'/`findSystemBrowser`'s candidate sources.
708
+ * Describes the options overriding `findSystemBrowsers`'/`findSystemBrowser`'s candidate sources.
569
709
  *
570
710
  * @remarks
571
711
  * Each field replaces the default candidate list for its category — a field
@@ -594,11 +734,12 @@ export declare interface SystemBrowserOptions {
594
734
  }
595
735
 
596
736
  /**
597
- * Poll a browser's CDP version endpoint until it responds or the timeout elapses.
737
+ * Polls a browser's CDP version endpoint until it responds or the timeout elapses.
598
738
  *
599
739
  * @param port - Port the browser exposes its CDP endpoint on
600
740
  * @param timeout - Maximum time to wait in milliseconds
601
741
  * @param host - Host the browser exposes its CDP endpoint on (default `127.0.0.1`)
742
+ * @param signal - Optional external abort; an abort while waiting rethrows rather than resolving
602
743
  * @returns The browser's WebSocket debugger URL
603
744
  *
604
745
  * @throws When the endpoint does not become ready before the timeout
@@ -606,25 +747,34 @@ export declare interface SystemBrowserOptions {
606
747
  export declare function waitForCDPReady(port: number, timeout: number, host?: string, signal?: AbortSignal): Promise<string>;
607
748
 
608
749
  /**
609
- * `@orkestrel/websocket`-backed raw CDP text transport.
750
+ * Provides a raw CDP text transport backed by `@orkestrel/websocket`.
610
751
  *
611
752
  * @remarks
612
753
  * Performs and validates the RFC 6455 HTTP upgrade, then delegates frame
613
754
  * handling to `@orkestrel/websocket`. Concurrent and repeated `start()` /
614
755
  * `close()` calls share their active transition, and a later `start()` opens a
615
756
  * fresh socket after the prior one closes.
757
+ *
758
+ * @example
759
+ * ```ts
760
+ * import { WebSocketCDPTransport } from '@orkestrel/browser/server'
761
+ *
762
+ * const transport = new WebSocketCDPTransport({ url: 'ws://127.0.0.1:9222/devtools/browser/abc' })
763
+ * await transport.start()
764
+ * await transport.close()
765
+ * ```
616
766
  */
617
767
  export declare class WebSocketCDPTransport implements CDPTransportInterface {
618
768
  #private;
619
769
  constructor(options: WebSocketCDPTransportOptions);
620
- get emitter(): EmitterInterface<CDPTransportEventMap_2>;
770
+ get emitter(): EmitterInterface<CDPTransportEventMap>;
621
771
  start(): Promise<void>;
622
772
  send(data: string): Promise<void>;
623
773
  close(): Promise<void>;
624
774
  }
625
775
 
626
776
  /**
627
- * Options for creating a WebSocketCDPTransport.
777
+ * Describes the options for creating a `WebSocketCDPTransport` instance.
628
778
  *
629
779
  * @remarks
630
780
  * - `on` — initial event listeners wired at construction
@@ -639,7 +789,4 @@ export declare interface WebSocketCDPTransportOptions {
639
789
  readonly timeout?: number;
640
790
  }
641
791
 
642
- /** Derive Windows install roots from env vars, falling back to well-known literals when absent. */
643
- export declare function windowsRoots(env: Readonly<Record<string, string | undefined>>): readonly string[];
644
-
645
792
  export { }