browser-debugger-cli 0.8.0 → 0.9.0
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 +4 -1
- package/dist/cdp/schema.d.ts +4 -1
- package/dist/cdp/schema.js +48 -7
- package/dist/commands/cdp.js +3 -2
- package/dist/commands/cleanup.d.ts +11 -0
- package/dist/commands/cleanup.js +161 -57
- package/dist/commands/console.d.ts +20 -1
- package/dist/commands/console.js +57 -17
- package/dist/commands/details.js +3 -2
- package/dist/commands/dom/DomElementResolver.d.ts +10 -3
- package/dist/commands/dom/DomElementResolver.js +35 -17
- package/dist/commands/dom/a11y.d.ts +10 -0
- package/dist/commands/dom/a11y.js +27 -5
- package/dist/commands/dom/eval.d.ts +3 -1
- package/dist/commands/dom/eval.js +29 -4
- package/dist/commands/dom/form.js +16 -62
- package/dist/commands/dom/formInteraction.js +152 -113
- package/dist/commands/dom/formSummary.d.ts +49 -0
- package/dist/commands/dom/formSummary.js +180 -0
- package/dist/commands/dom/frames.d.ts +2 -1
- package/dist/commands/dom/frames.js +17 -2
- package/dist/commands/dom/get.d.ts +6 -5
- package/dist/commands/dom/get.js +92 -82
- package/dist/commands/dom/helpers/index.d.ts +1 -1
- package/dist/commands/dom/helpers/index.js +1 -1
- package/dist/commands/dom/helpers/query.d.ts +44 -17
- package/dist/commands/dom/helpers/query.js +244 -97
- package/dist/commands/dom/helpers/runElementCommand.d.ts +10 -2
- package/dist/commands/dom/helpers/runElementCommand.js +97 -30
- package/dist/commands/dom/helpers/screenshot.d.ts +4 -1
- package/dist/commands/dom/helpers/screenshot.js +164 -49
- package/dist/commands/dom/index.d.ts +3 -1
- package/dist/commands/dom/index.js +16 -6
- package/dist/commands/dom/layout.d.ts +14 -0
- package/dist/commands/dom/layout.js +54 -0
- package/dist/commands/dom/listeners.d.ts +5 -1
- package/dist/commands/dom/listeners.js +13 -3
- package/dist/commands/dom/query.js +2 -3
- package/dist/commands/dom/screenshot.d.ts +12 -2
- package/dist/commands/dom/screenshot.js +27 -3
- package/dist/commands/dom/semanticUtils.d.ts +6 -13
- package/dist/commands/dom/semanticUtils.js +15 -19
- package/dist/commands/dom/wait.d.ts +13 -0
- package/dist/commands/dom/wait.js +83 -0
- package/dist/commands/helpJson.js +2 -2
- package/dist/commands/network/list.js +4 -11
- package/dist/commands/optionBehaviors.js +112 -21
- package/dist/commands/page.d.ts +2 -1
- package/dist/commands/page.js +41 -5
- package/dist/commands/peek.js +4 -11
- package/dist/commands/sessions.d.ts +8 -0
- package/dist/commands/sessions.js +19 -0
- package/dist/commands/shared/CommandRunner.js +4 -4
- package/dist/commands/shared/dataFetcher.js +2 -2
- package/dist/commands/shared/followMode.d.ts +21 -1
- package/dist/commands/shared/followMode.js +29 -2
- package/dist/commands/shared/handleValidationError.d.ts +2 -2
- package/dist/commands/shared/handleValidationError.js +12 -3
- package/dist/commands/shared/optionTypes.d.ts +40 -5
- package/dist/commands/shared/startHelpers.js +12 -3
- package/dist/commands/shared/validation.d.ts +3 -2
- package/dist/commands/shared/validation.js +4 -3
- package/dist/commands/start.d.ts +63 -0
- package/dist/commands/start.js +115 -15
- package/dist/commands/status.js +29 -7
- package/dist/commands/stop.js +7 -6
- package/dist/commands/tail.js +4 -11
- package/dist/commands/types.d.ts +2 -0
- package/dist/commands.js +2 -0
- package/dist/connection/chromeIdentity.d.ts +65 -0
- package/dist/connection/chromeIdentity.js +143 -0
- package/dist/connection/launcher/profilePreferences.d.ts +47 -0
- package/dist/connection/launcher/profilePreferences.js +151 -0
- package/dist/connection/launcher.d.ts +21 -2
- package/dist/connection/launcher.js +42 -16
- package/dist/connection/portReservation.d.ts +14 -4
- package/dist/connection/portReservation.js +21 -6
- package/dist/connection/startupExit.d.ts +8 -0
- package/dist/connection/startupExit.js +15 -6
- package/dist/constants.d.ts +6 -2
- package/dist/constants.js +9 -2
- package/dist/daemon/SessionController.js +23 -7
- package/dist/daemon/errors.d.ts +1 -1
- package/dist/daemon/errors.js +1 -1
- package/dist/daemon/launcher.d.ts +2 -1
- package/dist/daemon/launcher.js +5 -6
- package/dist/daemon/server/SocketServer.js +1 -2
- package/dist/daemon/session/Session.d.ts +13 -0
- package/dist/daemon/session/Session.js +57 -8
- package/dist/daemon/session/chromeConnection.d.ts +9 -0
- package/dist/daemon/session/chromeConnection.js +45 -8
- package/dist/daemon/session/commandRegistry.js +52 -62
- package/dist/daemon/session/interactions.d.ts +35 -9
- package/dist/daemon/session/interactions.js +36 -9
- package/dist/daemon/session/triggeredRequests.d.ts +67 -0
- package/dist/daemon/session/triggeredRequests.js +157 -0
- package/dist/daemon/session/types.d.ts +5 -1
- package/dist/daemon.js +5393 -1600
- package/dist/errors/messages.d.ts +387 -24
- package/dist/errors/messages.js +761 -67
- package/dist/index.js +3976 -1558
- package/dist/ipc/client.d.ts +12 -1
- package/dist/ipc/client.js +22 -3
- package/dist/ipc/protocol/commands.d.ts +89 -4
- package/dist/ipc/protocol/commands.js +2 -0
- package/dist/ipc/protocol/domTypes.d.ts +258 -7
- package/dist/ipc/session/lifecycle.d.ts +8 -1
- package/dist/ipc/session/queries.d.ts +5 -1
- package/dist/ipc/session/types.d.ts +5 -0
- package/dist/ipc/transport/index.d.ts +2 -1
- package/dist/ipc/transport/index.js +2 -2
- package/dist/runtime/dom/actionEffects.d.ts +106 -0
- package/dist/runtime/dom/actionEffects.js +256 -0
- package/dist/runtime/dom/actionEffectsScripts.d.ts +52 -0
- package/dist/runtime/dom/actionEffectsScripts.js +234 -0
- package/dist/runtime/dom/elementGeometry.d.ts +170 -0
- package/dist/runtime/dom/elementGeometry.js +553 -0
- package/dist/runtime/dom/elementInfo.d.ts +77 -0
- package/dist/runtime/dom/elementInfo.js +191 -0
- package/dist/runtime/dom/evalHelpers.d.ts +51 -6
- package/dist/runtime/dom/evalHelpers.js +136 -26
- package/dist/runtime/dom/eventListeners.d.ts +2 -1
- package/dist/runtime/dom/eventListeners.js +174 -47
- package/dist/runtime/dom/formDiscovery.d.ts +1 -1
- package/dist/runtime/dom/formDiscovery.js +116 -16
- package/dist/runtime/dom/formFillHelpers/fill.d.ts +10 -0
- package/dist/runtime/dom/formFillHelpers/fill.js +125 -10
- package/dist/runtime/dom/formFillHelpers/index.d.ts +2 -2
- package/dist/runtime/dom/formFillHelpers/index.js +2 -2
- package/dist/runtime/dom/formFillHelpers/pressKey.js +14 -3
- package/dist/runtime/dom/formFillHelpers/scroll.d.ts +3 -0
- package/dist/runtime/dom/formFillHelpers/scroll.js +60 -18
- package/dist/runtime/dom/formFillHelpers/shared.d.ts +17 -0
- package/dist/runtime/dom/formFillHelpers/shared.js +25 -1
- package/dist/runtime/dom/formFillHelpers/stability.d.ts +20 -6
- package/dist/runtime/dom/formFillHelpers/stability.js +50 -19
- package/dist/runtime/dom/formSubmitHelpers.d.ts +3 -0
- package/dist/runtime/dom/formSubmitHelpers.js +89 -15
- package/dist/runtime/dom/frameLayout.d.ts +60 -0
- package/dist/runtime/dom/frameLayout.js +140 -0
- package/dist/runtime/dom/frameOrigin.d.ts +50 -0
- package/dist/runtime/dom/frameOrigin.js +62 -0
- package/dist/runtime/dom/frameScopedConnection.d.ts +92 -0
- package/dist/runtime/dom/frameScopedConnection.js +252 -0
- package/dist/runtime/dom/frameSelection.d.ts +1 -1
- package/dist/runtime/dom/frameSelection.js +2 -2
- package/dist/runtime/dom/frames.d.ts +25 -2
- package/dist/runtime/dom/frames.js +202 -63
- package/dist/runtime/dom/layout.d.ts +67 -0
- package/dist/runtime/dom/layout.js +333 -0
- package/dist/runtime/dom/listenerPageScripts.d.ts +66 -0
- package/dist/runtime/dom/listenerPageScripts.js +279 -0
- package/dist/runtime/dom/listenerSummary.d.ts +132 -11
- package/dist/runtime/dom/listenerSummary.js +344 -22
- package/dist/runtime/dom/pageActivity.d.ts +41 -0
- package/dist/runtime/dom/pageActivity.js +123 -0
- package/dist/runtime/dom/reactEventHelpers.d.ts +58 -2
- package/dist/runtime/dom/reactEventHelpers.js +212 -41
- package/dist/runtime/dom/targetNode.d.ts +80 -27
- package/dist/runtime/dom/targetNode.js +249 -33
- package/dist/runtime/dom/wait.d.ts +25 -0
- package/dist/runtime/dom/wait.js +199 -0
- package/dist/runtime/dom/waitCondition.d.ts +71 -0
- package/dist/runtime/dom/waitCondition.js +75 -0
- package/dist/runtime/page/emulation.d.ts +51 -0
- package/dist/runtime/page/emulation.js +80 -0
- package/dist/runtime/page/loadingState.d.ts +36 -0
- package/dist/runtime/page/loadingState.js +86 -0
- package/dist/runtime/page/navigation.d.ts +46 -2
- package/dist/runtime/page/navigation.js +69 -33
- package/dist/session/QueryCacheManager.d.ts +11 -1
- package/dist/session/QueryCacheManager.js +25 -3
- package/dist/session/chromeOwners.d.ts +34 -0
- package/dist/session/chromeOwners.js +51 -0
- package/dist/session/cleanup/staleSession.d.ts +11 -1
- package/dist/session/cleanup/staleSession.js +17 -6
- package/dist/session/cleanup/userCommands.js +2 -4
- package/dist/session/metadata.d.ts +5 -1
- package/dist/session/metadata.js +2 -1
- package/dist/session/paths.d.ts +77 -3
- package/dist/session/paths.js +111 -5
- package/dist/session/port.d.ts +31 -7
- package/dist/session/port.js +50 -43
- package/dist/session/portClaims.d.ts +66 -0
- package/dist/session/portClaims.js +284 -0
- package/dist/session/sessionList.d.ts +58 -0
- package/dist/session/sessionList.js +199 -0
- package/dist/session/sessionName.d.ts +46 -0
- package/dist/session/sessionName.js +97 -0
- package/dist/telemetry/a11y.d.ts +8 -3
- package/dist/telemetry/a11y.js +92 -28
- package/dist/telemetry/requestKinds.d.ts +32 -0
- package/dist/telemetry/requestKinds.js +61 -0
- package/dist/telemetry/requestState.d.ts +31 -0
- package/dist/telemetry/requestState.js +38 -0
- package/dist/types.d.ts +80 -3
- package/dist/ui/formatters/a11y.js +3 -0
- package/dist/ui/formatters/console/chronological.d.ts +8 -0
- package/dist/ui/formatters/console/chronological.js +17 -4
- package/dist/ui/formatters/console/json.js +3 -4
- package/dist/ui/formatters/console/shared.d.ts +12 -0
- package/dist/ui/formatters/console.d.ts +2 -2
- package/dist/ui/formatters/console.js +1 -1
- package/dist/ui/formatters/details.js +2 -1
- package/dist/ui/formatters/dom.d.ts +26 -14
- package/dist/ui/formatters/dom.js +65 -52
- package/dist/ui/formatters/form.js +29 -18
- package/dist/ui/formatters/layout.d.ts +31 -0
- package/dist/ui/formatters/layout.js +53 -0
- package/dist/ui/formatters/listeners.d.ts +3 -2
- package/dist/ui/formatters/listeners.js +73 -9
- package/dist/ui/formatters/networkHeaders.js +13 -0
- package/dist/ui/formatters/preview.js +2 -1
- package/dist/ui/formatters/requestStatus.d.ts +1 -17
- package/dist/ui/formatters/requestStatus.js +2 -30
- package/dist/ui/formatters/sessions.d.ts +12 -0
- package/dist/ui/formatters/sessions.js +40 -0
- package/dist/ui/formatters/status.d.ts +21 -2
- package/dist/ui/formatters/status.js +47 -10
- package/dist/ui/formatters/triggeredRequests.d.ts +36 -0
- package/dist/ui/formatters/triggeredRequests.js +65 -0
- package/dist/ui/formatting.d.ts +10 -0
- package/dist/ui/formatting.js +28 -36
- package/dist/ui/messages/chrome.d.ts +9 -0
- package/dist/ui/messages/chrome.js +17 -5
- package/dist/ui/messages/commands.d.ts +388 -14
- package/dist/ui/messages/commands.js +664 -21
- package/dist/ui/messages/consoleMessages.d.ts +10 -0
- package/dist/ui/messages/consoleMessages.js +17 -0
- package/dist/ui/messages/hints.js +2 -1
- package/dist/ui/messages/preview.js +5 -4
- package/dist/ui/messages/session.d.ts +16 -21
- package/dist/ui/messages/session.js +28 -26
- package/dist/ui/messages/sessionCommand.d.ts +43 -0
- package/dist/ui/messages/sessionCommand.js +52 -0
- package/dist/utils/async.d.ts +8 -0
- package/dist/utils/async.js +19 -0
- package/dist/utils/http.d.ts +22 -1
- package/dist/utils/http.js +28 -9
- package/dist/utils/selectorFilters.d.ts +36 -8
- package/dist/utils/selectorFilters.js +267 -53
- package/dist/utils/shellDetection.d.ts +8 -2
- package/dist/utils/shellDetection.js +120 -33
- package/dist/utils/suggestions.d.ts +26 -0
- package/dist/utils/suggestions.js +73 -0
- package/dist/utils/taskMappings.js +10 -0
- package/dist/utils/url.d.ts +12 -2
- package/dist/utils/url.js +69 -7
- package/package.json +1 -1
- package/dist/ui/formatters/sessionFormatters.d.ts +0 -58
- package/dist/ui/formatters/sessionFormatters.js +0 -121
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run the interaction scripts inside the frame of a cached element that the
|
|
3
|
+
* top page cannot reach.
|
|
4
|
+
*
|
|
5
|
+
* An element from `bdg dom a11y query` may be in a cross-origin iframe that
|
|
6
|
+
* shares the page's process (same site, e.g. a consent dialog served from a
|
|
7
|
+
* subdomain). The top page cannot hold it, so its page scripts run in the
|
|
8
|
+
* element's own frame instead: every `Runtime.evaluate` becomes a
|
|
9
|
+
* `Runtime.callFunctionOn` on the element (which runs in the element's
|
|
10
|
+
* context), and mouse events, whose coordinates the scripts measure in the
|
|
11
|
+
* frame's viewport, are mapped into the top-level viewport
|
|
12
|
+
* ({@link FrameMapping}).
|
|
13
|
+
*/
|
|
14
|
+
import { CommandError } from '../../errors/index.js';
|
|
15
|
+
import { frameMappingError } from '../../errors/messages.js';
|
|
16
|
+
import { getErrorMessage } from '../../utils/errors.js';
|
|
17
|
+
import { EXIT_CODES } from '../../utils/exitCodes.js';
|
|
18
|
+
/** `Runtime.evaluate` parameters that `Runtime.callFunctionOn` takes too */
|
|
19
|
+
const SHARED_EVALUATE_PARAMS = [
|
|
20
|
+
'returnByValue',
|
|
21
|
+
'userGesture',
|
|
22
|
+
'awaitPromise',
|
|
23
|
+
'objectGroup',
|
|
24
|
+
'silent',
|
|
25
|
+
'generatePreview',
|
|
26
|
+
'throwOnSideEffect',
|
|
27
|
+
'serializationOptions',
|
|
28
|
+
];
|
|
29
|
+
/** `Runtime.evaluate` parameters with no `Runtime.callFunctionOn` counterpart */
|
|
30
|
+
const UNSUPPORTED_EVALUATE_PARAMS = [
|
|
31
|
+
'timeout',
|
|
32
|
+
'contextId',
|
|
33
|
+
'uniqueContextId',
|
|
34
|
+
'includeCommandLineAPI',
|
|
35
|
+
'replMode',
|
|
36
|
+
'disableBreaks',
|
|
37
|
+
'allowUnsafeEvalBlockedByCSP',
|
|
38
|
+
];
|
|
39
|
+
/** Slack (CSS px) for rounding when telling a scaled frame from an unscaled one */
|
|
40
|
+
const SCALE_SLACK_PX = 0.5;
|
|
41
|
+
/**
|
|
42
|
+
* `Runtime.callFunctionOn` parameters that evaluate an expression in the
|
|
43
|
+
* context of the element `objectId` refers to.
|
|
44
|
+
*
|
|
45
|
+
* @param params - `Runtime.evaluate` parameters
|
|
46
|
+
* @param objectId - Remote object of the element
|
|
47
|
+
* @returns Parameters for `Runtime.callFunctionOn`
|
|
48
|
+
* @throws Error for a parameter `Runtime.callFunctionOn` has no counterpart for
|
|
49
|
+
* (e.g. `timeout`), so it is not dropped silently
|
|
50
|
+
*/
|
|
51
|
+
export function evaluateOnNodeParams(params, objectId) {
|
|
52
|
+
const unsupported = UNSUPPORTED_EVALUATE_PARAMS.filter((key) => params[key] !== undefined);
|
|
53
|
+
if (unsupported.length > 0) {
|
|
54
|
+
throw new Error(`Runtime.evaluate in a frame cannot take ${unsupported.join(', ')}`);
|
|
55
|
+
}
|
|
56
|
+
const shared = Object.fromEntries(SHARED_EVALUATE_PARAMS.filter((key) => params[key] !== undefined).map((key) => [
|
|
57
|
+
key,
|
|
58
|
+
params[key],
|
|
59
|
+
]));
|
|
60
|
+
return {
|
|
61
|
+
...shared,
|
|
62
|
+
objectId,
|
|
63
|
+
functionDeclaration: `function () { return (\n${String(params['expression'])}\n); }`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Error for a frame that cannot be placed in the top-level viewport.
|
|
68
|
+
*
|
|
69
|
+
* @param problem - What went wrong
|
|
70
|
+
* @param detail - Underlying error, if any
|
|
71
|
+
* @returns Not found (83) error
|
|
72
|
+
*/
|
|
73
|
+
function mappingError(problem, detail) {
|
|
74
|
+
const err = frameMappingError(problem, detail);
|
|
75
|
+
return new CommandError(err.message, { suggestion: err.suggestion }, EXIT_CODES.RESOURCE_NOT_FOUND);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether a quad is an axis-aligned rectangle (not rotated or skewed).
|
|
79
|
+
*
|
|
80
|
+
* @param quad - x1,y1,…,x4,y4 clockwise from the top left
|
|
81
|
+
* @returns True when its edges are horizontal and vertical
|
|
82
|
+
*/
|
|
83
|
+
function axisAligned(quad) {
|
|
84
|
+
const [x1, y1, x2, y2, x3, y3, x4, y4] = quad;
|
|
85
|
+
const near = (a, b) => Math.abs(a - b) <= SCALE_SLACK_PX;
|
|
86
|
+
return near(y1, y2) && near(x2, x3) && near(y3, y4) && near(x4, x1);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Scale along one axis: the length in the top-level viewport over the length
|
|
90
|
+
* in the frame, 1 when they differ by no more than rounding.
|
|
91
|
+
*
|
|
92
|
+
* @param top - Length in the top-level viewport
|
|
93
|
+
* @param frame - Length in the frame
|
|
94
|
+
* @returns Scale factor
|
|
95
|
+
*/
|
|
96
|
+
function axisScale(top, frame) {
|
|
97
|
+
return Math.abs(top - frame) <= SCALE_SLACK_PX ? 1 : top / frame;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* How the frame maps into the top-level viewport, from one box seen both ways.
|
|
101
|
+
*
|
|
102
|
+
* @param box - The reference box in the frame and in the top-level viewport
|
|
103
|
+
* @returns The mapping
|
|
104
|
+
* @throws CommandError (83) when the box has no quads or size, or is rotated or skewed
|
|
105
|
+
*/
|
|
106
|
+
export function frameMappingFrom(box) {
|
|
107
|
+
const { rect, quads } = box;
|
|
108
|
+
if (quads.length === 0 || quads.some((quad) => quad.length !== 8))
|
|
109
|
+
throw mappingError('no-box');
|
|
110
|
+
if (rect.width <= 0 || rect.height <= 0)
|
|
111
|
+
throw mappingError('no-box');
|
|
112
|
+
if (!quads.every(axisAligned))
|
|
113
|
+
throw mappingError('rotated');
|
|
114
|
+
const xs = quads.flatMap((quad) => quad.filter((_, i) => i % 2 === 0));
|
|
115
|
+
const ys = quads.flatMap((quad) => quad.filter((_, i) => i % 2 === 1));
|
|
116
|
+
const left = Math.min(...xs);
|
|
117
|
+
const top = Math.min(...ys);
|
|
118
|
+
const scaleX = axisScale(Math.max(...xs) - left, rect.width);
|
|
119
|
+
const scaleY = axisScale(Math.max(...ys) - top, rect.height);
|
|
120
|
+
return { origin: { x: left - rect.x * scaleX, y: top - rect.y * scaleY }, scaleX, scaleY };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Map a point of the frame's viewport into the top-level viewport.
|
|
124
|
+
*
|
|
125
|
+
* @param mapping - Frame mapping
|
|
126
|
+
* @param point - Point in the frame's viewport
|
|
127
|
+
* @returns Point in the top-level viewport
|
|
128
|
+
*/
|
|
129
|
+
export function mapPoint(mapping, point) {
|
|
130
|
+
return {
|
|
131
|
+
x: mapping.origin.x + point.x * mapping.scaleX,
|
|
132
|
+
y: mapping.origin.y + point.y * mapping.scaleY,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Map a box of the frame's viewport into the top-level viewport.
|
|
137
|
+
*
|
|
138
|
+
* @param mapping - Frame mapping
|
|
139
|
+
* @param box - Box in the frame's viewport
|
|
140
|
+
* @returns Box in the top-level viewport
|
|
141
|
+
*/
|
|
142
|
+
export function mapBox(mapping, box) {
|
|
143
|
+
return {
|
|
144
|
+
...mapPoint(mapping, box),
|
|
145
|
+
width: box.width * mapping.scaleX,
|
|
146
|
+
height: box.height * mapping.scaleY,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Page-side choice of the box to measure: the element's, or its document's
|
|
151
|
+
* root element when the element has no size (hidden, collapsed).
|
|
152
|
+
*/
|
|
153
|
+
const REFERENCE_NODE_FUNCTION = `function () {
|
|
154
|
+
const r = this.getBoundingClientRect();
|
|
155
|
+
return r.width > 0 && r.height > 0 ? this : this.ownerDocument.documentElement;
|
|
156
|
+
}`;
|
|
157
|
+
/** Page-side `getBoundingClientRect()` as a plain box */
|
|
158
|
+
const CLIENT_RECT_FUNCTION = 'function () { const r = this.getBoundingClientRect(); return { x: r.left, y: r.top, width: r.width, height: r.height }; }';
|
|
159
|
+
/**
|
|
160
|
+
* Measure a box of the element's frame both in the frame and through CDP.
|
|
161
|
+
*
|
|
162
|
+
* @param cdp - CDP connection
|
|
163
|
+
* @param objectId - Remote object of the element
|
|
164
|
+
* @returns The reference box
|
|
165
|
+
* @throws CommandError (83) when it cannot be read
|
|
166
|
+
*/
|
|
167
|
+
async function measureReferenceBox(cdp, objectId) {
|
|
168
|
+
try {
|
|
169
|
+
const reference = (await cdp.send('Runtime.callFunctionOn', {
|
|
170
|
+
objectId,
|
|
171
|
+
functionDeclaration: REFERENCE_NODE_FUNCTION,
|
|
172
|
+
}));
|
|
173
|
+
const referenceId = reference.result.objectId;
|
|
174
|
+
if (!referenceId)
|
|
175
|
+
throw mappingError('no-box');
|
|
176
|
+
const [quads, rect] = await Promise.all([
|
|
177
|
+
cdp.send('DOM.getContentQuads', {
|
|
178
|
+
objectId: referenceId,
|
|
179
|
+
}),
|
|
180
|
+
cdp.send('Runtime.callFunctionOn', {
|
|
181
|
+
objectId: referenceId,
|
|
182
|
+
functionDeclaration: CLIENT_RECT_FUNCTION,
|
|
183
|
+
returnByValue: true,
|
|
184
|
+
}),
|
|
185
|
+
]);
|
|
186
|
+
const box = rect.result?.value;
|
|
187
|
+
if (!box)
|
|
188
|
+
throw mappingError('no-box');
|
|
189
|
+
return { rect: box, quads: quads.quads };
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (error instanceof CommandError)
|
|
193
|
+
throw error;
|
|
194
|
+
throw mappingError('unreadable', getErrorMessage(error));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* How the element's frame maps into the top-level viewport.
|
|
199
|
+
*
|
|
200
|
+
* @param cdp - CDP connection
|
|
201
|
+
* @param objectId - Remote object of the element
|
|
202
|
+
* @returns The mapping
|
|
203
|
+
* @throws CommandError (83) when the frame cannot be measured or is rotated or skewed
|
|
204
|
+
*/
|
|
205
|
+
export async function measureFrameMapping(cdp, objectId) {
|
|
206
|
+
return frameMappingFrom(await measureReferenceBox(cdp, objectId));
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* A view of the session's connection whose page scripts run in the frame of
|
|
210
|
+
* one element and whose mouse events land on that frame.
|
|
211
|
+
*
|
|
212
|
+
* The mapping is measured at the first mouse event (after the scripts scrolled
|
|
213
|
+
* the element into view) and kept for the rest of the action; a failed
|
|
214
|
+
* measurement is not kept (the next event measures again) and fails the event.
|
|
215
|
+
*
|
|
216
|
+
* @param cdp - Session connection
|
|
217
|
+
* @param objectId - Remote object of the element
|
|
218
|
+
* @returns Connection to hand to the interaction functions
|
|
219
|
+
*/
|
|
220
|
+
export function frameScopedConnection(cdp, objectId) {
|
|
221
|
+
let mapping;
|
|
222
|
+
const measured = () => {
|
|
223
|
+
mapping ??= measureFrameMapping(cdp, objectId).catch((error) => {
|
|
224
|
+
mapping = undefined;
|
|
225
|
+
throw error;
|
|
226
|
+
});
|
|
227
|
+
return mapping;
|
|
228
|
+
};
|
|
229
|
+
const send = async (method, params = {}, sessionId) => {
|
|
230
|
+
if (sessionId !== undefined)
|
|
231
|
+
return cdp.send(method, params, sessionId);
|
|
232
|
+
if (method === 'Runtime.evaluate') {
|
|
233
|
+
return cdp.send('Runtime.callFunctionOn', evaluateOnNodeParams(params, objectId));
|
|
234
|
+
}
|
|
235
|
+
if (method === 'Input.dispatchMouseEvent') {
|
|
236
|
+
const point = mapPoint(await measured(), { x: Number(params['x']), y: Number(params['y']) });
|
|
237
|
+
return cdp.send(method, { ...params, ...point });
|
|
238
|
+
}
|
|
239
|
+
return cdp.send(method, params);
|
|
240
|
+
};
|
|
241
|
+
return new Proxy(cdp, {
|
|
242
|
+
get(target, property) {
|
|
243
|
+
if (property === 'send')
|
|
244
|
+
return send;
|
|
245
|
+
const value = Reflect.get(target, property, target);
|
|
246
|
+
return typeof value === 'function'
|
|
247
|
+
? value.bind(target)
|
|
248
|
+
: value;
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=frameScopedConnection.js.map
|
|
@@ -5,7 +5,7 @@ import { CommandError } from '../../errors/index.js';
|
|
|
5
5
|
import type { DomFrame } from '../../ipc/protocol/commands.js';
|
|
6
6
|
/**
|
|
7
7
|
* Pick the frame a `--frame` value names: a 0-based index, an exact `name`
|
|
8
|
-
* or `id` attribute, or else a case-insensitive part of the URL.
|
|
8
|
+
* or `id` attribute, or else a case-insensitive part of the name, id or URL.
|
|
9
9
|
*
|
|
10
10
|
* @param frames - Frames of the page
|
|
11
11
|
* @param query - Requested frame
|
|
@@ -6,7 +6,7 @@ import { ambiguousFrameError, emptyFrameError, frameNotFoundError } from '../../
|
|
|
6
6
|
import { EXIT_CODES } from '../../utils/exitCodes.js';
|
|
7
7
|
/**
|
|
8
8
|
* Pick the frame a `--frame` value names: a 0-based index, an exact `name`
|
|
9
|
-
* or `id` attribute, or else a case-insensitive part of the URL.
|
|
9
|
+
* or `id` attribute, or else a case-insensitive part of the name, id or URL.
|
|
10
10
|
*
|
|
11
11
|
* @param frames - Frames of the page
|
|
12
12
|
* @param query - Requested frame
|
|
@@ -33,7 +33,7 @@ function candidatesFor(frames, wanted) {
|
|
|
33
33
|
if (named.length > 0)
|
|
34
34
|
return named;
|
|
35
35
|
const needle = wanted.toLowerCase();
|
|
36
|
-
return frames.filter((frame) => frame.url.toLowerCase().includes(needle));
|
|
36
|
+
return frames.filter((frame) => [frame.name, frame.id, frame.url].some((text) => text?.toLowerCase().includes(needle)));
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* The only candidate, or an error listing the frames.
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
* all, not even to `Runtime.terminateExecution`.
|
|
15
15
|
*/
|
|
16
16
|
import { CDPConnection } from '../../connection/cdp.js';
|
|
17
|
+
import type { CommandError } from '../../errors/index.js';
|
|
17
18
|
import type { DomEvalData, DomFrame } from '../../ipc/protocol/commands.js';
|
|
19
|
+
import { type CDPSender } from '../../telemetry/objectExpander.js';
|
|
18
20
|
/**
|
|
19
21
|
* List the page's iframes.
|
|
20
22
|
*
|
|
@@ -23,6 +25,26 @@ import type { DomEvalData, DomFrame } from '../../ipc/protocol/commands.js';
|
|
|
23
25
|
* @returns Iframes in listing order
|
|
24
26
|
*/
|
|
25
27
|
export declare function listFrames(page: CDPConnection, wsUrl: string): Promise<DomFrame[]>;
|
|
28
|
+
/** A frame whose script lost its context */
|
|
29
|
+
export interface LostFrame {
|
|
30
|
+
frameId: string;
|
|
31
|
+
/** Session of the parent frame, which owns the iframe element */
|
|
32
|
+
ownerSession?: string;
|
|
33
|
+
/** Frame URL when the script started */
|
|
34
|
+
url: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The error for a script whose frame context went away: the page was
|
|
38
|
+
* closed, the frame navigated (its iframe element is still there) or was
|
|
39
|
+
* removed.
|
|
40
|
+
*
|
|
41
|
+
* @param conn - Connection the frame was found on
|
|
42
|
+
* @param page - The session's connection to the page
|
|
43
|
+
* @param frame - The frame
|
|
44
|
+
* @returns Command error (83)
|
|
45
|
+
* @throws Errors of the checks other than Chrome saying the frame is gone
|
|
46
|
+
*/
|
|
47
|
+
export declare function frameContextLostError(conn: Pick<CDPConnection, 'send'>, page: CDPSender, frame: LostFrame): Promise<CommandError>;
|
|
26
48
|
/**
|
|
27
49
|
* Evaluate a `bdg dom eval` script in one iframe, like {@link evaluateScript}
|
|
28
50
|
* does in the page.
|
|
@@ -30,9 +52,10 @@ export declare function listFrames(page: CDPConnection, wsUrl: string): Promise<
|
|
|
30
52
|
* @param page - The session's connection
|
|
31
53
|
* @param wsUrl - WebSocket URL of the page target
|
|
32
54
|
* @param script - JavaScript expression
|
|
33
|
-
* @param query - Requested frame (index, name/id attribute, or part of the URL)
|
|
55
|
+
* @param query - Requested frame (index, name/id attribute, or part of the name, id or URL)
|
|
34
56
|
* @returns Value, type and the frame's URL
|
|
35
|
-
* @throws CommandError (81/83) when the frame is ambiguous or missing,
|
|
57
|
+
* @throws CommandError (81/83) when the frame is ambiguous or missing, (83)
|
|
58
|
+
* when it navigated or was removed while the script ran, else as evaluateScript
|
|
36
59
|
*/
|
|
37
60
|
export declare function evaluateInFrame(page: CDPConnection, wsUrl: string, script: string, query: string): Promise<DomEvalData>;
|
|
38
61
|
//# sourceMappingURL=frames.d.ts.map
|