@orkestrel/browser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +68 -0
- package/dist/src/core/index.cjs +1209 -0
- package/dist/src/core/index.cjs.map +1 -0
- package/dist/src/core/index.d.cts +742 -0
- package/dist/src/core/index.d.ts +742 -0
- package/dist/src/core/index.js +1174 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/server/index.cjs +1172 -0
- package/dist/src/server/index.cjs.map +1 -0
- package/dist/src/server/index.d.cts +567 -0
- package/dist/src/server/index.d.ts +567 -0
- package/dist/src/server/index.js +1120 -0
- package/dist/src/server/index.js.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
import { BrowserContextInterface } from '../core/index.ts';
|
|
2
|
+
import { BrowserError } from '../core/index.ts';
|
|
3
|
+
import { BrowserPageInterface } from '../core/index.ts';
|
|
4
|
+
import { BrowserPageOptions } from '../core/index.ts';
|
|
5
|
+
import { BrowserViewport } from '../core/index.ts';
|
|
6
|
+
import { CDPTarget } from '../core/index.ts';
|
|
7
|
+
import { CDPTransportEventMap } from '../../core/index.ts';
|
|
8
|
+
import { CDPTransportInterface } from '../../core/index.ts';
|
|
9
|
+
import { CDPTransportInterface as CDPTransportInterface_2 } from '../core/index.ts';
|
|
10
|
+
import { ChildProcess } from 'node:child_process';
|
|
11
|
+
import { EmitterHooks } from '@orkestrel/emitter';
|
|
12
|
+
import { EmitterInterface } from '@orkestrel/emitter';
|
|
13
|
+
import { ScreenshotWriterInterface } from '../core/index.ts';
|
|
14
|
+
|
|
15
|
+
export declare class Browser implements BrowserInterface {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(options?: BrowserOptions);
|
|
18
|
+
get emitter(): EmitterInterface<BrowserEventMap>;
|
|
19
|
+
get engine(): BrowserEngine;
|
|
20
|
+
get status(): BrowserStatus;
|
|
21
|
+
get connection(): BrowserConnection | undefined;
|
|
22
|
+
get connected(): boolean;
|
|
23
|
+
get pid(): number | undefined;
|
|
24
|
+
discover(): Promise<BrowserDiscoveryResult>;
|
|
25
|
+
connect(): Promise<void>;
|
|
26
|
+
disconnect(): Promise<void>;
|
|
27
|
+
context(index?: number): BrowserContextInterface | undefined;
|
|
28
|
+
contexts(): readonly BrowserContextInterface[];
|
|
29
|
+
create(options?: BrowserPageOptions): Promise<BrowserPageInterface>;
|
|
30
|
+
destroy(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Gracefully shut down the remote browser, whether this instance owns its
|
|
33
|
+
* process or merely attached to it via CDP.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* Sends CDP `Browser.close` best-effort; on an owned browser also awaits
|
|
37
|
+
* the process's exit (bounded by the kill-escalation grace period,
|
|
38
|
+
* escalating to a kill only if it does not exit in time). Ends in the
|
|
39
|
+
* same local-cleanup state as `destroy()`.
|
|
40
|
+
*/
|
|
41
|
+
close(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Path appended to the CDP host to list open targets (pages, workers, etc). */
|
|
45
|
+
export declare const BROWSER_CDP_LIST_PATH = "/json/list";
|
|
46
|
+
|
|
47
|
+
/** Protocol prefix for CDP discovery requests. */
|
|
48
|
+
export declare const BROWSER_CDP_PROTOCOL = "http";
|
|
49
|
+
|
|
50
|
+
/** Path appended to the CDP host to fetch version metadata (endpoint discovery). */
|
|
51
|
+
export declare const BROWSER_CDP_VERSION_PATH = "/json/version";
|
|
52
|
+
|
|
53
|
+
/** Default CDP port probed for an existing browser and used for launches. */
|
|
54
|
+
export declare const BROWSER_DEFAULT_CDP_PORT = 9222;
|
|
55
|
+
|
|
56
|
+
/** Default host probed for an existing browser and used for launches (avoids `localhost` resolving to `::1` when Chromium binds `127.0.0.1`). */
|
|
57
|
+
export declare const BROWSER_DEFAULT_HOST = "127.0.0.1";
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Case-insensitive substrings identifying an executable path/name's browser
|
|
61
|
+
* engine, checked by `parseBrowserEngine` in the order `edge` → `chromium` → `chrome`.
|
|
62
|
+
*/
|
|
63
|
+
export declare const BROWSER_ENGINE_HINTS: Readonly<Record<BrowserEngine, readonly string[]>>;
|
|
64
|
+
|
|
65
|
+
/** Environment variables checked (in order) for an explicit browser executable path override. */
|
|
66
|
+
export declare const BROWSER_ENV_PATH_KEYS: readonly string[];
|
|
67
|
+
|
|
68
|
+
/** Command names probed on PATH when no well-known executable path exists. */
|
|
69
|
+
export declare const BROWSER_EXECUTABLE_NAMES: readonly string[];
|
|
70
|
+
|
|
71
|
+
/** Well-known Chrome/Chromium/Edge executable paths with no platform-specific root, keyed by `process.platform`. */
|
|
72
|
+
export declare const BROWSER_EXECUTABLE_PATHS: Readonly<Record<string, readonly string[]>>;
|
|
73
|
+
|
|
74
|
+
/** Flag enabling headless mode on a launched browser process. */
|
|
75
|
+
export declare const BROWSER_HEADLESS_ARG = "--headless=new";
|
|
76
|
+
|
|
77
|
+
/** Grace period after SIGTERM before a launched process is escalated to SIGKILL during teardown. */
|
|
78
|
+
export declare const BROWSER_KILL_GRACE_MS = 3000;
|
|
79
|
+
|
|
80
|
+
/** Flags always passed to a launched browser process, alongside the caller's own. */
|
|
81
|
+
export declare const BROWSER_LAUNCH_ARGS: readonly string[];
|
|
82
|
+
|
|
83
|
+
/** Sentinel result returned by discovery when no browser is reachable. */
|
|
84
|
+
export declare const BROWSER_NOT_FOUND_RESULT: BrowserDiscoveryResult;
|
|
85
|
+
|
|
86
|
+
/** 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. */
|
|
87
|
+
export declare const BROWSER_PORT_PROBE_TIMEOUT_MS = 200;
|
|
88
|
+
|
|
89
|
+
/** Per-OS default Playwright browser cache directory, relative to the home directory (win32 uses `LOCALAPPDATA` directly). */
|
|
90
|
+
export declare const BROWSER_STORE_CACHE_DIRS: Readonly<Record<string, string>>;
|
|
91
|
+
|
|
92
|
+
/** Well-known Playwright browser store base directories checked in addition to `PLAYWRIGHT_BROWSERS_PATH`. */
|
|
93
|
+
export declare const BROWSER_STORE_DEFAULT_DIRS: readonly string[];
|
|
94
|
+
|
|
95
|
+
/** Environment variable naming an additional Playwright browser store base directory. */
|
|
96
|
+
export declare const BROWSER_STORE_ENV_KEY = "PLAYWRIGHT_BROWSERS_PATH";
|
|
97
|
+
|
|
98
|
+
/** Glob pattern (relative to a store base) matching a versioned Chromium binary, keyed by `process.platform`. */
|
|
99
|
+
export declare const BROWSER_STORE_GLOBS: Readonly<Record<string, string>>;
|
|
100
|
+
|
|
101
|
+
/** Name of the top-level Chromium symlink/binary Playwright maintains inside a browser store base. */
|
|
102
|
+
export declare const BROWSER_STORE_LINK_NAME = "chromium";
|
|
103
|
+
|
|
104
|
+
/** 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. */
|
|
105
|
+
export declare const BROWSER_TRANSPORT_LOSS_DEFER_MS = 50;
|
|
106
|
+
|
|
107
|
+
/** Fallback Windows install roots used when the corresponding environment variable is absent. */
|
|
108
|
+
export declare const BROWSER_WINDOWS_ROOT_FALLBACKS: Readonly<Record<string, string>>;
|
|
109
|
+
|
|
110
|
+
/** Windows install-root-relative suffixes for Chrome/Edge/Chromium, joined against each candidate root (`PROGRAMFILES`, `PROGRAMFILES(X86)`, `LOCALAPPDATA`). */
|
|
111
|
+
export declare const BROWSER_WINDOWS_SUFFIXES: readonly string[];
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* CDP (Chrome DevTools Protocol) connection configuration.
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* - `port` — port number to probe for an existing CDP endpoint (default `9222`)
|
|
118
|
+
* - `host` — host to probe/launch on (default `127.0.0.1`; avoids `localhost`
|
|
119
|
+
* resolving to `::1` when Chromium binds `127.0.0.1`)
|
|
120
|
+
* - `endpoint` — explicit CDP WebSocket URL; when provided, skips discovery
|
|
121
|
+
* - `discover` — whether `connect()` passively probes for an existing browser
|
|
122
|
+
* before launching (default `true`); set `false` to skip discovery and go
|
|
123
|
+
* straight to launch — a short probe of `port` still runs first and rejects
|
|
124
|
+
* with a coded error naming the occupied port if something is already
|
|
125
|
+
* listening there, so a demanded fresh launch never silently attaches to a
|
|
126
|
+
* stranger browser
|
|
127
|
+
*/
|
|
128
|
+
export declare interface BrowserCdpOptions {
|
|
129
|
+
readonly port?: number;
|
|
130
|
+
readonly host?: string;
|
|
131
|
+
readonly endpoint?: string;
|
|
132
|
+
readonly discover?: boolean;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** How the browser connection was established. */
|
|
136
|
+
export declare type BrowserConnection = 'cdp' | 'launch' | 'persistent';
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A CDP connection, discovery, or launch attempt failed.
|
|
140
|
+
*/
|
|
141
|
+
export declare class BrowserConnectionError extends BrowserError {
|
|
142
|
+
constructor(message: string, context?: Readonly<Record<string, unknown>>);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* An operation was attempted after the Browser was destroyed.
|
|
147
|
+
*/
|
|
148
|
+
export declare class BrowserDestroyedError extends BrowserError {
|
|
149
|
+
constructor(context?: Readonly<Record<string, unknown>>);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Result of passive browser discovery.
|
|
154
|
+
*
|
|
155
|
+
* @remarks
|
|
156
|
+
* Returned by `discover()` to report whether an existing browser is
|
|
157
|
+
* reachable via CDP without actually connecting to it.
|
|
158
|
+
*
|
|
159
|
+
* - `found` — true when a browser responded on the CDP endpoint
|
|
160
|
+
* - `endpoint` — the CDP WebSocket URL when found
|
|
161
|
+
* - `browser` — browser product name reported by the endpoint
|
|
162
|
+
* - `connection` — the connection mode that would be used
|
|
163
|
+
*/
|
|
164
|
+
export declare interface BrowserDiscoveryResult {
|
|
165
|
+
readonly found: boolean;
|
|
166
|
+
readonly endpoint: string | undefined;
|
|
167
|
+
readonly browser: string | undefined;
|
|
168
|
+
readonly connection: BrowserConnection | undefined;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Supported browser engine (raw CDP targets Chromium-family browsers only). */
|
|
172
|
+
export declare type BrowserEngine = 'chromium' | 'chrome' | 'edge';
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Event map for a {@link BrowserInterface}.
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* - `idle` — no active connection (initial state, or after disconnect)
|
|
179
|
+
* - `discover` — passive CDP probe completed
|
|
180
|
+
* - `connect` — a connection was established, carrying the mode used
|
|
181
|
+
* - `disconnect` — the connection was detached — either explicitly, or after
|
|
182
|
+
* an external disconnect (process exit or transport loss); always preceded
|
|
183
|
+
* by a coded `error` describing the cause
|
|
184
|
+
* - `launch` — a new browser process was launched, carrying the engine
|
|
185
|
+
* - `page` — a new page was created via the `create()` shortcut
|
|
186
|
+
* - `error` — a connection or launch fault
|
|
187
|
+
* - `destroy` — the browser and all resources were torn down
|
|
188
|
+
*/
|
|
189
|
+
export declare type BrowserEventMap = {
|
|
190
|
+
readonly idle: readonly [];
|
|
191
|
+
readonly discover: readonly [result: BrowserDiscoveryResult];
|
|
192
|
+
readonly connect: readonly [connection: BrowserConnection];
|
|
193
|
+
readonly disconnect: readonly [];
|
|
194
|
+
readonly launch: readonly [engine: BrowserEngine];
|
|
195
|
+
readonly page: readonly [page: BrowserPageInterface];
|
|
196
|
+
readonly error: readonly [error: unknown];
|
|
197
|
+
readonly destroy: readonly [];
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Browser wrapper with discovery, connection management, and lifecycle control.
|
|
202
|
+
*
|
|
203
|
+
* @remarks
|
|
204
|
+
* Encapsulates the full raw-CDP browser lifecycle behind a clean interface:
|
|
205
|
+
*
|
|
206
|
+
* **Connection strategy** (executed by `connect()`):
|
|
207
|
+
* 1. If `cdp.endpoint` is set, connect directly via CDP
|
|
208
|
+
* 2. Probe `localhost:{cdp.port}` for an existing browser (passive discovery)
|
|
209
|
+
* 3. If found, connect over CDP (preserves the existing browser session)
|
|
210
|
+
* 4. Otherwise, launch a new browser process with raw-CDP flags
|
|
211
|
+
*
|
|
212
|
+
* This lets automation reuse an already-running browser before falling back
|
|
213
|
+
* to a fresh launch.
|
|
214
|
+
*
|
|
215
|
+
* **Lifecycle:**
|
|
216
|
+
* - `discover` — passive CDP probe, no side effects
|
|
217
|
+
* - `connect` — establish connection using the strategy above
|
|
218
|
+
* - `disconnect` — detach from the browser. For `'cdp'` and `'persistent'`
|
|
219
|
+
* connections this closes the client WITHOUT killing the browser process —
|
|
220
|
+
* a `'persistent'` (profile-backed) launch releases ownership of its process
|
|
221
|
+
* (no kill, no exit listener) so the browser stays alive for later
|
|
222
|
+
* reattachment via CDP discovery on the same port. Rejects with the coded
|
|
223
|
+
* `BrowserConnectionError` for `'launch'` (ephemeral, no profile) sessions —
|
|
224
|
+
* use `destroy()` instead. An external disconnect (transport loss while the
|
|
225
|
+
* owned process is still alive, or the owned process exiting on its own)
|
|
226
|
+
* drives this same released/disconnected state automatically, preceded by
|
|
227
|
+
* a coded `error` — `connect()` on the same instance can reattach afterward.
|
|
228
|
+
* - `destroy` — release local resources. On an owned (`'launch'`/`'persistent'`)
|
|
229
|
+
* browser this closes pages/contexts, then kills the process (SIGTERM,
|
|
230
|
+
* escalating to SIGKILL). On a `'cdp'`-attached browser this is a LOCAL
|
|
231
|
+
* DETACH ONLY — the client is closed and local context/page objects are
|
|
232
|
+
* dropped WITHOUT sending any remote close to the browser, since other
|
|
233
|
+
* clients may share those targets. Idempotent.
|
|
234
|
+
* - `close` — graceful REMOTE shutdown: best-effort sends CDP `Browser.close`
|
|
235
|
+
* (works whether attached or owned), and when owned also awaits the
|
|
236
|
+
* process's exit (escalating to a kill only if it doesn't exit in time),
|
|
237
|
+
* then performs the same local cleanup as `destroy()`. Use this to shut
|
|
238
|
+
* down a browser this instance doesn't own but wants to terminate anyway.
|
|
239
|
+
*
|
|
240
|
+
* **Page management:**
|
|
241
|
+
* - `context(index?)` → one context or first
|
|
242
|
+
* - `contexts()` → all contexts
|
|
243
|
+
* - `create(options?)` → shortcut to open a page in the default context
|
|
244
|
+
*/
|
|
245
|
+
export declare interface BrowserInterface {
|
|
246
|
+
readonly emitter: EmitterInterface<BrowserEventMap>;
|
|
247
|
+
readonly engine: BrowserEngine;
|
|
248
|
+
readonly status: BrowserStatus;
|
|
249
|
+
readonly connection: BrowserConnection | undefined;
|
|
250
|
+
readonly connected: boolean;
|
|
251
|
+
/**
|
|
252
|
+
* The process this instance launched, if any, while it is believed alive.
|
|
253
|
+
*
|
|
254
|
+
* @remarks
|
|
255
|
+
* Remains readable after a persistent disconnect-release (the process
|
|
256
|
+
* keeps running, detached from this instance) until `destroy()` or an
|
|
257
|
+
* observed process exit clears it.
|
|
258
|
+
*/
|
|
259
|
+
readonly pid: number | undefined;
|
|
260
|
+
discover(): Promise<BrowserDiscoveryResult>;
|
|
261
|
+
connect(): Promise<void>;
|
|
262
|
+
disconnect(): Promise<void>;
|
|
263
|
+
context(index?: number): BrowserContextInterface | undefined;
|
|
264
|
+
contexts(): readonly BrowserContextInterface[];
|
|
265
|
+
create(options?: BrowserPageOptions): Promise<BrowserPageInterface>;
|
|
266
|
+
destroy(): Promise<void>;
|
|
267
|
+
close(): Promise<void>;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* An operation requiring an active connection was attempted while disconnected.
|
|
272
|
+
*/
|
|
273
|
+
export declare class BrowserNotConnectedError extends BrowserError {
|
|
274
|
+
constructor(context?: Readonly<Record<string, unknown>>);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Options for creating a Browser.
|
|
279
|
+
*
|
|
280
|
+
* @remarks
|
|
281
|
+
* - `on` — initial event listeners wired at construction
|
|
282
|
+
* - `headless` — launch in headless mode (default `true`; ignored for CDP connections)
|
|
283
|
+
* - `executable` — absolute path to a browser executable; when provided, skips
|
|
284
|
+
* system browser discovery and launches this binary directly
|
|
285
|
+
* - `profile` — persistent browser profile (user-data) directory
|
|
286
|
+
* - `cdp` — CDP connection options (port and endpoint)
|
|
287
|
+
* - `timeout` — connection, discovery, and launch timeout in milliseconds (default `30_000`)
|
|
288
|
+
* - `viewport` — default viewport dimensions for new pages
|
|
289
|
+
* - `signal` — external AbortSignal for cancelling the connection attempt
|
|
290
|
+
* - `args` — additional command-line flags passed to the launched browser process
|
|
291
|
+
* - `engine` — preferred browser engine to launch; narrows system browser
|
|
292
|
+
* discovery to this engine (ignored when `executable` is given); takes
|
|
293
|
+
* precedence over `browsers.engine`
|
|
294
|
+
* - `browsers` — candidate-source overrides consulted when `connect()` needs
|
|
295
|
+
* to launch (same shape `findSystemBrowsers` takes); ignored when
|
|
296
|
+
* `executable` is given, which bypasses discovery entirely
|
|
297
|
+
*/
|
|
298
|
+
export declare interface BrowserOptions {
|
|
299
|
+
readonly on?: EmitterHooks<BrowserEventMap>;
|
|
300
|
+
readonly headless?: boolean;
|
|
301
|
+
readonly executable?: string;
|
|
302
|
+
readonly profile?: string;
|
|
303
|
+
readonly cdp?: BrowserCdpOptions;
|
|
304
|
+
readonly timeout?: number;
|
|
305
|
+
readonly viewport?: BrowserViewport;
|
|
306
|
+
readonly signal?: AbortSignal;
|
|
307
|
+
readonly args?: readonly string[];
|
|
308
|
+
readonly engine?: BrowserEngine;
|
|
309
|
+
readonly browsers?: SystemBrowserOptions;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** Lifecycle status of a browser wrapper. */
|
|
313
|
+
export declare type BrowserStatus = 'idle' | 'connecting' | 'connected' | 'disconnected' | 'error';
|
|
314
|
+
|
|
315
|
+
/** Classify a `/json/version` `Browser` string into a {@link BrowserEngine} (`Edg/` → edge, `Chrome/` → chrome, else chromium). */
|
|
316
|
+
export declare function browserToEngine(browser: string): BrowserEngine;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Create a raw-CDP Browser façade.
|
|
320
|
+
*
|
|
321
|
+
* @param options - Connection, launch, and viewport configuration
|
|
322
|
+
* @returns A {@link BrowserInterface}
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```ts
|
|
326
|
+
* import { createBrowser } from '@src/server'
|
|
327
|
+
*
|
|
328
|
+
* const browser = createBrowser()
|
|
329
|
+
* await browser.connect()
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
export declare function createBrowser(options?: BrowserOptions): BrowserInterface;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Create a Node `WebSocket`-backed CDP transport.
|
|
336
|
+
*
|
|
337
|
+
* @param options - The CDP WebSocket debugger URL (and optional timeout)
|
|
338
|
+
* @returns A {@link CDPTransportInterface}
|
|
339
|
+
*/
|
|
340
|
+
export declare function createCDPTransport(options: WebSocketCDPTransportOptions): CDPTransportInterface_2;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Create a filesystem-backed screenshot writer.
|
|
344
|
+
*
|
|
345
|
+
* @returns A {@link ScreenshotWriterInterface} that persists bytes via `node:fs/promises`
|
|
346
|
+
*/
|
|
347
|
+
export declare function createScreenshotWriter(): ScreenshotWriterInterface;
|
|
348
|
+
|
|
349
|
+
/** Build the default well-known install-path candidates for a platform, deriving Windows roots from env vars. */
|
|
350
|
+
export declare function defaultInstallPaths(platform: string, env: Readonly<Record<string, string | undefined>>): readonly string[];
|
|
351
|
+
|
|
352
|
+
/** Build the default Playwright browser store base directories to search for a managed Chromium. */
|
|
353
|
+
export declare function defaultStoreBases(env: Readonly<Record<string, string | undefined>>, platform: string): readonly string[];
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Fetch the current CDP target list from a browser's `/json/list` endpoint.
|
|
357
|
+
*
|
|
358
|
+
* @param port - Port the browser exposes its CDP endpoint on
|
|
359
|
+
* @param timeout - Request timeout in milliseconds
|
|
360
|
+
* @param host - Host the browser exposes its CDP endpoint on (default `127.0.0.1`)
|
|
361
|
+
* @returns Normalized CDP targets
|
|
362
|
+
*/
|
|
363
|
+
export declare function fetchCdpTargets(port: number, timeout: number, host?: string): Promise<readonly CDPTarget[]>;
|
|
364
|
+
|
|
365
|
+
/** Check the env-override keys (`PLAYWRIGHT_EXECUTABLE_PATH`, `CHROME_PATH`) in order, returning every one that exists. */
|
|
366
|
+
export declare function findAllEnvOverrides(env: Readonly<Record<string, string | undefined>>): readonly string[];
|
|
367
|
+
|
|
368
|
+
/** Return every candidate path that exists on disk, in the given order. */
|
|
369
|
+
export declare function findAllInstallPaths(paths: readonly string[]): readonly string[];
|
|
370
|
+
|
|
371
|
+
/** Search one store base for the top-level `chromium` link and every `chromium-*` install, highest revision first. */
|
|
372
|
+
export declare function findAllInStore(base: string, platform: string): readonly string[];
|
|
373
|
+
|
|
374
|
+
/** Check the env-override keys (`PLAYWRIGHT_EXECUTABLE_PATH`, `CHROME_PATH`) in order for an existing file. */
|
|
375
|
+
export declare function findEnvOverride(env: Readonly<Record<string, string | undefined>>): string | undefined;
|
|
376
|
+
|
|
377
|
+
/** Return the first candidate path that exists on disk. */
|
|
378
|
+
export declare function findInstallPath(paths: readonly string[]): string | undefined;
|
|
379
|
+
|
|
380
|
+
/** Search one store base for the top-level `chromium` link, else the highest-revision `chromium-*` install. */
|
|
381
|
+
export declare function findInStore(base: string, platform: string): string | undefined;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Locate a Chrome/Chromium/Edge executable on this machine — the first entry
|
|
385
|
+
* of {@link findSystemBrowsers}.
|
|
386
|
+
*
|
|
387
|
+
* @param options - Overrides for the candidate sources; see {@link SystemBrowserOptions}
|
|
388
|
+
* @returns The first discovered browser, or undefined
|
|
389
|
+
*/
|
|
390
|
+
export declare function findSystemBrowser(options?: SystemBrowserOptions): SystemBrowser | undefined;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Enumerate every Chrome/Chromium/Edge executable discoverable on this
|
|
394
|
+
* machine, deduplicated by normalized absolute path.
|
|
395
|
+
*
|
|
396
|
+
* @remarks
|
|
397
|
+
* Resolution precedence (candidates appended in this order):
|
|
398
|
+
* 1. `PLAYWRIGHT_EXECUTABLE_PATH`, then `CHROME_PATH` — explicit environment
|
|
399
|
+
* overrides that exist on disk
|
|
400
|
+
* 2. Well-known platform install locations (Chrome, Edge, Chromium); Windows
|
|
401
|
+
* roots are derived from `PROGRAMFILES` / `PROGRAMFILES(X86)` / `LOCALAPPDATA`
|
|
402
|
+
* 3. PATH probe for known command names (`which` on POSIX, `where` on Windows)
|
|
403
|
+
* 4. Playwright-managed browser stores (`PLAYWRIGHT_BROWSERS_PATH`, `/opt/pw-browsers`,
|
|
404
|
+
* and the per-OS Playwright cache directory) — the top-level `chromium`
|
|
405
|
+
* link/binary, then the highest-revision `chromium-*` install found
|
|
406
|
+
*
|
|
407
|
+
* Each candidate is classified into a {@link BrowserEngine} via
|
|
408
|
+
* `parseBrowserEngine` (unclassifiable candidates default to `'chromium'`),
|
|
409
|
+
* and `options.engine` (when given) narrows the result to that engine.
|
|
410
|
+
*
|
|
411
|
+
* @param options - Overrides for the candidate sources; see {@link SystemBrowserOptions}
|
|
412
|
+
* @returns Every discovered browser, in resolution-precedence order
|
|
413
|
+
*/
|
|
414
|
+
export declare function findSystemBrowsers(options?: SystemBrowserOptions): readonly SystemBrowser[];
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Narrow an unknown value to BrowserConnectionError.
|
|
418
|
+
*
|
|
419
|
+
* @param value - Value to check
|
|
420
|
+
* @returns True when value is a BrowserConnectionError instance
|
|
421
|
+
*/
|
|
422
|
+
export declare function isBrowserConnectionError(value: unknown): value is BrowserConnectionError;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Narrow an unknown value to BrowserDestroyedError.
|
|
426
|
+
*
|
|
427
|
+
* @param value - Value to check
|
|
428
|
+
* @returns True when value is a BrowserDestroyedError instance
|
|
429
|
+
*/
|
|
430
|
+
export declare function isBrowserDestroyedError(value: unknown): value is BrowserDestroyedError;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Narrow an unknown value to BrowserNotConnectedError.
|
|
434
|
+
*
|
|
435
|
+
* @param value - Value to check
|
|
436
|
+
* @returns True when value is a BrowserNotConnectedError instance
|
|
437
|
+
*/
|
|
438
|
+
export declare function isBrowserNotConnectedError(value: unknown): value is BrowserNotConnectedError;
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Launch a browser process with raw-CDP debugging flags.
|
|
442
|
+
*
|
|
443
|
+
* @param executable - Absolute path to the browser executable
|
|
444
|
+
* @param port - Port the browser exposes its CDP endpoint on
|
|
445
|
+
* @param headless - Whether to launch in headless mode
|
|
446
|
+
* @param profile - Optional user-data-dir for a persistent profile
|
|
447
|
+
* @param extra - Additional command-line flags
|
|
448
|
+
* @returns The spawned ChildProcess
|
|
449
|
+
*/
|
|
450
|
+
export declare function launchBrowserProcess(executable: string, port: number, headless: boolean, profile?: string, extra?: readonly string[]): ChildProcess;
|
|
451
|
+
|
|
452
|
+
/** Normalize an executable path for cross-source deduplication (case-insensitive on Windows). */
|
|
453
|
+
export declare function normalizeExecutablePath(path: string, platform: string): string;
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Classify an executable path/name into a {@link BrowserEngine} by
|
|
457
|
+
* case-insensitive hint, checked in the order edge → chromium → chrome.
|
|
458
|
+
*
|
|
459
|
+
* @param executable - Executable path or command name to classify
|
|
460
|
+
* @returns The classified engine, or undefined when no hint matches
|
|
461
|
+
*/
|
|
462
|
+
export declare function parseBrowserEngine(executable: string): BrowserEngine | undefined;
|
|
463
|
+
|
|
464
|
+
/** Probe PATH (`which`/`where`) for every resolvable command name, in the given order. */
|
|
465
|
+
export declare function probeAllPathNames(names: readonly string[], platform: string): readonly string[];
|
|
466
|
+
|
|
467
|
+
/** Probe PATH (`which`/`where`) for the first resolvable command name. */
|
|
468
|
+
export declare function probePathNames(names: readonly string[], platform: string): string | undefined;
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* One discovered browser executable on this machine.
|
|
472
|
+
*
|
|
473
|
+
* @remarks
|
|
474
|
+
* Returned by `findSystemBrowsers`/`findSystemBrowser` — pairs the resolved
|
|
475
|
+
* absolute executable path with its classified engine.
|
|
476
|
+
*/
|
|
477
|
+
export declare type SystemBrowser = {
|
|
478
|
+
readonly executable: string;
|
|
479
|
+
readonly engine: BrowserEngine;
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Options overriding `findSystemBrowsers`'/`findSystemBrowser`'s candidate sources.
|
|
484
|
+
*
|
|
485
|
+
* @remarks
|
|
486
|
+
* Each field replaces the default candidate list for its category — a field
|
|
487
|
+
* left `undefined` falls back to the platform default, an explicit `[]` (or
|
|
488
|
+
* empty `env`) disables that category entirely. Zero-arg `findSystemBrowsers()`
|
|
489
|
+
* uses full default resolution.
|
|
490
|
+
*
|
|
491
|
+
* - `env` — environment record consulted for both the override keys
|
|
492
|
+
* (`PLAYWRIGHT_EXECUTABLE_PATH`, `CHROME_PATH`) and Windows install roots
|
|
493
|
+
* (`PROGRAMFILES`, `PROGRAMFILES(X86)`, `LOCALAPPDATA`); defaults to `process.env`
|
|
494
|
+
* - `paths` — candidate install paths checked in order; defaults to the
|
|
495
|
+
* platform's well-known Chrome/Edge/Chromium locations
|
|
496
|
+
* - `names` — command names probed on PATH (`which`/`where`); defaults to
|
|
497
|
+
* `BROWSER_EXECUTABLE_NAMES`
|
|
498
|
+
* - `stores` — Playwright browser store base directories searched for a
|
|
499
|
+
* managed Chromium; defaults to `PLAYWRIGHT_BROWSERS_PATH`, the well-known
|
|
500
|
+
* store dirs, and the per-OS Playwright cache directory
|
|
501
|
+
* - `engine` — when set, narrows results to candidates classified as this engine
|
|
502
|
+
*/
|
|
503
|
+
export declare interface SystemBrowserOptions {
|
|
504
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
505
|
+
readonly paths?: readonly string[];
|
|
506
|
+
readonly names?: readonly string[];
|
|
507
|
+
readonly stores?: readonly string[];
|
|
508
|
+
readonly engine?: BrowserEngine;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Poll a browser's CDP version endpoint until it responds or the timeout elapses.
|
|
513
|
+
*
|
|
514
|
+
* @param port - Port the browser exposes its CDP endpoint on
|
|
515
|
+
* @param timeout - Maximum time to wait in milliseconds
|
|
516
|
+
* @param host - Host the browser exposes its CDP endpoint on (default `127.0.0.1`)
|
|
517
|
+
* @returns The browser's WebSocket debugger URL
|
|
518
|
+
*
|
|
519
|
+
* @throws When the endpoint does not become ready before the timeout
|
|
520
|
+
*/
|
|
521
|
+
export declare function waitForCdpReady(port: number, timeout: number, host?: string): Promise<string>;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* `@orkestrel/websocket`-backed {@link CDPTransportInterface} — the dumb text
|
|
525
|
+
* pipe a {@link import('@src/core').CDPClientInterface} sends and receives
|
|
526
|
+
* JSON-RPC frames over.
|
|
527
|
+
*
|
|
528
|
+
* @remarks
|
|
529
|
+
* `start()` hand-rolls the RFC 6455 client handshake: it opens a `node:http`
|
|
530
|
+
* `GET` carrying `Connection: Upgrade` / `Upgrade: websocket` / a random
|
|
531
|
+
* `Sec-WebSocket-Key` / `Sec-WebSocket-Version`, awaits the client `'upgrade'`
|
|
532
|
+
* event, and validates `Sec-WebSocket-Accept === computeWebSocketAccept(key)`
|
|
533
|
+
* — a mismatch (or a connection/request error, or a timeout) rejects `start()`
|
|
534
|
+
* with a coded {@link BrowserConnectionError} and cleans up the socket. On
|
|
535
|
+
* success it wraps the raw upgraded socket in `createNodeWebSocket({ socket,
|
|
536
|
+
* head })` (CLIENT mode — no `key` — so outgoing frames are masked per RFC
|
|
537
|
+
* 6455 §5.3) and bridges its `message`/`close`/`error` events onto this
|
|
538
|
+
* transport's emitter. `start()` opens a fresh socket each call (safe to call
|
|
539
|
+
* again after `close()` — a new request/socket/NodeWebSocket triple is
|
|
540
|
+
* created every time, which is what `CDPClient.reconnect()` depends on). CDP
|
|
541
|
+
* frames are text-only, so `message` always carries a `string`.
|
|
542
|
+
*/
|
|
543
|
+
export declare class WebSocketCDPTransport implements CDPTransportInterface {
|
|
544
|
+
#private;
|
|
545
|
+
constructor(options: WebSocketCDPTransportOptions);
|
|
546
|
+
get emitter(): EmitterInterface<CDPTransportEventMap>;
|
|
547
|
+
start(): Promise<void>;
|
|
548
|
+
send(data: string): Promise<void>;
|
|
549
|
+
close(): Promise<void>;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Options for creating a WebSocketCDPTransport.
|
|
554
|
+
*
|
|
555
|
+
* @remarks
|
|
556
|
+
* - `url` — the CDP WebSocket debugger URL to connect to
|
|
557
|
+
* - `timeout` — ms before the connection attempt fails (default from constants)
|
|
558
|
+
*/
|
|
559
|
+
export declare interface WebSocketCDPTransportOptions {
|
|
560
|
+
readonly url: string;
|
|
561
|
+
readonly timeout?: number;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** Derive Windows install roots from env vars, falling back to well-known literals when absent. */
|
|
565
|
+
export declare function windowsRoots(env: Readonly<Record<string, string | undefined>>): readonly string[];
|
|
566
|
+
|
|
567
|
+
export { }
|