@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.
- package/README.md +14 -18
- package/dist/src/core/index.cjs +132 -101
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +463 -102
- package/dist/src/core/index.d.ts +463 -102
- package/dist/src/core/index.js +133 -102
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +93 -31
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +154 -56
- package/dist/src/server/index.d.ts +154 -56
- package/dist/src/server/index.js +93 -31
- package/dist/src/server/index.js.map +1 -1
- package/package.json +16 -17
|
@@ -14,35 +14,75 @@ let _orkestrel_emitter = require("@orkestrel/emitter");
|
|
|
14
14
|
let _orkestrel_websocket = require("@orkestrel/websocket");
|
|
15
15
|
let node_events = require("node:events");
|
|
16
16
|
//#region src/server/constants.ts
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Sets the default CDP port probed for an existing browser and used for launches, `9222`.
|
|
19
|
+
*/
|
|
18
20
|
var BROWSER_DEFAULT_CDP_PORT = 9222;
|
|
19
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Sets the default host probed for an existing browser and used for launches, `'127.0.0.1'`,
|
|
23
|
+
* which avoids `localhost` resolving to `::1` when Chromium binds `127.0.0.1`.
|
|
24
|
+
*/
|
|
20
25
|
var BROWSER_DEFAULT_HOST = "127.0.0.1";
|
|
21
|
-
/** Names the protocol prefix for CDP discovery requests
|
|
26
|
+
/** Names the protocol prefix for CDP discovery requests, `'http'`. */
|
|
22
27
|
var BROWSER_CDP_PROTOCOL = "http";
|
|
23
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Names the path appended to the CDP host to fetch version metadata, `'/json/version'`, which
|
|
30
|
+
* is where endpoint discovery reads.
|
|
31
|
+
*/
|
|
24
32
|
var BROWSER_CDP_VERSION_PATH = "/json/version";
|
|
25
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Names the path appended to the CDP host to list open targets — pages, workers, and every
|
|
35
|
+
* other target category Chromium reports — `'/json/list'`.
|
|
36
|
+
*/
|
|
26
37
|
var BROWSER_CDP_LIST_PATH = "/json/list";
|
|
27
38
|
/** Lists the flags always passed to a launched browser process, alongside the caller's own. */
|
|
28
39
|
var BROWSER_LAUNCH_ARGS = Object.freeze(["--no-first-run", "--no-default-browser-check"]);
|
|
29
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Names the flag that enables headless mode on a launched browser process, `'--headless=new'`.
|
|
42
|
+
*/
|
|
30
43
|
var BROWSER_HEADLESS_ARG = "--headless=new";
|
|
31
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Names the prefix for isolated browser profiles created beneath the operating-system temp
|
|
46
|
+
* directory, `'orkestrel-browser-'`.
|
|
47
|
+
*/
|
|
32
48
|
var BROWSER_PROFILE_PREFIX = "orkestrel-browser-";
|
|
33
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Bounds each launched-process exit window during TERM-to-KILL teardown at `3_000`
|
|
51
|
+
* milliseconds.
|
|
52
|
+
*/
|
|
34
53
|
var BROWSER_KILL_GRACE_MS = 3e3;
|
|
35
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* Bounds the `discover: false` port-occupancy probe before launching at `200` milliseconds,
|
|
56
|
+
* which is short because the probe only needs to detect an already-listening CDP endpoint
|
|
57
|
+
* rather than perform full discovery.
|
|
58
|
+
*/
|
|
36
59
|
var BROWSER_PORT_PROBE_TIMEOUT_MS = 200;
|
|
37
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Defers once for `50` milliseconds when a transport loss is observed on an owned process,
|
|
62
|
+
* giving a near-simultaneous process-exit event, which libuv may reap slightly later than the
|
|
63
|
+
* socket close, first say over the diagnosis.
|
|
64
|
+
*/
|
|
38
65
|
var BROWSER_TRANSPORT_LOSS_DEFER_MS = 50;
|
|
39
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Names the machine-readable error-context cause for an owned browser process exiting,
|
|
68
|
+
* `'process-exit'`.
|
|
69
|
+
*/
|
|
40
70
|
var BROWSER_PROCESS_EXIT_CAUSE = "process-exit";
|
|
41
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* Names the machine-readable error-context cause for a CDP transport disconnecting while its
|
|
73
|
+
* browser remains alive, `'transport-loss'`.
|
|
74
|
+
*/
|
|
42
75
|
var BROWSER_TRANSPORT_LOSS_CAUSE = "transport-loss";
|
|
43
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Lists the environment variables checked, in order, for an explicit browser executable path
|
|
78
|
+
* override: `PLAYWRIGHT_EXECUTABLE_PATH`, then `CHROME_PATH`.
|
|
79
|
+
*/
|
|
44
80
|
var BROWSER_ENV_PATH_KEYS = Object.freeze(["PLAYWRIGHT_EXECUTABLE_PATH", "CHROME_PATH"]);
|
|
45
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Lists the well-known Chrome/Chromium/Edge executable paths with no platform-specific root,
|
|
83
|
+
* keyed by `process.platform`, leaving `win32` empty because its roots come from
|
|
84
|
+
* `BROWSER_WINDOWS_SUFFIXES`.
|
|
85
|
+
*/
|
|
46
86
|
var BROWSER_EXECUTABLE_PATHS = Object.freeze({
|
|
47
87
|
linux: Object.freeze([
|
|
48
88
|
"/usr/bin/google-chrome",
|
|
@@ -68,7 +108,10 @@ var BROWSER_WINDOWS_SUFFIXES = Object.freeze([
|
|
|
68
108
|
"Microsoft\\Edge\\Application\\msedge.exe",
|
|
69
109
|
"Chromium\\Application\\chrome.exe"
|
|
70
110
|
]);
|
|
71
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Lists the fallback Windows install roots used when `PROGRAMFILES`, `PROGRAMFILES(X86)`, or
|
|
113
|
+
* `LOCALAPPDATA` is absent.
|
|
114
|
+
*/
|
|
72
115
|
var BROWSER_WINDOWS_ROOT_FALLBACKS = Object.freeze({
|
|
73
116
|
PROGRAMFILES: "C:\\Program Files",
|
|
74
117
|
"PROGRAMFILES(X86)": "C:\\Program Files (x86)"
|
|
@@ -83,16 +126,25 @@ var BROWSER_EXECUTABLE_NAMES = Object.freeze([
|
|
|
83
126
|
"chromium-browser",
|
|
84
127
|
"chrome"
|
|
85
128
|
]);
|
|
86
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* Names the environment variable that carries an additional Playwright browser store base
|
|
131
|
+
* directory, `'PLAYWRIGHT_BROWSERS_PATH'`.
|
|
132
|
+
*/
|
|
87
133
|
var BROWSER_STORE_ENV_KEY = "PLAYWRIGHT_BROWSERS_PATH";
|
|
88
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Lists the well-known Playwright browser store base directories checked in addition to
|
|
136
|
+
* `PLAYWRIGHT_BROWSERS_PATH`, starting with `/opt/pw-browsers`.
|
|
137
|
+
*/
|
|
89
138
|
var BROWSER_STORE_DEFAULT_DIRS = Object.freeze(["/opt/pw-browsers"]);
|
|
90
139
|
/** Names the per-OS default Playwright browser cache directory, relative to the home directory (win32 uses `LOCALAPPDATA` directly). */
|
|
91
140
|
var BROWSER_STORE_CACHE_DIRS = Object.freeze({
|
|
92
141
|
linux: ".cache/ms-playwright",
|
|
93
142
|
darwin: "Library/Caches/ms-playwright"
|
|
94
143
|
});
|
|
95
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* Names the top-level Chromium symlink or binary Playwright maintains inside a browser store
|
|
146
|
+
* base, `'chromium'`.
|
|
147
|
+
*/
|
|
96
148
|
var BROWSER_STORE_LINK_NAME = "chromium";
|
|
97
149
|
/**
|
|
98
150
|
* Lists the case-insensitive substrings identifying an executable path/name's browser
|
|
@@ -128,7 +180,8 @@ var BROWSER_STORE_GLOBS = Object.freeze({
|
|
|
128
180
|
//#endregion
|
|
129
181
|
//#region src/server/errors.ts
|
|
130
182
|
/**
|
|
131
|
-
* Reports that a CDP connection, discovery, or launch attempt failed
|
|
183
|
+
* Reports that a CDP connection, discovery, or launch attempt failed, under the code
|
|
184
|
+
* `BROWSER_CONNECTION_ERROR`.
|
|
132
185
|
*/
|
|
133
186
|
var BrowserConnectionError = class extends _src_core.BrowserError {
|
|
134
187
|
constructor(message, context) {
|
|
@@ -137,7 +190,8 @@ var BrowserConnectionError = class extends _src_core.BrowserError {
|
|
|
137
190
|
}
|
|
138
191
|
};
|
|
139
192
|
/**
|
|
140
|
-
* Reports that an operation requiring an active connection was attempted while disconnected
|
|
193
|
+
* Reports that an operation requiring an active connection was attempted while disconnected,
|
|
194
|
+
* under the code `BROWSER_NOT_CONNECTED_ERROR`.
|
|
141
195
|
*/
|
|
142
196
|
var BrowserNotConnectedError = class extends _src_core.BrowserError {
|
|
143
197
|
constructor(context) {
|
|
@@ -146,7 +200,8 @@ var BrowserNotConnectedError = class extends _src_core.BrowserError {
|
|
|
146
200
|
}
|
|
147
201
|
};
|
|
148
202
|
/**
|
|
149
|
-
* Reports that an operation was attempted after the
|
|
203
|
+
* Reports that an operation was attempted after the browser wrapper was destroyed, under the
|
|
204
|
+
* code `BROWSER_DESTROYED_ERROR`.
|
|
150
205
|
*/
|
|
151
206
|
var BrowserDestroyedError = class extends _src_core.BrowserError {
|
|
152
207
|
constructor(context) {
|
|
@@ -155,7 +210,7 @@ var BrowserDestroyedError = class extends _src_core.BrowserError {
|
|
|
155
210
|
}
|
|
156
211
|
};
|
|
157
212
|
/**
|
|
158
|
-
* Narrows an unknown value to BrowserConnectionError
|
|
213
|
+
* Narrows an unknown value to a `BrowserConnectionError`.
|
|
159
214
|
*
|
|
160
215
|
* @param value - Value to check
|
|
161
216
|
* @returns True if value is a BrowserConnectionError instance; false otherwise
|
|
@@ -164,7 +219,7 @@ function isBrowserConnectionError(value) {
|
|
|
164
219
|
return (0, _orkestrel_contract.isInstance)(value, BrowserConnectionError);
|
|
165
220
|
}
|
|
166
221
|
/**
|
|
167
|
-
* Narrows an unknown value to BrowserNotConnectedError
|
|
222
|
+
* Narrows an unknown value to a `BrowserNotConnectedError`.
|
|
168
223
|
*
|
|
169
224
|
* @param value - Value to check
|
|
170
225
|
* @returns True if value is a BrowserNotConnectedError instance; false otherwise
|
|
@@ -173,7 +228,7 @@ function isBrowserNotConnectedError(value) {
|
|
|
173
228
|
return (0, _orkestrel_contract.isInstance)(value, BrowserNotConnectedError);
|
|
174
229
|
}
|
|
175
230
|
/**
|
|
176
|
-
* Narrows an unknown value to BrowserDestroyedError
|
|
231
|
+
* Narrows an unknown value to a `BrowserDestroyedError`.
|
|
177
232
|
*
|
|
178
233
|
* @param value - Value to check
|
|
179
234
|
* @returns True if value is a BrowserDestroyedError instance; false otherwise
|
|
@@ -466,7 +521,8 @@ async function waitForCDPReady(port, timeout, host = BROWSER_DEFAULT_HOST, signa
|
|
|
466
521
|
});
|
|
467
522
|
}
|
|
468
523
|
/**
|
|
469
|
-
* Fetches the current CDP target list from a browser's `/json/list` endpoint
|
|
524
|
+
* Fetches the current CDP target list from a browser's `/json/list` endpoint, as a `Result`
|
|
525
|
+
* carrying either the targets or a coded `BrowserConnectionError`.
|
|
470
526
|
*
|
|
471
527
|
* @remarks
|
|
472
528
|
* The endpoint is a network boundary, so an unreachable host, a non-2xx
|
|
@@ -761,24 +817,29 @@ var FileBrowserWriter = class {
|
|
|
761
817
|
//#endregion
|
|
762
818
|
//#region src/server/factories.ts
|
|
763
819
|
/**
|
|
764
|
-
* Creates a raw-CDP
|
|
820
|
+
* Creates a raw-CDP `BrowserInterface` façade with discovery, connection, and lifecycle
|
|
821
|
+
* management.
|
|
765
822
|
*
|
|
766
823
|
* @param options - Connection, launch, and viewport configuration
|
|
767
824
|
* @returns A {@link BrowserInterface}
|
|
768
825
|
*
|
|
769
|
-
* @example
|
|
826
|
+
* @example Connect to a browser and drive a page
|
|
770
827
|
* ```ts
|
|
771
828
|
* import { createBrowser } from '@orkestrel/browser/server'
|
|
772
829
|
*
|
|
773
|
-
* const browser = createBrowser()
|
|
774
|
-
* await browser.connect()
|
|
830
|
+
* const browser = createBrowser({ headless: true })
|
|
831
|
+
* await browser.connect() // CDP endpoint discovery → connect, else launch
|
|
832
|
+
* const page = await browser.create({ url: 'https://example.com' })
|
|
833
|
+
* await page.click('#accept')
|
|
834
|
+
* const shot = await page.screenshot({ path: './out.png' })
|
|
835
|
+
* await browser.destroy()
|
|
775
836
|
* ```
|
|
776
837
|
*/
|
|
777
838
|
function createBrowser(options) {
|
|
778
839
|
return new Browser(options);
|
|
779
840
|
}
|
|
780
841
|
/**
|
|
781
|
-
* Creates a Node `WebSocket`-backed CDP
|
|
842
|
+
* Creates a Node `WebSocket`-backed `CDPTransportInterface` for the given CDP debugger URL.
|
|
782
843
|
*
|
|
783
844
|
* @param options - The CDP WebSocket debugger URL (and optional timeout)
|
|
784
845
|
* @returns A {@link CDPTransportInterface}
|
|
@@ -787,7 +848,8 @@ function createCDPTransport(options) {
|
|
|
787
848
|
return new WebSocketCDPTransport(options);
|
|
788
849
|
}
|
|
789
850
|
/**
|
|
790
|
-
* Creates a filesystem-backed
|
|
851
|
+
* Creates a filesystem-backed `BrowserWriterInterface` that persists bytes through
|
|
852
|
+
* `node:fs/promises`.
|
|
791
853
|
*
|
|
792
854
|
* @returns A {@link BrowserWriterInterface} that persists bytes through `node:fs/promises`
|
|
793
855
|
*/
|