@orkestrel/browser 0.0.15 → 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,21 +1,18 @@
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 { BrowserWriterInterface } from '@orkestrel/browser';
8
- import { BrowserWriterInterface as BrowserWriterInterface_2 } from '@orkestrel/browser';
9
- import { CDPTarget } from '@orkestrel/browser';
10
- import { CDPTransportEventMap } from '@orkestrel/browser';
11
- import { CDPTransportEventMap as CDPTransportEventMap_2 } from '@orkestrel/browser';
12
- import { CDPTransportInterface } from '@orkestrel/browser';
13
- import { CDPTransportInterface as CDPTransportInterface_2 } from '@orkestrel/browser';
14
- import { ChildProcess } from 'node:child_process';
15
- import { EmitterErrorHandler } from '@orkestrel/emitter';
16
- import { EmitterHooks } from '@orkestrel/emitter';
17
- import { EmitterInterface } from '@orkestrel/emitter';
18
- import { Result } from '@orkestrel/contract';
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';
19
16
 
20
17
  /**
21
18
  * Discovers, launches, connects to, and owns Chromium-family browser sessions.
@@ -51,19 +48,30 @@ export declare class Browser implements BrowserInterface {
51
48
  close(): Promise<void>;
52
49
  }
53
50
 
54
- /** Names the 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
+ */
55
55
  export declare const BROWSER_CDP_LIST_PATH = "/json/list";
56
56
 
57
- /** Names the protocol prefix for CDP discovery requests. */
57
+ /** Names the protocol prefix for CDP discovery requests, `'http'`. */
58
58
  export declare const BROWSER_CDP_PROTOCOL = "http";
59
59
 
60
- /** Names the 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
+ */
61
64
  export declare const BROWSER_CDP_VERSION_PATH = "/json/version";
62
65
 
63
- /** Sets the 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
+ */
64
69
  export declare const BROWSER_DEFAULT_CDP_PORT = 9222;
65
70
 
66
- /** Sets the 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
+ */
67
75
  export declare const BROWSER_DEFAULT_HOST = "127.0.0.1";
68
76
 
69
77
  /**
@@ -72,55 +80,96 @@ export declare const BROWSER_DEFAULT_HOST = "127.0.0.1";
72
80
  */
73
81
  export declare const BROWSER_ENGINE_HINTS: Readonly<Record<BrowserEngine, readonly string[]>>;
74
82
 
75
- /** Lists the 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
+ */
76
87
  export declare const BROWSER_ENV_PATH_KEYS: readonly string[];
77
88
 
78
89
  /** Lists the command names probed on PATH when no well-known executable path exists. */
79
90
  export declare const BROWSER_EXECUTABLE_NAMES: readonly string[];
80
91
 
81
- /** Lists the 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
+ */
82
97
  export declare const BROWSER_EXECUTABLE_PATHS: Readonly<Record<string, readonly string[]>>;
83
98
 
84
- /** Names the flag that enables headless mode on a launched browser process. */
99
+ /**
100
+ * Names the flag that enables headless mode on a launched browser process, `'--headless=new'`.
101
+ */
85
102
  export declare const BROWSER_HEADLESS_ARG = "--headless=new";
86
103
 
87
- /** Bounds 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
+ */
88
108
  export declare const BROWSER_KILL_GRACE_MS = 3000;
89
109
 
90
110
  /** Lists the flags always passed to a launched browser process, alongside the caller's own. */
91
111
  export declare const BROWSER_LAUNCH_ARGS: readonly string[];
92
112
 
93
- /** Bounds the `discover: false` port-occupancy probe before launching — short, because 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
+ */
94
118
  export declare const BROWSER_PORT_PROBE_TIMEOUT_MS = 200;
95
119
 
96
- /** Names the 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
+ */
97
124
  export declare const BROWSER_PROCESS_EXIT_CAUSE = "process-exit";
98
125
 
99
- /** Names the 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
+ */
100
130
  export declare const BROWSER_PROFILE_PREFIX = "orkestrel-browser-";
101
131
 
102
132
  /** Names the per-OS default Playwright browser cache directory, relative to the home directory (win32 uses `LOCALAPPDATA` directly). */
103
133
  export declare const BROWSER_STORE_CACHE_DIRS: Readonly<Record<string, string>>;
104
134
 
105
- /** Lists the 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
+ */
106
139
  export declare const BROWSER_STORE_DEFAULT_DIRS: readonly string[];
107
140
 
108
- /** Names the environment variable that carries 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
+ */
109
145
  export declare const BROWSER_STORE_ENV_KEY = "PLAYWRIGHT_BROWSERS_PATH";
110
146
 
111
147
  /** Names the glob pattern (relative to a store base) matching a versioned Chromium binary, keyed by `process.platform`. */
112
148
  export declare const BROWSER_STORE_GLOBS: Readonly<Record<string, string>>;
113
149
 
114
- /** Names 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
+ */
115
154
  export declare const BROWSER_STORE_LINK_NAME = "chromium";
116
155
 
117
- /** Names the 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
+ */
118
160
  export declare const BROWSER_TRANSPORT_LOSS_CAUSE = "transport-loss";
119
161
 
120
- /** Defers once, briefly, 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
+ */
121
167
  export declare const BROWSER_TRANSPORT_LOSS_DEFER_MS = 50;
122
168
 
123
- /** Lists the 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
+ */
124
173
  export declare const BROWSER_WINDOWS_ROOT_FALLBACKS: Readonly<Record<string, string>>;
125
174
 
126
175
  /** Lists the Windows install-root-relative suffixes for Chrome/Edge/Chromium, joined against each candidate root (`PROGRAMFILES`, `PROGRAMFILES(X86)`, `LOCALAPPDATA`). */
@@ -152,14 +201,16 @@ export declare interface BrowserCDPOptions {
152
201
  export declare type BrowserConnection = 'cdp' | 'launch' | 'persistent';
153
202
 
154
203
  /**
155
- * Reports that 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`.
156
206
  */
157
207
  export declare class BrowserConnectionError extends BrowserError {
158
208
  constructor(message: string, context?: Readonly<Record<string, unknown>>);
159
209
  }
160
210
 
161
211
  /**
162
- * Reports that 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`.
163
214
  */
164
215
  export declare class BrowserDestroyedError extends BrowserError {
165
216
  constructor(context?: Readonly<Record<string, unknown>>);
@@ -243,9 +294,9 @@ export declare type BrowserEventMap = {
243
294
  * pages/contexts, then kills and awaits the process serving the CDP endpoint
244
295
  * plus its POSIX process group. On an adopted browser it sends
245
296
  * `Browser.close`. On a merely
246
- * 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
247
298
  * share its targets. Idempotent.
248
- * - `close` — graceful REMOTE shutdown: best-effort sends CDP `Browser.close`
299
+ * - `close` — graceful remote shutdown: best-effort sends CDP `Browser.close`
249
300
  * (works whether attached or owned), and when owned also awaits the exit of
250
301
  * the process serving the CDP endpoint plus its POSIX process-group drain
251
302
  * (escalating to a kill only if needed), then performs the same local cleanup
@@ -286,28 +337,68 @@ export declare interface BrowserInterface {
286
337
  * until `destroy()` or an observed process exit clears it.
287
338
  */
288
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
+ */
289
344
  discover(): Promise<BrowserDiscoveryResult>;
345
+ /**
346
+ * Establishes a connection through the endpoint, then discovery, then a launch.
347
+ * Idempotent.
348
+ */
290
349
  connect(): Promise<void>;
291
- /** Assumes responsibility for terminating the currently connected browser. */
350
+ /** Assumes responsibility for terminating the connected browser. */
292
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
+ */
293
359
  disconnect(): Promise<void>;
360
+ /** Returns one context by index, or the first. */
294
361
  context(index?: number): BrowserContextInterface | undefined;
362
+ /** Returns every context. */
295
363
  contexts(): readonly BrowserContextInterface[];
364
+ /**
365
+ * Creates and registers an isolated CDP context with validated proxy, download, origin,
366
+ * and emulation options.
367
+ */
296
368
  isolate(options?: BrowserContextOptions): Promise<BrowserContextInterface>;
369
+ /** Opens a page in the default context. */
297
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
+ */
298
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
+ */
299
389
  close(): Promise<void>;
300
390
  }
301
391
 
302
392
  /**
303
- * Reports that 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`.
304
395
  */
305
396
  export declare class BrowserNotConnectedError extends BrowserError {
306
397
  constructor(context?: Readonly<Record<string, unknown>>);
307
398
  }
308
399
 
309
400
  /**
310
- * Describes the options for creating a Browser.
401
+ * Describes the options for creating a `Browser` instance.
311
402
  *
312
403
  * @remarks
313
404
  * - `on` — initial event listeners wired at construction
@@ -372,17 +463,22 @@ export declare function buildStoreBases(env: Readonly<Record<string, string | un
372
463
  export declare function buildWindowsRoots(env: Readonly<Record<string, string | undefined>>): readonly string[];
373
464
 
374
465
  /**
375
- * Creates a raw-CDP Browser façade.
466
+ * Creates a raw-CDP `BrowserInterface` façade with discovery, connection, and lifecycle
467
+ * management.
376
468
  *
377
469
  * @param options - Connection, launch, and viewport configuration
378
470
  * @returns A {@link BrowserInterface}
379
471
  *
380
- * @example
472
+ * @example Connect to a browser and drive a page
381
473
  * ```ts
382
474
  * import { createBrowser } from '@orkestrel/browser/server'
383
475
  *
384
- * const browser = createBrowser()
385
- * await browser.connect()
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()
386
482
  * ```
387
483
  */
388
484
  export declare function createBrowser(options?: BrowserOptions): BrowserInterface;
@@ -396,22 +492,24 @@ export declare function createBrowser(options?: BrowserOptions): BrowserInterfac
396
492
  export declare function createBrowserProfile(path?: string): Promise<BrowserProfileResult>;
397
493
 
398
494
  /**
399
- * Creates a filesystem-backed browser writer.
495
+ * Creates a filesystem-backed `BrowserWriterInterface` that persists bytes through
496
+ * `node:fs/promises`.
400
497
  *
401
498
  * @returns A {@link BrowserWriterInterface} that persists bytes through `node:fs/promises`
402
499
  */
403
- export declare function createBrowserWriter(): BrowserWriterInterface_2;
500
+ export declare function createBrowserWriter(): BrowserWriterInterface;
404
501
 
405
502
  /**
406
- * Creates a Node `WebSocket`-backed CDP transport.
503
+ * Creates a Node `WebSocket`-backed `CDPTransportInterface` for the given CDP debugger URL.
407
504
  *
408
505
  * @param options - The CDP WebSocket debugger URL (and optional timeout)
409
506
  * @returns A {@link CDPTransportInterface}
410
507
  */
411
- export declare function createCDPTransport(options: WebSocketCDPTransportOptions): CDPTransportInterface_2;
508
+ export declare function createCDPTransport(options: WebSocketCDPTransportOptions): CDPTransportInterface;
412
509
 
413
510
  /**
414
- * Fetches 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`.
415
513
  *
416
514
  * @remarks
417
515
  * The endpoint is a network boundary, so an unreachable host, a non-2xx
@@ -504,7 +602,7 @@ export declare function findSystemBrowser(options?: SystemBrowserOptions): Syste
504
602
  export declare function findSystemBrowsers(options?: SystemBrowserOptions): readonly SystemBrowser[];
505
603
 
506
604
  /**
507
- * Narrows an unknown value to BrowserConnectionError.
605
+ * Narrows an unknown value to a `BrowserConnectionError`.
508
606
  *
509
607
  * @param value - Value to check
510
608
  * @returns True if value is a BrowserConnectionError instance; false otherwise
@@ -512,7 +610,7 @@ export declare function findSystemBrowsers(options?: SystemBrowserOptions): read
512
610
  export declare function isBrowserConnectionError(value: unknown): value is BrowserConnectionError;
513
611
 
514
612
  /**
515
- * Narrows an unknown value to BrowserDestroyedError.
613
+ * Narrows an unknown value to a `BrowserDestroyedError`.
516
614
  *
517
615
  * @param value - Value to check
518
616
  * @returns True if value is a BrowserDestroyedError instance; false otherwise
@@ -520,7 +618,7 @@ export declare function isBrowserConnectionError(value: unknown): value is Brows
520
618
  export declare function isBrowserDestroyedError(value: unknown): value is BrowserDestroyedError;
521
619
 
522
620
  /**
523
- * Narrows an unknown value to BrowserNotConnectedError.
621
+ * Narrows an unknown value to a `BrowserNotConnectedError`.
524
622
  *
525
623
  * @param value - Value to check
526
624
  * @returns True if value is a BrowserNotConnectedError instance; false otherwise
@@ -669,14 +767,14 @@ export declare function waitForCDPReady(port: number, timeout: number, host?: st
669
767
  export declare class WebSocketCDPTransport implements CDPTransportInterface {
670
768
  #private;
671
769
  constructor(options: WebSocketCDPTransportOptions);
672
- get emitter(): EmitterInterface<CDPTransportEventMap_2>;
770
+ get emitter(): EmitterInterface<CDPTransportEventMap>;
673
771
  start(): Promise<void>;
674
772
  send(data: string): Promise<void>;
675
773
  close(): Promise<void>;
676
774
  }
677
775
 
678
776
  /**
679
- * Describes the options for creating a WebSocketCDPTransport.
777
+ * Describes the options for creating a `WebSocketCDPTransport` instance.
680
778
  *
681
779
  * @remarks
682
780
  * - `on` — initial event listeners wired at construction
@@ -13,35 +13,75 @@ import { Emitter } from "@orkestrel/emitter";
13
13
  import { WEBSOCKET_READY_CLOSED, WEBSOCKET_READY_OPEN, WEBSOCKET_VERSION, computeWebSocketAccept, createNodeWebSocket } from "@orkestrel/websocket";
14
14
  import { addAbortListener, once } from "node:events";
15
15
  //#region src/server/constants.ts
16
- /** Sets the default CDP port probed for an existing browser and used for launches. */
16
+ /**
17
+ * Sets the default CDP port probed for an existing browser and used for launches, `9222`.
18
+ */
17
19
  var BROWSER_DEFAULT_CDP_PORT = 9222;
18
- /** Sets the default host probed for an existing browser and used for launches (avoids `localhost` resolving to `::1` when Chromium binds `127.0.0.1`). */
20
+ /**
21
+ * Sets the default host probed for an existing browser and used for launches, `'127.0.0.1'`,
22
+ * which avoids `localhost` resolving to `::1` when Chromium binds `127.0.0.1`.
23
+ */
19
24
  var BROWSER_DEFAULT_HOST = "127.0.0.1";
20
- /** Names the protocol prefix for CDP discovery requests. */
25
+ /** Names the protocol prefix for CDP discovery requests, `'http'`. */
21
26
  var BROWSER_CDP_PROTOCOL = "http";
22
- /** Names the path appended to the CDP host to fetch version metadata (endpoint discovery). */
27
+ /**
28
+ * Names the path appended to the CDP host to fetch version metadata, `'/json/version'`, which
29
+ * is where endpoint discovery reads.
30
+ */
23
31
  var BROWSER_CDP_VERSION_PATH = "/json/version";
24
- /** Names the path appended to the CDP host to list open targets (pages, workers, etc). */
32
+ /**
33
+ * Names the path appended to the CDP host to list open targets — pages, workers, and every
34
+ * other target category Chromium reports — `'/json/list'`.
35
+ */
25
36
  var BROWSER_CDP_LIST_PATH = "/json/list";
26
37
  /** Lists the flags always passed to a launched browser process, alongside the caller's own. */
27
38
  var BROWSER_LAUNCH_ARGS = Object.freeze(["--no-first-run", "--no-default-browser-check"]);
28
- /** Names the flag that enables headless mode on a launched browser process. */
39
+ /**
40
+ * Names the flag that enables headless mode on a launched browser process, `'--headless=new'`.
41
+ */
29
42
  var BROWSER_HEADLESS_ARG = "--headless=new";
30
- /** Names the prefix for isolated browser profiles created beneath the operating-system temp directory. */
43
+ /**
44
+ * Names the prefix for isolated browser profiles created beneath the operating-system temp
45
+ * directory, `'orkestrel-browser-'`.
46
+ */
31
47
  var BROWSER_PROFILE_PREFIX = "orkestrel-browser-";
32
- /** Bounds each launched-process exit window during TERM-to-KILL teardown. */
48
+ /**
49
+ * Bounds each launched-process exit window during TERM-to-KILL teardown at `3_000`
50
+ * milliseconds.
51
+ */
33
52
  var BROWSER_KILL_GRACE_MS = 3e3;
34
- /** Bounds the `discover: false` port-occupancy probe before launching — short, because it only needs to detect an already-listening CDP endpoint, not perform full discovery. */
53
+ /**
54
+ * Bounds the `discover: false` port-occupancy probe before launching at `200` milliseconds,
55
+ * which is short because the probe only needs to detect an already-listening CDP endpoint
56
+ * rather than perform full discovery.
57
+ */
35
58
  var BROWSER_PORT_PROBE_TIMEOUT_MS = 200;
36
- /** Defers once, briefly, 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. */
59
+ /**
60
+ * Defers once for `50` milliseconds when a transport loss is observed on an owned process,
61
+ * giving a near-simultaneous process-exit event, which libuv may reap slightly later than the
62
+ * socket close, first say over the diagnosis.
63
+ */
37
64
  var BROWSER_TRANSPORT_LOSS_DEFER_MS = 50;
38
- /** Names the machine-readable error-context cause for an owned browser process exiting. */
65
+ /**
66
+ * Names the machine-readable error-context cause for an owned browser process exiting,
67
+ * `'process-exit'`.
68
+ */
39
69
  var BROWSER_PROCESS_EXIT_CAUSE = "process-exit";
40
- /** Names the machine-readable error-context cause for a CDP transport disconnecting while its browser remains alive. */
70
+ /**
71
+ * Names the machine-readable error-context cause for a CDP transport disconnecting while its
72
+ * browser remains alive, `'transport-loss'`.
73
+ */
41
74
  var BROWSER_TRANSPORT_LOSS_CAUSE = "transport-loss";
42
- /** Lists the environment variables checked (in order) for an explicit browser executable path override. */
75
+ /**
76
+ * Lists the environment variables checked, in order, for an explicit browser executable path
77
+ * override: `PLAYWRIGHT_EXECUTABLE_PATH`, then `CHROME_PATH`.
78
+ */
43
79
  var BROWSER_ENV_PATH_KEYS = Object.freeze(["PLAYWRIGHT_EXECUTABLE_PATH", "CHROME_PATH"]);
44
- /** Lists the well-known Chrome/Chromium/Edge executable paths with no platform-specific root, keyed by `process.platform`. */
80
+ /**
81
+ * Lists the well-known Chrome/Chromium/Edge executable paths with no platform-specific root,
82
+ * keyed by `process.platform`, leaving `win32` empty because its roots come from
83
+ * `BROWSER_WINDOWS_SUFFIXES`.
84
+ */
45
85
  var BROWSER_EXECUTABLE_PATHS = Object.freeze({
46
86
  linux: Object.freeze([
47
87
  "/usr/bin/google-chrome",
@@ -67,7 +107,10 @@ var BROWSER_WINDOWS_SUFFIXES = Object.freeze([
67
107
  "Microsoft\\Edge\\Application\\msedge.exe",
68
108
  "Chromium\\Application\\chrome.exe"
69
109
  ]);
70
- /** Lists the fallback Windows install roots used when the corresponding environment variable is absent. */
110
+ /**
111
+ * Lists the fallback Windows install roots used when `PROGRAMFILES`, `PROGRAMFILES(X86)`, or
112
+ * `LOCALAPPDATA` is absent.
113
+ */
71
114
  var BROWSER_WINDOWS_ROOT_FALLBACKS = Object.freeze({
72
115
  PROGRAMFILES: "C:\\Program Files",
73
116
  "PROGRAMFILES(X86)": "C:\\Program Files (x86)"
@@ -82,16 +125,25 @@ var BROWSER_EXECUTABLE_NAMES = Object.freeze([
82
125
  "chromium-browser",
83
126
  "chrome"
84
127
  ]);
85
- /** Names the environment variable that carries an additional Playwright browser store base directory. */
128
+ /**
129
+ * Names the environment variable that carries an additional Playwright browser store base
130
+ * directory, `'PLAYWRIGHT_BROWSERS_PATH'`.
131
+ */
86
132
  var BROWSER_STORE_ENV_KEY = "PLAYWRIGHT_BROWSERS_PATH";
87
- /** Lists the well-known Playwright browser store base directories checked in addition to `PLAYWRIGHT_BROWSERS_PATH`. */
133
+ /**
134
+ * Lists the well-known Playwright browser store base directories checked in addition to
135
+ * `PLAYWRIGHT_BROWSERS_PATH`, starting with `/opt/pw-browsers`.
136
+ */
88
137
  var BROWSER_STORE_DEFAULT_DIRS = Object.freeze(["/opt/pw-browsers"]);
89
138
  /** Names the per-OS default Playwright browser cache directory, relative to the home directory (win32 uses `LOCALAPPDATA` directly). */
90
139
  var BROWSER_STORE_CACHE_DIRS = Object.freeze({
91
140
  linux: ".cache/ms-playwright",
92
141
  darwin: "Library/Caches/ms-playwright"
93
142
  });
94
- /** Names the top-level Chromium symlink/binary Playwright maintains inside a browser store base. */
143
+ /**
144
+ * Names the top-level Chromium symlink or binary Playwright maintains inside a browser store
145
+ * base, `'chromium'`.
146
+ */
95
147
  var BROWSER_STORE_LINK_NAME = "chromium";
96
148
  /**
97
149
  * Lists the case-insensitive substrings identifying an executable path/name's browser
@@ -127,7 +179,8 @@ var BROWSER_STORE_GLOBS = Object.freeze({
127
179
  //#endregion
128
180
  //#region src/server/errors.ts
129
181
  /**
130
- * Reports that a CDP connection, discovery, or launch attempt failed.
182
+ * Reports that a CDP connection, discovery, or launch attempt failed, under the code
183
+ * `BROWSER_CONNECTION_ERROR`.
131
184
  */
132
185
  var BrowserConnectionError = class extends BrowserError {
133
186
  constructor(message, context) {
@@ -136,7 +189,8 @@ var BrowserConnectionError = class extends BrowserError {
136
189
  }
137
190
  };
138
191
  /**
139
- * Reports that an operation requiring an active connection was attempted while disconnected.
192
+ * Reports that an operation requiring an active connection was attempted while disconnected,
193
+ * under the code `BROWSER_NOT_CONNECTED_ERROR`.
140
194
  */
141
195
  var BrowserNotConnectedError = class extends BrowserError {
142
196
  constructor(context) {
@@ -145,7 +199,8 @@ var BrowserNotConnectedError = class extends BrowserError {
145
199
  }
146
200
  };
147
201
  /**
148
- * Reports that an operation was attempted after the Browser was destroyed.
202
+ * Reports that an operation was attempted after the browser wrapper was destroyed, under the
203
+ * code `BROWSER_DESTROYED_ERROR`.
149
204
  */
150
205
  var BrowserDestroyedError = class extends BrowserError {
151
206
  constructor(context) {
@@ -154,7 +209,7 @@ var BrowserDestroyedError = class extends BrowserError {
154
209
  }
155
210
  };
156
211
  /**
157
- * Narrows an unknown value to BrowserConnectionError.
212
+ * Narrows an unknown value to a `BrowserConnectionError`.
158
213
  *
159
214
  * @param value - Value to check
160
215
  * @returns True if value is a BrowserConnectionError instance; false otherwise
@@ -163,7 +218,7 @@ function isBrowserConnectionError(value) {
163
218
  return isInstance(value, BrowserConnectionError);
164
219
  }
165
220
  /**
166
- * Narrows an unknown value to BrowserNotConnectedError.
221
+ * Narrows an unknown value to a `BrowserNotConnectedError`.
167
222
  *
168
223
  * @param value - Value to check
169
224
  * @returns True if value is a BrowserNotConnectedError instance; false otherwise
@@ -172,7 +227,7 @@ function isBrowserNotConnectedError(value) {
172
227
  return isInstance(value, BrowserNotConnectedError);
173
228
  }
174
229
  /**
175
- * Narrows an unknown value to BrowserDestroyedError.
230
+ * Narrows an unknown value to a `BrowserDestroyedError`.
176
231
  *
177
232
  * @param value - Value to check
178
233
  * @returns True if value is a BrowserDestroyedError instance; false otherwise
@@ -465,7 +520,8 @@ async function waitForCDPReady(port, timeout, host = BROWSER_DEFAULT_HOST, signa
465
520
  });
466
521
  }
467
522
  /**
468
- * Fetches the current CDP target list from a browser's `/json/list` endpoint.
523
+ * Fetches the current CDP target list from a browser's `/json/list` endpoint, as a `Result`
524
+ * carrying either the targets or a coded `BrowserConnectionError`.
469
525
  *
470
526
  * @remarks
471
527
  * The endpoint is a network boundary, so an unreachable host, a non-2xx
@@ -760,24 +816,29 @@ var FileBrowserWriter = class {
760
816
  //#endregion
761
817
  //#region src/server/factories.ts
762
818
  /**
763
- * Creates a raw-CDP Browser façade.
819
+ * Creates a raw-CDP `BrowserInterface` façade with discovery, connection, and lifecycle
820
+ * management.
764
821
  *
765
822
  * @param options - Connection, launch, and viewport configuration
766
823
  * @returns A {@link BrowserInterface}
767
824
  *
768
- * @example
825
+ * @example Connect to a browser and drive a page
769
826
  * ```ts
770
827
  * import { createBrowser } from '@orkestrel/browser/server'
771
828
  *
772
- * const browser = createBrowser()
773
- * await browser.connect()
829
+ * const browser = createBrowser({ headless: true })
830
+ * await browser.connect() // CDP endpoint discovery → connect, else launch
831
+ * const page = await browser.create({ url: 'https://example.com' })
832
+ * await page.click('#accept')
833
+ * const shot = await page.screenshot({ path: './out.png' })
834
+ * await browser.destroy()
774
835
  * ```
775
836
  */
776
837
  function createBrowser(options) {
777
838
  return new Browser(options);
778
839
  }
779
840
  /**
780
- * Creates a Node `WebSocket`-backed CDP transport.
841
+ * Creates a Node `WebSocket`-backed `CDPTransportInterface` for the given CDP debugger URL.
781
842
  *
782
843
  * @param options - The CDP WebSocket debugger URL (and optional timeout)
783
844
  * @returns A {@link CDPTransportInterface}
@@ -786,7 +847,8 @@ function createCDPTransport(options) {
786
847
  return new WebSocketCDPTransport(options);
787
848
  }
788
849
  /**
789
- * Creates a filesystem-backed browser writer.
850
+ * Creates a filesystem-backed `BrowserWriterInterface` that persists bytes through
851
+ * `node:fs/promises`.
790
852
  *
791
853
  * @returns A {@link BrowserWriterInterface} that persists bytes through `node:fs/promises`
792
854
  */