@orkestrel/browser 0.0.2 → 0.0.5
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/dist/src/core/index.cjs +422 -162
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +11 -2
- package/dist/src/core/index.d.ts +11 -2
- package/dist/src/core/index.js +422 -162
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +588 -411
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +52 -53
- package/dist/src/server/index.d.ts +52 -53
- package/dist/src/server/index.js +586 -410
- package/dist/src/server/index.js.map +1 -1
- package/package.json +11 -8
|
@@ -4,10 +4,12 @@ import { BrowserPageInterface } from '../core/index.ts';
|
|
|
4
4
|
import { BrowserPageOptions } from '../core/index.ts';
|
|
5
5
|
import { BrowserViewport } from '../core/index.ts';
|
|
6
6
|
import { CDPTarget } from '../core/index.ts';
|
|
7
|
-
import { CDPTransportEventMap } from '
|
|
7
|
+
import { CDPTransportEventMap } from '../core/index.ts';
|
|
8
|
+
import { CDPTransportEventMap as CDPTransportEventMap_2 } from '../../core/index.ts';
|
|
8
9
|
import { CDPTransportInterface } from '../../core/index.ts';
|
|
9
10
|
import { CDPTransportInterface as CDPTransportInterface_2 } from '../core/index.ts';
|
|
10
11
|
import { ChildProcess } from 'node:child_process';
|
|
12
|
+
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
11
13
|
import { EmitterHooks } from '@orkestrel/emitter';
|
|
12
14
|
import { EmitterInterface } from '@orkestrel/emitter';
|
|
13
15
|
import { ScreenshotWriterInterface } from '../core/index.ts';
|
|
@@ -19,25 +21,17 @@ export declare class Browser implements BrowserInterface {
|
|
|
19
21
|
get engine(): BrowserEngine;
|
|
20
22
|
get status(): BrowserStatus;
|
|
21
23
|
get connection(): BrowserConnection | undefined;
|
|
24
|
+
get owned(): boolean | undefined;
|
|
22
25
|
get connected(): boolean;
|
|
23
26
|
get pid(): number | undefined;
|
|
24
27
|
discover(): Promise<BrowserDiscoveryResult>;
|
|
25
28
|
connect(): Promise<void>;
|
|
29
|
+
adopt(): void;
|
|
26
30
|
disconnect(): Promise<void>;
|
|
27
31
|
context(index?: number): BrowserContextInterface | undefined;
|
|
28
32
|
contexts(): readonly BrowserContextInterface[];
|
|
29
33
|
create(options?: BrowserPageOptions): Promise<BrowserPageInterface>;
|
|
30
34
|
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
35
|
close(): Promise<void>;
|
|
42
36
|
}
|
|
43
37
|
|
|
@@ -80,12 +74,12 @@ export declare const BROWSER_KILL_GRACE_MS = 3000;
|
|
|
80
74
|
/** Flags always passed to a launched browser process, alongside the caller's own. */
|
|
81
75
|
export declare const BROWSER_LAUNCH_ARGS: readonly string[];
|
|
82
76
|
|
|
83
|
-
/** Sentinel result returned by discovery when no browser is reachable. */
|
|
84
|
-
export declare const BROWSER_NOT_FOUND_RESULT: BrowserDiscoveryResult;
|
|
85
|
-
|
|
86
77
|
/** 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
78
|
export declare const BROWSER_PORT_PROBE_TIMEOUT_MS = 200;
|
|
88
79
|
|
|
80
|
+
/** Machine-readable error-context cause for an owned browser process exiting. */
|
|
81
|
+
export declare const BROWSER_PROCESS_EXIT_CAUSE = "process-exit";
|
|
82
|
+
|
|
89
83
|
/** Per-OS default Playwright browser cache directory, relative to the home directory (win32 uses `LOCALAPPDATA` directly). */
|
|
90
84
|
export declare const BROWSER_STORE_CACHE_DIRS: Readonly<Record<string, string>>;
|
|
91
85
|
|
|
@@ -101,6 +95,9 @@ export declare const BROWSER_STORE_GLOBS: Readonly<Record<string, string>>;
|
|
|
101
95
|
/** Name of the top-level Chromium symlink/binary Playwright maintains inside a browser store base. */
|
|
102
96
|
export declare const BROWSER_STORE_LINK_NAME = "chromium";
|
|
103
97
|
|
|
98
|
+
/** Machine-readable error-context cause for a CDP transport disconnecting while its browser remains alive. */
|
|
99
|
+
export declare const BROWSER_TRANSPORT_LOSS_CAUSE = "transport-loss";
|
|
100
|
+
|
|
104
101
|
/** 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
102
|
export declare const BROWSER_TRANSPORT_LOSS_DEFER_MS = 50;
|
|
106
103
|
|
|
@@ -125,7 +122,7 @@ export declare const BROWSER_WINDOWS_SUFFIXES: readonly string[];
|
|
|
125
122
|
* listening there, so a demanded fresh launch never silently attaches to a
|
|
126
123
|
* stranger browser
|
|
127
124
|
*/
|
|
128
|
-
export declare interface
|
|
125
|
+
export declare interface BrowserCDPOptions {
|
|
129
126
|
readonly port?: number;
|
|
130
127
|
readonly host?: string;
|
|
131
128
|
readonly endpoint?: string;
|
|
@@ -215,22 +212,19 @@ export declare type BrowserEventMap = {
|
|
|
215
212
|
* **Lifecycle:**
|
|
216
213
|
* - `discover` — passive CDP probe, no side effects
|
|
217
214
|
* - `connect` — establish connection using the strategy above
|
|
218
|
-
* - `
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* drives this same released/disconnected state automatically, preceded by
|
|
215
|
+
* - `adopt` — explicitly assume responsibility for terminating the connected
|
|
216
|
+
* browser, including a browser this instance attached to over CDP
|
|
217
|
+
* - `disconnect` — detach from the browser. For attached CDP connections this
|
|
218
|
+
* closes only the client. For owned launches and adopted connections, it
|
|
219
|
+
* retains ownership and the endpoint so the same instance can reconnect
|
|
220
|
+
* and remains responsible for eventual termination. An external disconnect
|
|
221
|
+
* (transport loss while the owned process is still alive, or the owned
|
|
222
|
+
* process exiting on its own) drives the disconnected state, preceded by
|
|
227
223
|
* a coded `error` — `connect()` on the same instance can reattach afterward.
|
|
228
|
-
* - `destroy` — release local resources. On
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* DETACH ONLY
|
|
232
|
-
* dropped WITHOUT sending any remote close to the browser, since other
|
|
233
|
-
* clients may share those targets. Idempotent.
|
|
224
|
+
* - `destroy` — release local resources. On a launched browser this closes
|
|
225
|
+
* pages/contexts, then kills and awaits the process. On an adopted browser
|
|
226
|
+
* it sends `Browser.close`. On a merely attached browser this is a LOCAL
|
|
227
|
+
* DETACH ONLY because other clients may share its targets. Idempotent.
|
|
234
228
|
* - `close` — graceful REMOTE shutdown: best-effort sends CDP `Browser.close`
|
|
235
229
|
* (works whether attached or owned), and when owned also awaits the
|
|
236
230
|
* process's exit (escalating to a kill only if it doesn't exit in time),
|
|
@@ -247,18 +241,28 @@ export declare interface BrowserInterface {
|
|
|
247
241
|
readonly engine: BrowserEngine;
|
|
248
242
|
readonly status: BrowserStatus;
|
|
249
243
|
readonly connection: BrowserConnection | undefined;
|
|
244
|
+
/**
|
|
245
|
+
* Whether this instance is responsible for terminating the represented browser.
|
|
246
|
+
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* `true` for launched and explicitly adopted sessions, `false` for an
|
|
249
|
+
* active attachment, and `undefined` when no session is represented.
|
|
250
|
+
*/
|
|
251
|
+
readonly owned: boolean | undefined;
|
|
250
252
|
readonly connected: boolean;
|
|
251
253
|
/**
|
|
252
254
|
* The process this instance launched, if any, while it is believed alive.
|
|
253
255
|
*
|
|
254
256
|
* @remarks
|
|
255
|
-
* Remains readable after a persistent disconnect
|
|
256
|
-
*
|
|
257
|
+
* Remains readable after a persistent disconnect (the process keeps
|
|
258
|
+
* running, detached from the transport) until `destroy()` or an
|
|
257
259
|
* observed process exit clears it.
|
|
258
260
|
*/
|
|
259
261
|
readonly pid: number | undefined;
|
|
260
262
|
discover(): Promise<BrowserDiscoveryResult>;
|
|
261
263
|
connect(): Promise<void>;
|
|
264
|
+
/** Assume responsibility for terminating the currently connected browser. */
|
|
265
|
+
adopt(): void;
|
|
262
266
|
disconnect(): Promise<void>;
|
|
263
267
|
context(index?: number): BrowserContextInterface | undefined;
|
|
264
268
|
contexts(): readonly BrowserContextInterface[];
|
|
@@ -279,6 +283,7 @@ export declare class BrowserNotConnectedError extends BrowserError {
|
|
|
279
283
|
*
|
|
280
284
|
* @remarks
|
|
281
285
|
* - `on` — initial event listeners wired at construction
|
|
286
|
+
* - `error` — observer error handler forwarded to the emitter
|
|
282
287
|
* - `headless` — launch in headless mode (default `true`; ignored for CDP connections)
|
|
283
288
|
* - `executable` — absolute path to a browser executable; when provided, skips
|
|
284
289
|
* system browser discovery and launches this binary directly
|
|
@@ -297,10 +302,11 @@ export declare class BrowserNotConnectedError extends BrowserError {
|
|
|
297
302
|
*/
|
|
298
303
|
export declare interface BrowserOptions {
|
|
299
304
|
readonly on?: EmitterHooks<BrowserEventMap>;
|
|
305
|
+
readonly error?: EmitterErrorHandler;
|
|
300
306
|
readonly headless?: boolean;
|
|
301
307
|
readonly executable?: string;
|
|
302
308
|
readonly profile?: string;
|
|
303
|
-
readonly cdp?:
|
|
309
|
+
readonly cdp?: BrowserCDPOptions;
|
|
304
310
|
readonly timeout?: number;
|
|
305
311
|
readonly viewport?: BrowserViewport;
|
|
306
312
|
readonly signal?: AbortSignal;
|
|
@@ -313,7 +319,7 @@ export declare interface BrowserOptions {
|
|
|
313
319
|
export declare type BrowserStatus = 'idle' | 'connecting' | 'connected' | 'disconnected' | 'error';
|
|
314
320
|
|
|
315
321
|
/** Classify a `/json/version` `Browser` string into a {@link BrowserEngine} (`Edg/` → edge, `Chrome/` → chrome, else chromium). */
|
|
316
|
-
export declare function browserToEngine(browser
|
|
322
|
+
export declare function browserToEngine(browser?: string): BrowserEngine;
|
|
317
323
|
|
|
318
324
|
/**
|
|
319
325
|
* Create a raw-CDP Browser façade.
|
|
@@ -360,7 +366,7 @@ export declare function defaultStoreBases(env: Readonly<Record<string, string |
|
|
|
360
366
|
* @param host - Host the browser exposes its CDP endpoint on (default `127.0.0.1`)
|
|
361
367
|
* @returns Normalized CDP targets
|
|
362
368
|
*/
|
|
363
|
-
export declare function
|
|
369
|
+
export declare function fetchCDPTargets(port: number, timeout: number, host?: string): Promise<readonly CDPTarget[]>;
|
|
364
370
|
|
|
365
371
|
/** Check the env-override keys (`PLAYWRIGHT_EXECUTABLE_PATH`, `CHROME_PATH`) in order, returning every one that exists. */
|
|
366
372
|
export declare function findAllEnvOverrides(env: Readonly<Record<string, string | undefined>>): readonly string[];
|
|
@@ -518,32 +524,21 @@ export declare interface SystemBrowserOptions {
|
|
|
518
524
|
*
|
|
519
525
|
* @throws When the endpoint does not become ready before the timeout
|
|
520
526
|
*/
|
|
521
|
-
export declare function
|
|
527
|
+
export declare function waitForCDPReady(port: number, timeout: number, host?: string, signal?: AbortSignal): Promise<string>;
|
|
522
528
|
|
|
523
529
|
/**
|
|
524
|
-
* `@orkestrel/websocket`-backed
|
|
525
|
-
* pipe a {@link import('@src/core').CDPClientInterface} sends and receives
|
|
526
|
-
* JSON-RPC frames over.
|
|
530
|
+
* `@orkestrel/websocket`-backed raw CDP text transport.
|
|
527
531
|
*
|
|
528
532
|
* @remarks
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
* `
|
|
532
|
-
*
|
|
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`.
|
|
533
|
+
* Performs and validates the RFC 6455 HTTP upgrade, then delegates frame
|
|
534
|
+
* handling to `@orkestrel/websocket`. Concurrent and repeated `start()` /
|
|
535
|
+
* `close()` calls share their active transition, and a later `start()` opens a
|
|
536
|
+
* fresh socket after the prior one closes.
|
|
542
537
|
*/
|
|
543
538
|
export declare class WebSocketCDPTransport implements CDPTransportInterface {
|
|
544
539
|
#private;
|
|
545
540
|
constructor(options: WebSocketCDPTransportOptions);
|
|
546
|
-
get emitter(): EmitterInterface<
|
|
541
|
+
get emitter(): EmitterInterface<CDPTransportEventMap_2>;
|
|
547
542
|
start(): Promise<void>;
|
|
548
543
|
send(data: string): Promise<void>;
|
|
549
544
|
close(): Promise<void>;
|
|
@@ -553,10 +548,14 @@ export declare class WebSocketCDPTransport implements CDPTransportInterface {
|
|
|
553
548
|
* Options for creating a WebSocketCDPTransport.
|
|
554
549
|
*
|
|
555
550
|
* @remarks
|
|
551
|
+
* - `on` — initial event listeners wired at construction
|
|
552
|
+
* - `error` — observer error handler forwarded to the emitter
|
|
556
553
|
* - `url` — the CDP WebSocket debugger URL to connect to
|
|
557
554
|
* - `timeout` — ms before the connection attempt fails (default from constants)
|
|
558
555
|
*/
|
|
559
556
|
export declare interface WebSocketCDPTransportOptions {
|
|
557
|
+
readonly on?: EmitterHooks<CDPTransportEventMap>;
|
|
558
|
+
readonly error?: EmitterErrorHandler;
|
|
560
559
|
readonly url: string;
|
|
561
560
|
readonly timeout?: number;
|
|
562
561
|
}
|
|
@@ -4,10 +4,12 @@ import { BrowserPageInterface } from '../core/index.ts';
|
|
|
4
4
|
import { BrowserPageOptions } from '../core/index.ts';
|
|
5
5
|
import { BrowserViewport } from '../core/index.ts';
|
|
6
6
|
import { CDPTarget } from '../core/index.ts';
|
|
7
|
-
import { CDPTransportEventMap } from '
|
|
7
|
+
import { CDPTransportEventMap } from '../core/index.ts';
|
|
8
|
+
import { CDPTransportEventMap as CDPTransportEventMap_2 } from '../../core/index.ts';
|
|
8
9
|
import { CDPTransportInterface } from '../../core/index.ts';
|
|
9
10
|
import { CDPTransportInterface as CDPTransportInterface_2 } from '../core/index.ts';
|
|
10
11
|
import { ChildProcess } from 'node:child_process';
|
|
12
|
+
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
11
13
|
import { EmitterHooks } from '@orkestrel/emitter';
|
|
12
14
|
import { EmitterInterface } from '@orkestrel/emitter';
|
|
13
15
|
import { ScreenshotWriterInterface } from '../core/index.ts';
|
|
@@ -19,25 +21,17 @@ export declare class Browser implements BrowserInterface {
|
|
|
19
21
|
get engine(): BrowserEngine;
|
|
20
22
|
get status(): BrowserStatus;
|
|
21
23
|
get connection(): BrowserConnection | undefined;
|
|
24
|
+
get owned(): boolean | undefined;
|
|
22
25
|
get connected(): boolean;
|
|
23
26
|
get pid(): number | undefined;
|
|
24
27
|
discover(): Promise<BrowserDiscoveryResult>;
|
|
25
28
|
connect(): Promise<void>;
|
|
29
|
+
adopt(): void;
|
|
26
30
|
disconnect(): Promise<void>;
|
|
27
31
|
context(index?: number): BrowserContextInterface | undefined;
|
|
28
32
|
contexts(): readonly BrowserContextInterface[];
|
|
29
33
|
create(options?: BrowserPageOptions): Promise<BrowserPageInterface>;
|
|
30
34
|
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
35
|
close(): Promise<void>;
|
|
42
36
|
}
|
|
43
37
|
|
|
@@ -80,12 +74,12 @@ export declare const BROWSER_KILL_GRACE_MS = 3000;
|
|
|
80
74
|
/** Flags always passed to a launched browser process, alongside the caller's own. */
|
|
81
75
|
export declare const BROWSER_LAUNCH_ARGS: readonly string[];
|
|
82
76
|
|
|
83
|
-
/** Sentinel result returned by discovery when no browser is reachable. */
|
|
84
|
-
export declare const BROWSER_NOT_FOUND_RESULT: BrowserDiscoveryResult;
|
|
85
|
-
|
|
86
77
|
/** 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
78
|
export declare const BROWSER_PORT_PROBE_TIMEOUT_MS = 200;
|
|
88
79
|
|
|
80
|
+
/** Machine-readable error-context cause for an owned browser process exiting. */
|
|
81
|
+
export declare const BROWSER_PROCESS_EXIT_CAUSE = "process-exit";
|
|
82
|
+
|
|
89
83
|
/** Per-OS default Playwright browser cache directory, relative to the home directory (win32 uses `LOCALAPPDATA` directly). */
|
|
90
84
|
export declare const BROWSER_STORE_CACHE_DIRS: Readonly<Record<string, string>>;
|
|
91
85
|
|
|
@@ -101,6 +95,9 @@ export declare const BROWSER_STORE_GLOBS: Readonly<Record<string, string>>;
|
|
|
101
95
|
/** Name of the top-level Chromium symlink/binary Playwright maintains inside a browser store base. */
|
|
102
96
|
export declare const BROWSER_STORE_LINK_NAME = "chromium";
|
|
103
97
|
|
|
98
|
+
/** Machine-readable error-context cause for a CDP transport disconnecting while its browser remains alive. */
|
|
99
|
+
export declare const BROWSER_TRANSPORT_LOSS_CAUSE = "transport-loss";
|
|
100
|
+
|
|
104
101
|
/** 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
102
|
export declare const BROWSER_TRANSPORT_LOSS_DEFER_MS = 50;
|
|
106
103
|
|
|
@@ -125,7 +122,7 @@ export declare const BROWSER_WINDOWS_SUFFIXES: readonly string[];
|
|
|
125
122
|
* listening there, so a demanded fresh launch never silently attaches to a
|
|
126
123
|
* stranger browser
|
|
127
124
|
*/
|
|
128
|
-
export declare interface
|
|
125
|
+
export declare interface BrowserCDPOptions {
|
|
129
126
|
readonly port?: number;
|
|
130
127
|
readonly host?: string;
|
|
131
128
|
readonly endpoint?: string;
|
|
@@ -215,22 +212,19 @@ export declare type BrowserEventMap = {
|
|
|
215
212
|
* **Lifecycle:**
|
|
216
213
|
* - `discover` — passive CDP probe, no side effects
|
|
217
214
|
* - `connect` — establish connection using the strategy above
|
|
218
|
-
* - `
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* drives this same released/disconnected state automatically, preceded by
|
|
215
|
+
* - `adopt` — explicitly assume responsibility for terminating the connected
|
|
216
|
+
* browser, including a browser this instance attached to over CDP
|
|
217
|
+
* - `disconnect` — detach from the browser. For attached CDP connections this
|
|
218
|
+
* closes only the client. For owned launches and adopted connections, it
|
|
219
|
+
* retains ownership and the endpoint so the same instance can reconnect
|
|
220
|
+
* and remains responsible for eventual termination. An external disconnect
|
|
221
|
+
* (transport loss while the owned process is still alive, or the owned
|
|
222
|
+
* process exiting on its own) drives the disconnected state, preceded by
|
|
227
223
|
* a coded `error` — `connect()` on the same instance can reattach afterward.
|
|
228
|
-
* - `destroy` — release local resources. On
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* DETACH ONLY
|
|
232
|
-
* dropped WITHOUT sending any remote close to the browser, since other
|
|
233
|
-
* clients may share those targets. Idempotent.
|
|
224
|
+
* - `destroy` — release local resources. On a launched browser this closes
|
|
225
|
+
* pages/contexts, then kills and awaits the process. On an adopted browser
|
|
226
|
+
* it sends `Browser.close`. On a merely attached browser this is a LOCAL
|
|
227
|
+
* DETACH ONLY because other clients may share its targets. Idempotent.
|
|
234
228
|
* - `close` — graceful REMOTE shutdown: best-effort sends CDP `Browser.close`
|
|
235
229
|
* (works whether attached or owned), and when owned also awaits the
|
|
236
230
|
* process's exit (escalating to a kill only if it doesn't exit in time),
|
|
@@ -247,18 +241,28 @@ export declare interface BrowserInterface {
|
|
|
247
241
|
readonly engine: BrowserEngine;
|
|
248
242
|
readonly status: BrowserStatus;
|
|
249
243
|
readonly connection: BrowserConnection | undefined;
|
|
244
|
+
/**
|
|
245
|
+
* Whether this instance is responsible for terminating the represented browser.
|
|
246
|
+
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* `true` for launched and explicitly adopted sessions, `false` for an
|
|
249
|
+
* active attachment, and `undefined` when no session is represented.
|
|
250
|
+
*/
|
|
251
|
+
readonly owned: boolean | undefined;
|
|
250
252
|
readonly connected: boolean;
|
|
251
253
|
/**
|
|
252
254
|
* The process this instance launched, if any, while it is believed alive.
|
|
253
255
|
*
|
|
254
256
|
* @remarks
|
|
255
|
-
* Remains readable after a persistent disconnect
|
|
256
|
-
*
|
|
257
|
+
* Remains readable after a persistent disconnect (the process keeps
|
|
258
|
+
* running, detached from the transport) until `destroy()` or an
|
|
257
259
|
* observed process exit clears it.
|
|
258
260
|
*/
|
|
259
261
|
readonly pid: number | undefined;
|
|
260
262
|
discover(): Promise<BrowserDiscoveryResult>;
|
|
261
263
|
connect(): Promise<void>;
|
|
264
|
+
/** Assume responsibility for terminating the currently connected browser. */
|
|
265
|
+
adopt(): void;
|
|
262
266
|
disconnect(): Promise<void>;
|
|
263
267
|
context(index?: number): BrowserContextInterface | undefined;
|
|
264
268
|
contexts(): readonly BrowserContextInterface[];
|
|
@@ -279,6 +283,7 @@ export declare class BrowserNotConnectedError extends BrowserError {
|
|
|
279
283
|
*
|
|
280
284
|
* @remarks
|
|
281
285
|
* - `on` — initial event listeners wired at construction
|
|
286
|
+
* - `error` — observer error handler forwarded to the emitter
|
|
282
287
|
* - `headless` — launch in headless mode (default `true`; ignored for CDP connections)
|
|
283
288
|
* - `executable` — absolute path to a browser executable; when provided, skips
|
|
284
289
|
* system browser discovery and launches this binary directly
|
|
@@ -297,10 +302,11 @@ export declare class BrowserNotConnectedError extends BrowserError {
|
|
|
297
302
|
*/
|
|
298
303
|
export declare interface BrowserOptions {
|
|
299
304
|
readonly on?: EmitterHooks<BrowserEventMap>;
|
|
305
|
+
readonly error?: EmitterErrorHandler;
|
|
300
306
|
readonly headless?: boolean;
|
|
301
307
|
readonly executable?: string;
|
|
302
308
|
readonly profile?: string;
|
|
303
|
-
readonly cdp?:
|
|
309
|
+
readonly cdp?: BrowserCDPOptions;
|
|
304
310
|
readonly timeout?: number;
|
|
305
311
|
readonly viewport?: BrowserViewport;
|
|
306
312
|
readonly signal?: AbortSignal;
|
|
@@ -313,7 +319,7 @@ export declare interface BrowserOptions {
|
|
|
313
319
|
export declare type BrowserStatus = 'idle' | 'connecting' | 'connected' | 'disconnected' | 'error';
|
|
314
320
|
|
|
315
321
|
/** Classify a `/json/version` `Browser` string into a {@link BrowserEngine} (`Edg/` → edge, `Chrome/` → chrome, else chromium). */
|
|
316
|
-
export declare function browserToEngine(browser
|
|
322
|
+
export declare function browserToEngine(browser?: string): BrowserEngine;
|
|
317
323
|
|
|
318
324
|
/**
|
|
319
325
|
* Create a raw-CDP Browser façade.
|
|
@@ -360,7 +366,7 @@ export declare function defaultStoreBases(env: Readonly<Record<string, string |
|
|
|
360
366
|
* @param host - Host the browser exposes its CDP endpoint on (default `127.0.0.1`)
|
|
361
367
|
* @returns Normalized CDP targets
|
|
362
368
|
*/
|
|
363
|
-
export declare function
|
|
369
|
+
export declare function fetchCDPTargets(port: number, timeout: number, host?: string): Promise<readonly CDPTarget[]>;
|
|
364
370
|
|
|
365
371
|
/** Check the env-override keys (`PLAYWRIGHT_EXECUTABLE_PATH`, `CHROME_PATH`) in order, returning every one that exists. */
|
|
366
372
|
export declare function findAllEnvOverrides(env: Readonly<Record<string, string | undefined>>): readonly string[];
|
|
@@ -518,32 +524,21 @@ export declare interface SystemBrowserOptions {
|
|
|
518
524
|
*
|
|
519
525
|
* @throws When the endpoint does not become ready before the timeout
|
|
520
526
|
*/
|
|
521
|
-
export declare function
|
|
527
|
+
export declare function waitForCDPReady(port: number, timeout: number, host?: string, signal?: AbortSignal): Promise<string>;
|
|
522
528
|
|
|
523
529
|
/**
|
|
524
|
-
* `@orkestrel/websocket`-backed
|
|
525
|
-
* pipe a {@link import('@src/core').CDPClientInterface} sends and receives
|
|
526
|
-
* JSON-RPC frames over.
|
|
530
|
+
* `@orkestrel/websocket`-backed raw CDP text transport.
|
|
527
531
|
*
|
|
528
532
|
* @remarks
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
* `
|
|
532
|
-
*
|
|
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`.
|
|
533
|
+
* Performs and validates the RFC 6455 HTTP upgrade, then delegates frame
|
|
534
|
+
* handling to `@orkestrel/websocket`. Concurrent and repeated `start()` /
|
|
535
|
+
* `close()` calls share their active transition, and a later `start()` opens a
|
|
536
|
+
* fresh socket after the prior one closes.
|
|
542
537
|
*/
|
|
543
538
|
export declare class WebSocketCDPTransport implements CDPTransportInterface {
|
|
544
539
|
#private;
|
|
545
540
|
constructor(options: WebSocketCDPTransportOptions);
|
|
546
|
-
get emitter(): EmitterInterface<
|
|
541
|
+
get emitter(): EmitterInterface<CDPTransportEventMap_2>;
|
|
547
542
|
start(): Promise<void>;
|
|
548
543
|
send(data: string): Promise<void>;
|
|
549
544
|
close(): Promise<void>;
|
|
@@ -553,10 +548,14 @@ export declare class WebSocketCDPTransport implements CDPTransportInterface {
|
|
|
553
548
|
* Options for creating a WebSocketCDPTransport.
|
|
554
549
|
*
|
|
555
550
|
* @remarks
|
|
551
|
+
* - `on` — initial event listeners wired at construction
|
|
552
|
+
* - `error` — observer error handler forwarded to the emitter
|
|
556
553
|
* - `url` — the CDP WebSocket debugger URL to connect to
|
|
557
554
|
* - `timeout` — ms before the connection attempt fails (default from constants)
|
|
558
555
|
*/
|
|
559
556
|
export declare interface WebSocketCDPTransportOptions {
|
|
557
|
+
readonly on?: EmitterHooks<CDPTransportEventMap>;
|
|
558
|
+
readonly error?: EmitterErrorHandler;
|
|
560
559
|
readonly url: string;
|
|
561
560
|
readonly timeout?: number;
|
|
562
561
|
}
|