@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
package/dist/src/core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { attempt, instanceOf, isArray, isBoolean, isFiniteNumber, isFunction, isInstance, isInteger, isRecord, isString, parseArray, parseEnum, parseJSON } from "@orkestrel/contract";
|
|
1
|
+
import { attempt, instanceOf, isArray, isBoolean, isFiniteNumber, isFunction, isInstance, isInteger, isRecord, isString, parseArray, parseEnum, parseJSON, parseJSONAs } from "@orkestrel/contract";
|
|
2
2
|
import { Emitter } from "@orkestrel/emitter";
|
|
3
3
|
import { createHTML, renderText } from "@orkestrel/html";
|
|
4
4
|
//#region src/core/constants.ts
|
|
@@ -71,14 +71,17 @@ var BASE64_LOOKUP = Object.freeze({
|
|
|
71
71
|
"+": 62,
|
|
72
72
|
"/": 63
|
|
73
73
|
});
|
|
74
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Sets the default timeout for browser connection, requests, and navigation, `30_000`
|
|
76
|
+
* milliseconds.
|
|
77
|
+
*/
|
|
75
78
|
var BROWSER_DEFAULT_TIMEOUT_MS = 3e4;
|
|
76
79
|
/**
|
|
77
|
-
* Caps the serialized-character length for an `evaluate()`/`content()` result
|
|
78
|
-
* enforced
|
|
80
|
+
* Caps the serialized-character length for an `evaluate()`/`content()` result at `2_500_000`,
|
|
81
|
+
* enforced in-page before the result is returned to CDP.
|
|
79
82
|
*
|
|
80
83
|
* @remarks
|
|
81
|
-
* This counts UTF-16
|
|
84
|
+
* This counts UTF-16 string length (`String#length`), not transport bytes —
|
|
82
85
|
* the actual CDP frame is UTF-8 encoded (up to 3 bytes/char for common
|
|
83
86
|
* multibyte content) and carries additional JSON/CDP framing overhead on top
|
|
84
87
|
* of the raw content. A `Runtime.evaluate` result above this size, once
|
|
@@ -94,8 +97,8 @@ var BROWSER_DEFAULT_TIMEOUT_MS = 3e4;
|
|
|
94
97
|
*/
|
|
95
98
|
var BROWSER_RESULT_LIMIT = 25e5;
|
|
96
99
|
/**
|
|
97
|
-
* Names the distinctive prefix for the in-page result-limit sentinel error,
|
|
98
|
-
* followed by the serialized length.
|
|
100
|
+
* Names the distinctive prefix for the in-page result-limit sentinel error,
|
|
101
|
+
* `'[[ORKESTREL_BROWSER_RESULT_LIMIT]]'`, immediately followed by the serialized length.
|
|
99
102
|
*
|
|
100
103
|
* @remarks
|
|
101
104
|
* Deliberately unlikely to appear in a page's own thrown error text (unlike
|
|
@@ -105,18 +108,29 @@ var BROWSER_RESULT_LIMIT = 25e5;
|
|
|
105
108
|
*/
|
|
106
109
|
var BROWSER_RESULT_LIMIT_SENTINEL_PREFIX = "[[ORKESTREL_BROWSER_RESULT_LIMIT]]";
|
|
107
110
|
/**
|
|
108
|
-
* Matches the in-page result-limit sentinel error message, anchored
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
111
|
+
* Matches the in-page result-limit sentinel error message, anchored immediately after the
|
|
112
|
+
* `Error:` (optionally `Uncaught Error:`) prefix Chromium prepends to a thrown error's
|
|
113
|
+
* description, `/^(?:Uncaught )?Error: \[\[ORKESTREL_BROWSER_RESULT_LIMIT\]\](\d+)/`.
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* The anchor matches the guard's own throw only at the start of the message, rather than
|
|
117
|
+
* wherever the substring happens to occur.
|
|
113
118
|
*/
|
|
114
119
|
var BROWSER_RESULT_LIMIT_PATTERN = new RegExp(`^(?:Uncaught )?Error: \\[\\[ORKESTREL_BROWSER_RESULT_LIMIT\\]\\](\\d+)`);
|
|
115
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
* Sets the poll interval while waiting for a selector to appear, `100` milliseconds.
|
|
122
|
+
*
|
|
123
|
+
* @remarks
|
|
124
|
+
* A wait adds the same interval as slack to its own CDP call timeout, so the in-page poll
|
|
125
|
+
* expires before the call carrying it. Host-side CDP readiness probes wait it out between
|
|
126
|
+
* attempts.
|
|
127
|
+
*/
|
|
116
128
|
var BROWSER_WAIT_POLL_INTERVAL_MS = 100;
|
|
117
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* Sets the default maximum node count accepted from a decoded CDP DOM snapshot, `100_000`.
|
|
131
|
+
*/
|
|
118
132
|
var BROWSER_SNAPSHOT_NODE_LIMIT = 1e5;
|
|
119
|
-
/** Names the isolated world used for iframe evaluation
|
|
133
|
+
/** Names the isolated world used for iframe evaluation, `'__orkestrelBrowserFrame'`. */
|
|
120
134
|
var BROWSER_FRAME_WORLD_NAME = "__orkestrelBrowserFrame";
|
|
121
135
|
/** Names the attribute the semantic test-id selector uses. */
|
|
122
136
|
var BROWSER_TEST_ID_ATTRIBUTE = "data-testid";
|
|
@@ -157,13 +171,13 @@ var BROWSER_MOUSE_BUTTON_MASKS = Object.freeze({
|
|
|
157
171
|
*/
|
|
158
172
|
var BROWSER_HAR_CREATOR = Object.freeze({
|
|
159
173
|
name: "@orkestrel/browser",
|
|
160
|
-
version: "0.0.
|
|
174
|
+
version: "0.0.17"
|
|
161
175
|
});
|
|
162
176
|
/** Names the attribute that tags temporary screenshot styles and masks. */
|
|
163
177
|
var BROWSER_SCREENSHOT_ATTRIBUTE = "data-orkestrel-screenshot";
|
|
164
178
|
/**
|
|
165
|
-
* Bounds
|
|
166
|
-
*
|
|
179
|
+
* Bounds the best-effort `Page.stopLoading` call issued after a failed `navigate()` at `1_000`
|
|
180
|
+
* milliseconds.
|
|
167
181
|
*
|
|
168
182
|
* @remarks
|
|
169
183
|
* A wedged renderer can make the underlying CDP call hang for the full
|
|
@@ -172,23 +186,26 @@ var BROWSER_SCREENSHOT_ATTRIBUTE = "data-orkestrel-screenshot";
|
|
|
172
186
|
* it. Best-effort only — never masks the original navigate error.
|
|
173
187
|
*/
|
|
174
188
|
var BROWSER_STOP_LOADING_TIMEOUT_MS = 1e3;
|
|
175
|
-
/** Sets the default viewport width
|
|
189
|
+
/** Sets the default viewport width, `1280` pixels. */
|
|
176
190
|
var BROWSER_DEFAULT_VIEWPORT_WIDTH = 1280;
|
|
177
|
-
/** Sets the default viewport height
|
|
191
|
+
/** Sets the default viewport height, `720` pixels. */
|
|
178
192
|
var BROWSER_DEFAULT_VIEWPORT_HEIGHT = 720;
|
|
179
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* Names the CDP runtime binding the codegen recorder script calls into,
|
|
195
|
+
* `'__orkestrelBrowserCodegen'`.
|
|
196
|
+
*/
|
|
180
197
|
var BROWSER_CODEGEN_BINDING_NAME = "__orkestrelBrowserCodegen";
|
|
181
198
|
/**
|
|
182
199
|
* Holds the in-page recorder script injected through `Page.addScriptToEvaluateOnNewDocument`
|
|
183
200
|
* and `Runtime.evaluate`.
|
|
184
201
|
*
|
|
185
202
|
* @remarks
|
|
186
|
-
* Attaches capturing-phase listeners for `click`, `input` (fill), and
|
|
187
|
-
* `
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* install exactly once per document (`window[name]` sentinel) so
|
|
191
|
-
* injection on every new document is idempotent.
|
|
203
|
+
* Attaches capturing-phase listeners for `click`, `input` (fill), and `change` (select) on
|
|
204
|
+
* `document`, builds a stable CSS selector for the target element, and forwards each action
|
|
205
|
+
* to the CDP binding ({@link BROWSER_CODEGEN_BINDING_NAME}) as a JSON string payload. A
|
|
206
|
+
* `contenteditable` fill is captured through `input` events, the same way an input or a
|
|
207
|
+
* textarea is. Guarded to install exactly once per document (`window[name]` sentinel) so
|
|
208
|
+
* repeated injection on every new document is idempotent.
|
|
192
209
|
*/
|
|
193
210
|
var BROWSER_CODEGEN_SOURCE = `(() => {
|
|
194
211
|
const bindingName = ${JSON.stringify(BROWSER_CODEGEN_BINDING_NAME)}
|
|
@@ -281,11 +298,11 @@ var BROWSER_CODEGEN_SOURCE = `(() => {
|
|
|
281
298
|
//#endregion
|
|
282
299
|
//#region src/core/errors.ts
|
|
283
300
|
/**
|
|
284
|
-
* Represents the base error for all browser automation operations
|
|
301
|
+
* Represents the base error for all browser automation operations, carrying the code
|
|
302
|
+
* `BROWSER_ERROR` and a `context` record.
|
|
285
303
|
*
|
|
286
304
|
* @remarks
|
|
287
|
-
*
|
|
288
|
-
* callers can branch in a `catch` without parsing message strings.
|
|
305
|
+
* A caller branches in a `catch` on the `code` rather than parsing message strings.
|
|
289
306
|
*/
|
|
290
307
|
var BrowserError = class extends Error {
|
|
291
308
|
code;
|
|
@@ -298,7 +315,8 @@ var BrowserError = class extends Error {
|
|
|
298
315
|
}
|
|
299
316
|
};
|
|
300
317
|
/**
|
|
301
|
-
* Reports that a selector-based lookup or wait timed out without the element appearing
|
|
318
|
+
* Reports that a selector-based lookup or wait timed out without the element appearing, under
|
|
319
|
+
* the code `BROWSER_SELECTOR_ERROR`.
|
|
302
320
|
*/
|
|
303
321
|
var BrowserSelectorError = class extends BrowserError {
|
|
304
322
|
constructor(message, context) {
|
|
@@ -307,12 +325,12 @@ var BrowserSelectorError = class extends BrowserError {
|
|
|
307
325
|
}
|
|
308
326
|
};
|
|
309
327
|
/**
|
|
310
|
-
* Reports that a CDP request received an error response from the remote endpoint
|
|
328
|
+
* Reports that a CDP request received an error response from the remote endpoint, under the
|
|
329
|
+
* code `BROWSER_CDP_ERROR`, with the `method`, the CDP `code`, the `message`, and any `data`
|
|
330
|
+
* in its context.
|
|
311
331
|
*
|
|
312
332
|
* @remarks
|
|
313
|
-
*
|
|
314
|
-
* `message`, and `data` (when present) in `context`, so callers can branch
|
|
315
|
-
* on the protocol-level error instead of parsing the message string.
|
|
333
|
+
* Branch on the protocol-level error in `context` instead of parsing the message string.
|
|
316
334
|
*/
|
|
317
335
|
var CDPError = class extends BrowserError {
|
|
318
336
|
constructor(message, context) {
|
|
@@ -321,9 +339,9 @@ var CDPError = class extends BrowserError {
|
|
|
321
339
|
}
|
|
322
340
|
};
|
|
323
341
|
/**
|
|
324
|
-
* Reports that a CDP request could not be sent or completed because the client was not in
|
|
325
|
-
*
|
|
326
|
-
*
|
|
342
|
+
* Reports that a CDP request could not be sent or completed because the client was not in a
|
|
343
|
+
* connectable state — not connected, closed while connecting, or the connection dropped
|
|
344
|
+
* mid-request — under the code `BROWSER_CDP_CONNECTION_ERROR`.
|
|
327
345
|
*/
|
|
328
346
|
var CDPConnectionError = class extends BrowserError {
|
|
329
347
|
constructor(message, context) {
|
|
@@ -332,7 +350,8 @@ var CDPConnectionError = class extends BrowserError {
|
|
|
332
350
|
}
|
|
333
351
|
};
|
|
334
352
|
/**
|
|
335
|
-
* Reports that a pending CDP request was not answered within its timeout window
|
|
353
|
+
* Reports that a pending CDP request was not answered within its timeout window, under the
|
|
354
|
+
* code `BROWSER_CDP_TIMEOUT_ERROR`.
|
|
336
355
|
*/
|
|
337
356
|
var CDPTimeoutError = class extends BrowserError {
|
|
338
357
|
constructor(message, context) {
|
|
@@ -341,8 +360,9 @@ var CDPTimeoutError = class extends BrowserError {
|
|
|
341
360
|
}
|
|
342
361
|
};
|
|
343
362
|
/**
|
|
344
|
-
* Reports that an `evaluate()`/`content()` result exceeded {@link BROWSER_RESULT_LIMIT}
|
|
345
|
-
*
|
|
363
|
+
* Reports that an `evaluate()`/`content()` result exceeded {@link BROWSER_RESULT_LIMIT} and
|
|
364
|
+
* was rejected in-page before it could overflow the CDP transport frame, under the code
|
|
365
|
+
* `BROWSER_RESULT_LIMIT_ERROR`.
|
|
346
366
|
*/
|
|
347
367
|
var BrowserResultLimitError = class extends BrowserError {
|
|
348
368
|
constructor(message, context) {
|
|
@@ -351,7 +371,7 @@ var BrowserResultLimitError = class extends BrowserError {
|
|
|
351
371
|
}
|
|
352
372
|
};
|
|
353
373
|
/**
|
|
354
|
-
* Narrows an unknown value to BrowserError
|
|
374
|
+
* Narrows an unknown value to a `BrowserError`.
|
|
355
375
|
*
|
|
356
376
|
* @param value - Value to check
|
|
357
377
|
* @returns True if value is a BrowserError instance; false otherwise
|
|
@@ -360,7 +380,7 @@ function isBrowserError(value) {
|
|
|
360
380
|
return isInstance(value, BrowserError);
|
|
361
381
|
}
|
|
362
382
|
/**
|
|
363
|
-
* Narrows an unknown value to BrowserSelectorError
|
|
383
|
+
* Narrows an unknown value to a `BrowserSelectorError`.
|
|
364
384
|
*
|
|
365
385
|
* @param value - Value to check
|
|
366
386
|
* @returns True if value is a BrowserSelectorError instance; false otherwise
|
|
@@ -369,7 +389,7 @@ function isBrowserSelectorError(value) {
|
|
|
369
389
|
return isInstance(value, BrowserSelectorError);
|
|
370
390
|
}
|
|
371
391
|
/**
|
|
372
|
-
* Narrows an unknown value to CDPError
|
|
392
|
+
* Narrows an unknown value to a `CDPError`.
|
|
373
393
|
*
|
|
374
394
|
* @param value - Value to check
|
|
375
395
|
* @returns True if value is a CDPError instance; false otherwise
|
|
@@ -378,7 +398,7 @@ function isCDPError(value) {
|
|
|
378
398
|
return isInstance(value, CDPError);
|
|
379
399
|
}
|
|
380
400
|
/**
|
|
381
|
-
* Narrows an unknown value to CDPConnectionError
|
|
401
|
+
* Narrows an unknown value to a `CDPConnectionError`.
|
|
382
402
|
*
|
|
383
403
|
* @param value - Value to check
|
|
384
404
|
* @returns True if value is a CDPConnectionError instance; false otherwise
|
|
@@ -387,7 +407,7 @@ function isCDPConnectionError(value) {
|
|
|
387
407
|
return isInstance(value, CDPConnectionError);
|
|
388
408
|
}
|
|
389
409
|
/**
|
|
390
|
-
* Narrows an unknown value to CDPTimeoutError
|
|
410
|
+
* Narrows an unknown value to a `CDPTimeoutError`.
|
|
391
411
|
*
|
|
392
412
|
* @param value - Value to check
|
|
393
413
|
* @returns True if value is a CDPTimeoutError instance; false otherwise
|
|
@@ -396,7 +416,7 @@ function isCDPTimeoutError(value) {
|
|
|
396
416
|
return isInstance(value, CDPTimeoutError);
|
|
397
417
|
}
|
|
398
418
|
/**
|
|
399
|
-
* Narrows an unknown value to BrowserResultLimitError
|
|
419
|
+
* Narrows an unknown value to a `BrowserResultLimitError`.
|
|
400
420
|
*
|
|
401
421
|
* @param value - Value to check
|
|
402
422
|
* @returns True if value is a BrowserResultLimitError instance; false otherwise
|
|
@@ -574,8 +594,8 @@ function parseBrowserWebSocketFrame(value) {
|
|
|
574
594
|
*/
|
|
575
595
|
function parseBrowserBindingCall(value) {
|
|
576
596
|
if (!isRecord(value) || !isString(value["name"]) || !isString(value["payload"]) || !isInteger(value["executionContextId"])) return;
|
|
577
|
-
const payload =
|
|
578
|
-
if (
|
|
597
|
+
const payload = parseJSONAs(value["payload"], isRecord);
|
|
598
|
+
if (payload === void 0 || !isString(payload["id"]) || !isString(payload["name"]) || !isArray(payload["args"]) || payload["name"] !== value["name"]) return;
|
|
579
599
|
return {
|
|
580
600
|
id: payload["id"],
|
|
581
601
|
name: payload["name"],
|
|
@@ -701,8 +721,8 @@ function parseBrowserDownloadProgress(value) {
|
|
|
701
721
|
*/
|
|
702
722
|
function parseCodegenActionPayload(payload) {
|
|
703
723
|
if (!isString(payload)) return void 0;
|
|
704
|
-
const parsed =
|
|
705
|
-
if (
|
|
724
|
+
const parsed = parseJSONAs(payload, isRecord);
|
|
725
|
+
if (parsed === void 0) return void 0;
|
|
706
726
|
const action = parseEnum(parsed["action"], [
|
|
707
727
|
"click",
|
|
708
728
|
"fill",
|
|
@@ -728,8 +748,8 @@ function parseCodegenActionPayload(payload) {
|
|
|
728
748
|
}
|
|
729
749
|
}
|
|
730
750
|
/**
|
|
731
|
-
* Coerces a `Page.frameNavigated` CDP event to a `navigate` codegen action, or
|
|
732
|
-
*
|
|
751
|
+
* Coerces a `Page.frameNavigated` CDP event to a `navigate` codegen action, or `undefined`
|
|
752
|
+
* off-shape and for every frame but the top-level one.
|
|
733
753
|
*
|
|
734
754
|
* @remarks
|
|
735
755
|
* Only the top-level (main) frame's navigation is recorded — a frame
|
|
@@ -756,8 +776,7 @@ function parseCodegenNavigateAction(params) {
|
|
|
756
776
|
* @returns The number array, or undefined
|
|
757
777
|
*/
|
|
758
778
|
function parseNumberArray(value) {
|
|
759
|
-
|
|
760
|
-
return value;
|
|
779
|
+
return parseArray(value, isFiniteNumber);
|
|
761
780
|
}
|
|
762
781
|
/**
|
|
763
782
|
* Coerces one CDP snapshot string-table index to its string, or `undefined`
|
|
@@ -772,8 +791,7 @@ function parseSnapshotString(strings, index) {
|
|
|
772
791
|
return strings[index];
|
|
773
792
|
}
|
|
774
793
|
/**
|
|
775
|
-
* Coerces a
|
|
776
|
-
* off-shape.
|
|
794
|
+
* Coerces a four-number CSS-pixel rectangle to a `BrowserRect`, or `undefined` off-shape.
|
|
777
795
|
*
|
|
778
796
|
* @param value - Candidate four-number array
|
|
779
797
|
* @returns A rectangle, or undefined
|
|
@@ -870,7 +888,8 @@ function browserHeadersToProtocol(headers) {
|
|
|
870
888
|
}));
|
|
871
889
|
}
|
|
872
890
|
/**
|
|
873
|
-
* Decodes a Chromium Headers object into string values
|
|
891
|
+
* Decodes a Chromium Headers object into string values, skipping every entry that is neither a
|
|
892
|
+
* string nor a finite number.
|
|
874
893
|
*
|
|
875
894
|
* @param value - Unknown headers
|
|
876
895
|
* @returns Frozen-compatible header record
|
|
@@ -1055,7 +1074,8 @@ function matchesBrowserURL(url, pattern) {
|
|
|
1055
1074
|
return new RegExp(`^${source}$`).test(url);
|
|
1056
1075
|
}
|
|
1057
1076
|
/**
|
|
1058
|
-
* Decodes the `Page.addScriptToEvaluateOnNewDocument` result
|
|
1077
|
+
* Decodes the `Page.addScriptToEvaluateOnNewDocument` result, throwing a `BrowserError`
|
|
1078
|
+
* off-shape.
|
|
1059
1079
|
*
|
|
1060
1080
|
* @param value - Unknown protocol result
|
|
1061
1081
|
* @returns Script identifier
|
|
@@ -1073,7 +1093,7 @@ function validateBrowserPoint(point) {
|
|
|
1073
1093
|
if (!isFiniteNumber(point.x) || !isFiniteNumber(point.y)) throw new BrowserError("Browser input coordinates must be finite", void 0, { point });
|
|
1074
1094
|
}
|
|
1075
1095
|
/**
|
|
1076
|
-
* Validates the bounded
|
|
1096
|
+
* Validates the bounded delay, count, steps, and position of one trusted-input operation.
|
|
1077
1097
|
*
|
|
1078
1098
|
* @remarks
|
|
1079
1099
|
* The parameter is `BrowserOperationOptions`, so one validator answers for a
|
|
@@ -1239,7 +1259,8 @@ function validateBrowserRange(value, field, minimum, maximum, inclusive = true)
|
|
|
1239
1259
|
});
|
|
1240
1260
|
}
|
|
1241
1261
|
/**
|
|
1242
|
-
* Decodes Accessibility-domain nodes into a flat serializable tree
|
|
1262
|
+
* Decodes Accessibility-domain nodes into a flat serializable tree, throwing a `BrowserError`
|
|
1263
|
+
* off-shape.
|
|
1243
1264
|
*
|
|
1244
1265
|
* @param value - Unknown full or partial AX-tree result
|
|
1245
1266
|
* @returns Valid accessibility snapshot
|
|
@@ -1275,7 +1296,7 @@ function readBrowserAccessibility(value) {
|
|
|
1275
1296
|
};
|
|
1276
1297
|
}
|
|
1277
1298
|
/**
|
|
1278
|
-
* Decodes an Accessibility-domain AXValue.
|
|
1299
|
+
* Decodes an Accessibility-domain AXValue, or `undefined` when the record carries none.
|
|
1279
1300
|
*
|
|
1280
1301
|
* @param value - Unknown AX value
|
|
1281
1302
|
* @returns Underlying value
|
|
@@ -1300,7 +1321,7 @@ function concatBytes(chunks) {
|
|
|
1300
1321
|
return result;
|
|
1301
1322
|
}
|
|
1302
1323
|
/**
|
|
1303
|
-
* Decodes one `IO.read` response.
|
|
1324
|
+
* Decodes one `IO.read` response, throwing a `BrowserError` off-shape.
|
|
1304
1325
|
*
|
|
1305
1326
|
* @param value - Unknown protocol result
|
|
1306
1327
|
* @returns Valid stream chunk
|
|
@@ -1313,7 +1334,7 @@ function readBrowserStreamChunk(value) {
|
|
|
1313
1334
|
};
|
|
1314
1335
|
}
|
|
1315
1336
|
/**
|
|
1316
|
-
* Decodes JavaScript precise coverage.
|
|
1337
|
+
* Decodes JavaScript precise coverage, throwing a `BrowserError` off-shape.
|
|
1317
1338
|
*
|
|
1318
1339
|
* @param value - Unknown `Profiler.takePreciseCoverage` result
|
|
1319
1340
|
* @returns Script coverage
|
|
@@ -1341,7 +1362,7 @@ function readBrowserScriptCoverage(value) {
|
|
|
1341
1362
|
});
|
|
1342
1363
|
}
|
|
1343
1364
|
/**
|
|
1344
|
-
* Decodes CSS rule usage.
|
|
1365
|
+
* Decodes CSS rule usage, throwing a `BrowserError` off-shape.
|
|
1345
1366
|
*
|
|
1346
1367
|
* @param value - Unknown `CSS.stopRuleUsageTracking` result
|
|
1347
1368
|
* @returns Stylesheet coverage
|
|
@@ -1365,7 +1386,7 @@ function readBrowserStyleCoverage(value) {
|
|
|
1365
1386
|
}));
|
|
1366
1387
|
}
|
|
1367
1388
|
/**
|
|
1368
|
-
* Decodes coverage ranges.
|
|
1389
|
+
* Decodes and normalizes coverage ranges, throwing a `BrowserError` off-shape.
|
|
1369
1390
|
*
|
|
1370
1391
|
* @param value - Unknown ranges
|
|
1371
1392
|
* @param script - Script index for diagnostics
|
|
@@ -1386,7 +1407,7 @@ function readBrowserCoverageRanges(value, script) {
|
|
|
1386
1407
|
});
|
|
1387
1408
|
}
|
|
1388
1409
|
/**
|
|
1389
|
-
* Decodes Performance-domain metrics.
|
|
1410
|
+
* Decodes Performance-domain metrics, throwing a `BrowserError` off-shape.
|
|
1390
1411
|
*
|
|
1391
1412
|
* @param value - Unknown metrics result
|
|
1392
1413
|
* @returns Valid metrics
|
|
@@ -1402,7 +1423,7 @@ function readBrowserMetrics(value) {
|
|
|
1402
1423
|
});
|
|
1403
1424
|
}
|
|
1404
1425
|
/**
|
|
1405
|
-
* Decodes one CPU profile.
|
|
1426
|
+
* Decodes one CPU profile, throwing a `BrowserError` off-shape.
|
|
1406
1427
|
*
|
|
1407
1428
|
* @param value - Unknown `Profiler.stop` result
|
|
1408
1429
|
* @returns Valid profile
|
|
@@ -1435,7 +1456,7 @@ function readBrowserProfile(value) {
|
|
|
1435
1456
|
};
|
|
1436
1457
|
}
|
|
1437
1458
|
/**
|
|
1438
|
-
* Decodes a CPU profile call frame.
|
|
1459
|
+
* Decodes a CPU profile call frame, throwing a `BrowserError` off-shape.
|
|
1439
1460
|
*
|
|
1440
1461
|
* @param value - Unknown call frame
|
|
1441
1462
|
* @param node - Node index for diagnostics
|
|
@@ -1487,7 +1508,7 @@ function cookieToProtocol(cookie) {
|
|
|
1487
1508
|
return result;
|
|
1488
1509
|
}
|
|
1489
1510
|
/**
|
|
1490
|
-
* Decodes cookies
|
|
1511
|
+
* Decodes the cookies `Storage.getCookies` returns, throwing a `BrowserError` off-shape.
|
|
1491
1512
|
*
|
|
1492
1513
|
* @param value - Unknown protocol result
|
|
1493
1514
|
* @returns Valid cookies
|
|
@@ -1497,7 +1518,7 @@ function readBrowserCookies(value) {
|
|
|
1497
1518
|
return value["cookies"].map((candidate, index) => readBrowserCookie(candidate, index));
|
|
1498
1519
|
}
|
|
1499
1520
|
/**
|
|
1500
|
-
* Decodes one Chromium cookie.
|
|
1521
|
+
* Decodes one Chromium cookie, throwing a `BrowserError` off-shape.
|
|
1501
1522
|
*
|
|
1502
1523
|
* @param value - Unknown cookie record
|
|
1503
1524
|
* @param index - Source array position for diagnostics
|
|
@@ -1541,7 +1562,7 @@ function matchesBrowserCookieURL(cookie, value) {
|
|
|
1541
1562
|
return domainMatches && pathMatches && secureMatches;
|
|
1542
1563
|
}
|
|
1543
1564
|
/**
|
|
1544
|
-
* Decodes one in-page web-storage snapshot.
|
|
1565
|
+
* Decodes one in-page web-storage snapshot, throwing a `BrowserError` off-shape.
|
|
1545
1566
|
*
|
|
1546
1567
|
* @param value - Unknown evaluation result
|
|
1547
1568
|
* @param origin - Origin represented by the result
|
|
@@ -1556,7 +1577,7 @@ function readBrowserStorageOrigin(value, origin) {
|
|
|
1556
1577
|
};
|
|
1557
1578
|
}
|
|
1558
1579
|
/**
|
|
1559
|
-
* Decodes a list of web-storage entries.
|
|
1580
|
+
* Decodes a list of web-storage entries, throwing a `BrowserError` off-shape.
|
|
1560
1581
|
*
|
|
1561
1582
|
* @param value - Unknown entry list
|
|
1562
1583
|
* @param origin - Origin used for diagnostics
|
|
@@ -1607,7 +1628,7 @@ function mediaToFeatures(media) {
|
|
|
1607
1628
|
return features;
|
|
1608
1629
|
}
|
|
1609
1630
|
/**
|
|
1610
|
-
* Decodes a Chromium runtime stack trace.
|
|
1631
|
+
* Decodes a Chromium runtime stack trace, skipping every off-shape call frame.
|
|
1611
1632
|
*
|
|
1612
1633
|
* @param value - Unknown stack trace or call-frame list
|
|
1613
1634
|
* @returns Valid stack frames
|
|
@@ -1628,7 +1649,8 @@ function readBrowserStack(value) {
|
|
|
1628
1649
|
return stack;
|
|
1629
1650
|
}
|
|
1630
1651
|
/**
|
|
1631
|
-
* Decodes a Runtime remote object's printable value
|
|
1652
|
+
* Decodes a Runtime remote object's printable value, falling back to its unserializable form
|
|
1653
|
+
* and then its description, or `undefined` when it carries none.
|
|
1632
1654
|
*
|
|
1633
1655
|
* @param value - Unknown remote object
|
|
1634
1656
|
* @returns By-value data or a description
|
|
@@ -1640,7 +1662,8 @@ function readBrowserRemoteValue(value) {
|
|
|
1640
1662
|
if (isString(value["description"])) return value["description"];
|
|
1641
1663
|
}
|
|
1642
1664
|
/**
|
|
1643
|
-
* Decodes one CDP `Runtime.evaluate` result
|
|
1665
|
+
* Decodes one CDP `Runtime.evaluate` result, throwing a `BrowserError` on a failed evaluation
|
|
1666
|
+
* and a `BrowserResultLimitError` past the guarded result size.
|
|
1644
1667
|
*
|
|
1645
1668
|
* @param value - Unknown CDP result
|
|
1646
1669
|
* @returns The returned by-value payload, or undefined
|
|
@@ -1676,13 +1699,12 @@ function requireBrowserString(value, field) {
|
|
|
1676
1699
|
throw new BrowserError(`${field} failed: no string value returned`);
|
|
1677
1700
|
}
|
|
1678
1701
|
/**
|
|
1679
|
-
* Normalizes
|
|
1702
|
+
* Normalizes recorded codegen actions, collapsing consecutive `fill` actions on the same
|
|
1703
|
+
* selector into the latest value.
|
|
1680
1704
|
*
|
|
1681
1705
|
* @remarks
|
|
1682
|
-
*
|
|
1683
|
-
*
|
|
1684
|
-
* compiled script reflects the final typed value rather than every
|
|
1685
|
-
* intermediate keystroke.
|
|
1706
|
+
* A text input fires one `input` event per keystroke, so the compiled script reflects
|
|
1707
|
+
* the final typed value rather than every intermediate keystroke.
|
|
1686
1708
|
*
|
|
1687
1709
|
* @param actions - Raw recorded actions, in capture order
|
|
1688
1710
|
* @returns Normalized actions, in the same order
|
|
@@ -1700,7 +1722,8 @@ function normalizeCodegenActions(actions) {
|
|
|
1700
1722
|
return result;
|
|
1701
1723
|
}
|
|
1702
1724
|
/**
|
|
1703
|
-
* Decodes a flattened CDP `Page.getFrameTree` result
|
|
1725
|
+
* Decodes a flattened CDP `Page.getFrameTree` result into depth-first frame metadata, skipping
|
|
1726
|
+
* every off-shape frame.
|
|
1704
1727
|
*
|
|
1705
1728
|
* @param value - Unknown CDP result
|
|
1706
1729
|
* @returns Frame metadata in depth-first, main-frame-first order
|
|
@@ -1729,7 +1752,8 @@ function readBrowserFrames(value) {
|
|
|
1729
1752
|
return frames;
|
|
1730
1753
|
}
|
|
1731
1754
|
/**
|
|
1732
|
-
* Decodes the first `DOM.getContentQuads` quad and its center
|
|
1755
|
+
* Decodes the first `DOM.getContentQuads` quad and its center, throwing a `BrowserError`
|
|
1756
|
+
* off-shape.
|
|
1733
1757
|
*
|
|
1734
1758
|
* @param value - Unknown CDP result
|
|
1735
1759
|
* @returns Decoded quad
|
|
@@ -1765,7 +1789,8 @@ function readBrowserQuad(value) {
|
|
|
1765
1789
|
};
|
|
1766
1790
|
}
|
|
1767
1791
|
/**
|
|
1768
|
-
* Extracts a keyboard chord such as `Control+Shift+P` into its parts
|
|
1792
|
+
* Extracts a keyboard chord such as `Control+Shift+P` into its parts, throwing a
|
|
1793
|
+
* `BrowserError` on an empty chord or an unsupported modifier.
|
|
1769
1794
|
*
|
|
1770
1795
|
* @param value - Chord source
|
|
1771
1796
|
* @returns Canonical modifiers and terminal key
|
|
@@ -1803,7 +1828,7 @@ function computeBrowserModifiers(modifiers) {
|
|
|
1803
1828
|
/**
|
|
1804
1829
|
* Computes the CDP Input pressed-button bitmask.
|
|
1805
1830
|
*
|
|
1806
|
-
* @param buttons -
|
|
1831
|
+
* @param buttons - Pressed public mouse buttons
|
|
1807
1832
|
* @returns Combined CDP pressed-button mask
|
|
1808
1833
|
*/
|
|
1809
1834
|
function computeBrowserButtons(buttons) {
|
|
@@ -1943,7 +1968,8 @@ function keyToBrowserInput(value) {
|
|
|
1943
1968
|
};
|
|
1944
1969
|
}
|
|
1945
1970
|
/**
|
|
1946
|
-
* Decodes CDP snapshot sparse string data
|
|
1971
|
+
* Decodes CDP snapshot sparse string data into a node-index map, skipping every off-shape
|
|
1972
|
+
* entry.
|
|
1947
1973
|
*
|
|
1948
1974
|
* @param value - Sparse `{ index, value }` record
|
|
1949
1975
|
* @param strings - Snapshot string table
|
|
@@ -1963,7 +1989,8 @@ function readRareStringData(value, strings) {
|
|
|
1963
1989
|
return decoded;
|
|
1964
1990
|
}
|
|
1965
1991
|
/**
|
|
1966
|
-
* Decodes CDP snapshot sparse boolean data
|
|
1992
|
+
* Decodes CDP snapshot sparse boolean data into a set of node indexes, skipping every
|
|
1993
|
+
* off-shape entry.
|
|
1967
1994
|
*
|
|
1968
1995
|
* @param value - Sparse `{ index }` record
|
|
1969
1996
|
* @returns Set of node indexes whose value is true
|
|
@@ -1973,7 +2000,8 @@ function readRareBooleanData(value) {
|
|
|
1973
2000
|
return new Set(parseNumberArray(value["index"]) ?? []);
|
|
1974
2001
|
}
|
|
1975
2002
|
/**
|
|
1976
|
-
* Decodes CDP snapshot sparse integer data
|
|
2003
|
+
* Decodes CDP snapshot sparse integer data into a node-index map, skipping every off-shape
|
|
2004
|
+
* entry.
|
|
1977
2005
|
*
|
|
1978
2006
|
* @param value - Sparse `{ index, value }` record
|
|
1979
2007
|
* @returns Node-index to integer map
|
|
@@ -1992,7 +2020,7 @@ function readRareIntegerData(value) {
|
|
|
1992
2020
|
return decoded;
|
|
1993
2021
|
}
|
|
1994
2022
|
/**
|
|
1995
|
-
* Decodes flattened CDP node attributes.
|
|
2023
|
+
* Decodes flattened CDP node attributes into a frozen record, skipping every off-shape pair.
|
|
1996
2024
|
*
|
|
1997
2025
|
* @param value - Candidate string-index array
|
|
1998
2026
|
* @param strings - Snapshot string table
|
|
@@ -2010,7 +2038,9 @@ function readBrowserAttributes(value, strings) {
|
|
|
2010
2038
|
return Object.freeze(attributes);
|
|
2011
2039
|
}
|
|
2012
2040
|
/**
|
|
2013
|
-
* Decodes a CDP `DOMSnapshot.captureSnapshot` result
|
|
2041
|
+
* Decodes a CDP `DOMSnapshot.captureSnapshot` result into a serializable
|
|
2042
|
+
* `BrowserSnapshotInput`, throwing a `BrowserError` off-shape and a `BrowserResultLimitError`
|
|
2043
|
+
* past the configured node limit.
|
|
2014
2044
|
*
|
|
2015
2045
|
* @param value - Unknown CDP result
|
|
2016
2046
|
* @param styles - Requested computed-style names, in protocol order
|
|
@@ -2020,8 +2050,8 @@ function readBrowserAttributes(value, strings) {
|
|
|
2020
2050
|
function readBrowserSnapshot(value, styles = [], limit = BROWSER_SNAPSHOT_NODE_LIMIT) {
|
|
2021
2051
|
if (!isInteger(limit) || limit < 0) throw new BrowserError("Browser snapshot limit must be a non-negative integer", void 0, { limit });
|
|
2022
2052
|
if (!isRecord(value) || !isArray(value["strings"]) || !isArray(value["documents"])) throw new BrowserError("Malformed DOMSnapshot.captureSnapshot result");
|
|
2023
|
-
|
|
2024
|
-
|
|
2053
|
+
const strings = parseArray(value["strings"], isString);
|
|
2054
|
+
if (strings === void 0) throw new BrowserError("Malformed DOMSnapshot string table");
|
|
2025
2055
|
let count = 0;
|
|
2026
2056
|
for (const document of value["documents"]) {
|
|
2027
2057
|
if (!isRecord(document) || !isRecord(document["nodes"])) continue;
|
|
@@ -2139,7 +2169,7 @@ function readBrowserSnapshot(value, styles = [], limit = BROWSER_SNAPSHOT_NODE_L
|
|
|
2139
2169
|
};
|
|
2140
2170
|
}
|
|
2141
2171
|
/**
|
|
2142
|
-
* Tests whether a browser-node matcher is a declarative query.
|
|
2172
|
+
* Tests whether a browser-node matcher is a declarative query rather than a predicate.
|
|
2143
2173
|
*
|
|
2144
2174
|
* @param value - Browser-node query or predicate
|
|
2145
2175
|
* @returns True if the matcher is a declarative query; false otherwise
|
|
@@ -2411,9 +2441,9 @@ function compileStorageClearExpression() {
|
|
|
2411
2441
|
})()`;
|
|
2412
2442
|
}
|
|
2413
2443
|
/**
|
|
2414
|
-
* Compiles a `Runtime.evaluate` expression so the
|
|
2415
|
-
*
|
|
2416
|
-
*
|
|
2444
|
+
* Compiles a `Runtime.evaluate` expression so the in-page code stringifies its own result and
|
|
2445
|
+
* throws a recognizable sentinel error before an oversized result would overflow the CDP
|
|
2446
|
+
* transport frame.
|
|
2417
2447
|
*
|
|
2418
2448
|
* @remarks
|
|
2419
2449
|
* A result whose `JSON.stringify` length exceeds `limit` throws
|
|
@@ -2438,7 +2468,7 @@ ${expression}
|
|
|
2438
2468
|
); const s = JSON.stringify(r); if (typeof s === 'string' && s.length > ${limit}) throw new Error(${JSON.stringify(BROWSER_RESULT_LIMIT_SENTINEL_PREFIX)} + s.length); return r })()`;
|
|
2439
2469
|
}
|
|
2440
2470
|
/**
|
|
2441
|
-
* Compiles recorded codegen actions into a replayable script.
|
|
2471
|
+
* Compiles recorded codegen actions into a replayable JavaScript or TypeScript script.
|
|
2442
2472
|
*
|
|
2443
2473
|
* @remarks
|
|
2444
2474
|
* Emits one statement per action against a `page` object shaped like
|
|
@@ -4070,7 +4100,7 @@ var BrowserTracing = class {
|
|
|
4070
4100
|
//#endregion
|
|
4071
4101
|
//#region src/core/BrowserDiagnostics.ts
|
|
4072
4102
|
/**
|
|
4073
|
-
* Groups the
|
|
4103
|
+
* Groups the tracing, coverage, performance, and profiler classes beneath one page.
|
|
4074
4104
|
*
|
|
4075
4105
|
* @example
|
|
4076
4106
|
* ```ts
|
|
@@ -4704,8 +4734,9 @@ var BrowserLocator = class BrowserLocator {
|
|
|
4704
4734
|
}
|
|
4705
4735
|
async texts() {
|
|
4706
4736
|
const value = await this.#frame.evaluate(`(${compileLocatorListExpression(this.#query)}).map((element) => element.innerText)`);
|
|
4707
|
-
|
|
4708
|
-
|
|
4737
|
+
const texts = parseArray(value, isString);
|
|
4738
|
+
if (texts === void 0) throw new BrowserError("Browser locator text list is malformed");
|
|
4739
|
+
return texts;
|
|
4709
4740
|
}
|
|
4710
4741
|
async html() {
|
|
4711
4742
|
return await this.#string("outerHTML", "Browser locator HTML");
|
|
@@ -7371,7 +7402,7 @@ var BrowserContext = class {
|
|
|
7371
7402
|
//#endregion
|
|
7372
7403
|
//#region src/core/factories.ts
|
|
7373
7404
|
/**
|
|
7374
|
-
* Creates a
|
|
7405
|
+
* Creates a `CDPClientInterface` bound to the given `CDPTransportInterface`.
|
|
7375
7406
|
*
|
|
7376
7407
|
* @param options - The transport (and optional timeout) the client uses
|
|
7377
7408
|
* @returns A {@link CDPClientInterface}
|
|
@@ -7388,7 +7419,7 @@ function createCDPClient(options) {
|
|
|
7388
7419
|
return new CDPClient(options);
|
|
7389
7420
|
}
|
|
7390
7421
|
/**
|
|
7391
|
-
* Creates a navigable
|
|
7422
|
+
* Creates a navigable `BrowserSnapshotInterface` over decoded `BrowserSnapshotInput` data.
|
|
7392
7423
|
*
|
|
7393
7424
|
* @param input - Captured documents and computed-style names
|
|
7394
7425
|
* @returns A {@link BrowserSnapshotInterface}
|