@orkestrel/browser 0.0.15 → 0.0.17

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