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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { IPCMessage } from './lifecycle.js';
|
|
7
7
|
import type { PageState, SessionActivity } from './types.js';
|
|
8
|
-
import type { NetworkRequest, TelemetryType } from '../../types.js';
|
|
8
|
+
import type { ColorScheme, NetworkRequest, TelemetryType, ViewportSize } from '../../types.js';
|
|
9
9
|
/**
|
|
10
10
|
* Status request (client → daemon).
|
|
11
11
|
*/
|
|
@@ -35,6 +35,10 @@ export interface StatusResponseData {
|
|
|
35
35
|
activeTelemetry?: TelemetryType[];
|
|
36
36
|
/** When `--timeout` stops the session (epoch ms) */
|
|
37
37
|
autoStopAt?: number;
|
|
38
|
+
/** Viewport the page is emulated at (`--viewport`) */
|
|
39
|
+
viewport?: ViewportSize;
|
|
40
|
+
/** `prefers-color-scheme` the page is emulated with (`--color-scheme`) */
|
|
41
|
+
colorScheme?: ColorScheme;
|
|
38
42
|
};
|
|
39
43
|
/** Session activity metrics. */
|
|
40
44
|
activity?: SessionActivity;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Common types used across session messages and session commands.
|
|
5
5
|
*/
|
|
6
|
+
import type { ColorScheme, ViewportSize } from '../../types.js';
|
|
6
7
|
/**
|
|
7
8
|
* Session activity metrics.
|
|
8
9
|
*/
|
|
@@ -24,5 +25,9 @@ export interface PageState {
|
|
|
24
25
|
url: string;
|
|
25
26
|
/** Current page title. */
|
|
26
27
|
title: string;
|
|
28
|
+
/** Layout viewport without scrollbars (left out when the page did not answer in time). */
|
|
29
|
+
viewport?: ViewportSize;
|
|
30
|
+
/** `prefers-color-scheme` the page sees (left out when the page did not answer in time). */
|
|
31
|
+
colorScheme?: ColorScheme;
|
|
27
32
|
}
|
|
28
33
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -16,7 +16,8 @@ type WithTypeAndSession = {
|
|
|
16
16
|
* @param requestName - Name used in errors and logs
|
|
17
17
|
* @param expectedType - Response type to validate, if any
|
|
18
18
|
* @param timeoutMs - How long to wait for the response (default: IPC timeout)
|
|
19
|
+
* @param socketPath - Daemon socket (default: the selected session's)
|
|
19
20
|
* @returns The daemon's response
|
|
20
21
|
*/
|
|
21
|
-
export declare function sendRequest<TRequest extends WithTypeAndSession, TResponse extends WithTypeAndSession>(request: TRequest, requestName: string, expectedType?: string, timeoutMs?: number): Promise<TResponse>;
|
|
22
|
+
export declare function sendRequest<TRequest extends WithTypeAndSession, TResponse extends WithTypeAndSession>(request: TRequest, requestName: string, expectedType?: string, timeoutMs?: number, socketPath?: string): Promise<TResponse>;
|
|
22
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -20,10 +20,10 @@ const log = createLogger('client');
|
|
|
20
20
|
* @param requestName - Name used in errors and logs
|
|
21
21
|
* @param expectedType - Response type to validate, if any
|
|
22
22
|
* @param timeoutMs - How long to wait for the response (default: IPC timeout)
|
|
23
|
+
* @param socketPath - Daemon socket (default: the selected session's)
|
|
23
24
|
* @returns The daemon's response
|
|
24
25
|
*/
|
|
25
|
-
export async function sendRequest(request, requestName, expectedType, timeoutMs = getIPCRequestTimeout()) {
|
|
26
|
-
const socketPath = getDaemonSocketPath();
|
|
26
|
+
export async function sendRequest(request, requestName, expectedType, timeoutMs = getIPCRequestTimeout(), socketPath = getDaemonSocketPath()) {
|
|
27
27
|
return new Promise((resolve, reject) => {
|
|
28
28
|
const buffer = new JSONLBuffer();
|
|
29
29
|
let resolved = false;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a DOM action changed on the page: whether it navigated (to a new
|
|
3
|
+
* document or within the same one), which messages appeared, and whether it
|
|
4
|
+
* had no visible effect at all. Costs one page script sent before the action
|
|
5
|
+
* (not waited for: CDP runs it before the action's own scripts) and one read
|
|
6
|
+
* after it, plus a second look 300 ms later when nothing seemed to happen.
|
|
7
|
+
* Worst case, when the page does not answer (a navigation is pending), the
|
|
8
|
+
* snapshot is given up after {@link START_TIMEOUT_MS} and each read after
|
|
9
|
+
* {@link READ_TIMEOUT_MS}.
|
|
10
|
+
*/
|
|
11
|
+
import type { CDPConnection } from '../../connection/cdp.js';
|
|
12
|
+
import type { ActionEffects, NewMessage, PageNavigation } from '../../ipc/protocol/domTypes.js';
|
|
13
|
+
import { type NavigationEvents } from './pageActivity.js';
|
|
14
|
+
/** A message element as a page snapshot lists it */
|
|
15
|
+
export interface SeenMessage {
|
|
16
|
+
/** Number of the element, stable within its document */
|
|
17
|
+
id: number;
|
|
18
|
+
text: string;
|
|
19
|
+
element: string;
|
|
20
|
+
}
|
|
21
|
+
export type { NavigationEvents };
|
|
22
|
+
/** The page after the action */
|
|
23
|
+
export interface ReadSnapshot {
|
|
24
|
+
href: string;
|
|
25
|
+
/** The snapshot was gone: a new document */
|
|
26
|
+
fresh: boolean;
|
|
27
|
+
/** DOM changes counted since the start (same document only) */
|
|
28
|
+
changes?: number;
|
|
29
|
+
/** Why "no effect" can't be claimed even without changes */
|
|
30
|
+
uncertain?: string;
|
|
31
|
+
messages: SeenMessage[];
|
|
32
|
+
}
|
|
33
|
+
/** What the action did besides changing the page, for the "no effect" decision */
|
|
34
|
+
export interface OtherActivity {
|
|
35
|
+
/** Requests started during the action */
|
|
36
|
+
requests: number;
|
|
37
|
+
/** Dialogs opened during the action */
|
|
38
|
+
dialogs: number;
|
|
39
|
+
/** A window, tab or download was opened */
|
|
40
|
+
opened: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Messages that are new after the action: all of them after a new document
|
|
44
|
+
* loaded; otherwise those whose text is shown more often than before (a
|
|
45
|
+
* re-rendered message with the same text is not new) and those whose
|
|
46
|
+
* element changed its text. Texts that tick on their own
|
|
47
|
+
* ({@link TICKING_TEXT}: clocks, counters) are left out; other elements
|
|
48
|
+
* that change on their own (a rotating banner) are not recognised. Each text
|
|
49
|
+
* is reported once, at most {@link MAX_NEW_MESSAGES}, cut to
|
|
50
|
+
* {@link MAX_MESSAGE_LENGTH} characters.
|
|
51
|
+
*
|
|
52
|
+
* @param before - Messages before the action
|
|
53
|
+
* @param after - Messages after the action
|
|
54
|
+
* @param newDocument - Whether a new document loaded
|
|
55
|
+
* @returns New messages
|
|
56
|
+
*/
|
|
57
|
+
export declare function newMessages(before: SeenMessage[], after: SeenMessage[], newDocument: boolean): NewMessage[];
|
|
58
|
+
/**
|
|
59
|
+
* How the page's location changed: a new document committed in the main
|
|
60
|
+
* frame (also when it has the URL it had, as after a form POST that
|
|
61
|
+
* redirects back), or a same-document URL change (history API, hash).
|
|
62
|
+
*
|
|
63
|
+
* Without the URL before the action, a same-document change is reported
|
|
64
|
+
* only when Chrome announced one.
|
|
65
|
+
*
|
|
66
|
+
* @param startHref - URL before the action (undefined when not read)
|
|
67
|
+
* @param read - Page read after the action (undefined when not read)
|
|
68
|
+
* @param events - Main-frame navigation events
|
|
69
|
+
* @returns Navigation, or undefined when the location did not change
|
|
70
|
+
*/
|
|
71
|
+
export declare function pageNavigation(startHref: string | undefined, read: ReadSnapshot | undefined, events: NavigationEvents): PageNavigation | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Whether an action had no visible effect: the page was read before and
|
|
74
|
+
* after in the same document, it counted no DOM change, nothing made the
|
|
75
|
+
* check uncertain, and no navigation, message, request, dialog or new window
|
|
76
|
+
* happened.
|
|
77
|
+
*
|
|
78
|
+
* @param read - Page read after the action
|
|
79
|
+
* @param effects - Navigation and messages found
|
|
80
|
+
* @param activity - Requests, dialogs and windows during the action
|
|
81
|
+
* @returns True to report `effect: "none"`
|
|
82
|
+
*/
|
|
83
|
+
export declare function hadNoEffect(read: ReadSnapshot | undefined, effects: ActionEffects, activity: OtherActivity): boolean;
|
|
84
|
+
/** Collects what changed, once the action and its wait are done */
|
|
85
|
+
export interface ActionEffectsWatch {
|
|
86
|
+
/**
|
|
87
|
+
* @param options - Dialogs the action opened, and whether to decide "no effect"
|
|
88
|
+
* @returns What changed
|
|
89
|
+
*/
|
|
90
|
+
collect(options: {
|
|
91
|
+
dialogs: number;
|
|
92
|
+
detectNoEffect: boolean;
|
|
93
|
+
}): Promise<ActionEffects>;
|
|
94
|
+
/** Stop listening and stop the page's watch (always call) */
|
|
95
|
+
dispose(): void;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Start watching an action's effects: listen for main-frame navigations,
|
|
99
|
+
* document statuses, requests and new windows, and send the page snapshot
|
|
100
|
+
* without waiting for it.
|
|
101
|
+
*
|
|
102
|
+
* @param cdp - CDP connection
|
|
103
|
+
* @returns Watch to collect from after the action
|
|
104
|
+
*/
|
|
105
|
+
export declare function watchActionEffects(cdp: CDPConnection): ActionEffectsWatch;
|
|
106
|
+
//# sourceMappingURL=actionEffects.d.ts.map
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a DOM action changed on the page: whether it navigated (to a new
|
|
3
|
+
* document or within the same one), which messages appeared, and whether it
|
|
4
|
+
* had no visible effect at all. Costs one page script sent before the action
|
|
5
|
+
* (not waited for: CDP runs it before the action's own scripts) and one read
|
|
6
|
+
* after it, plus a second look 300 ms later when nothing seemed to happen.
|
|
7
|
+
* Worst case, when the page does not answer (a navigation is pending), the
|
|
8
|
+
* snapshot is given up after {@link START_TIMEOUT_MS} and each read after
|
|
9
|
+
* {@link READ_TIMEOUT_MS}.
|
|
10
|
+
*/
|
|
11
|
+
import { EFFECTS_READ_SCRIPT, EFFECTS_START_SCRIPT, EFFECTS_STOP_SCRIPT, } from './actionEffectsScripts.js';
|
|
12
|
+
import { listenForActivity, } from './pageActivity.js';
|
|
13
|
+
import { createLogger } from '../../ui/logging/index.js';
|
|
14
|
+
import { delay, raceTimeout } from '../../utils/async.js';
|
|
15
|
+
import { getErrorMessage } from '../../utils/errors.js';
|
|
16
|
+
const log = createLogger('dom');
|
|
17
|
+
/** Messages reported per action */
|
|
18
|
+
const MAX_NEW_MESSAGES = 3;
|
|
19
|
+
/** Longest message text reported */
|
|
20
|
+
const MAX_MESSAGE_LENGTH = 120;
|
|
21
|
+
/** How long collecting waits for the snapshot taken before the action */
|
|
22
|
+
const START_TIMEOUT_MS = 200;
|
|
23
|
+
/** How long a read after the action may take before its part is skipped */
|
|
24
|
+
const READ_TIMEOUT_MS = 250;
|
|
25
|
+
/** Second look before claiming "no effect" (late timers, animations) */
|
|
26
|
+
const NO_EFFECT_RECHECK_MS = 300;
|
|
27
|
+
/**
|
|
28
|
+
* Texts that tick on their own (clocks, counters, countdowns, percentages):
|
|
29
|
+
* digits with separators and at most a time unit, e.g. `12:04:33`, `57%`,
|
|
30
|
+
* `3 s`. Their changes are not reported as new messages.
|
|
31
|
+
*/
|
|
32
|
+
const TICKING_TEXT = /^[\d\s:.,/%+\-–—()]*\d[\d\s:.,/%+\-–—()]*(ms|s|sec|secs|min|mins|h|am|pm)?$/i;
|
|
33
|
+
/**
|
|
34
|
+
* Messages that are new after the action: all of them after a new document
|
|
35
|
+
* loaded; otherwise those whose text is shown more often than before (a
|
|
36
|
+
* re-rendered message with the same text is not new) and those whose
|
|
37
|
+
* element changed its text. Texts that tick on their own
|
|
38
|
+
* ({@link TICKING_TEXT}: clocks, counters) are left out; other elements
|
|
39
|
+
* that change on their own (a rotating banner) are not recognised. Each text
|
|
40
|
+
* is reported once, at most {@link MAX_NEW_MESSAGES}, cut to
|
|
41
|
+
* {@link MAX_MESSAGE_LENGTH} characters.
|
|
42
|
+
*
|
|
43
|
+
* @param before - Messages before the action
|
|
44
|
+
* @param after - Messages after the action
|
|
45
|
+
* @param newDocument - Whether a new document loaded
|
|
46
|
+
* @returns New messages
|
|
47
|
+
*/
|
|
48
|
+
export function newMessages(before, after, newDocument) {
|
|
49
|
+
const countTexts = (messages) => {
|
|
50
|
+
const counts = new Map();
|
|
51
|
+
messages.forEach(({ text }) => counts.set(text, (counts.get(text) ?? 0) + 1));
|
|
52
|
+
return counts;
|
|
53
|
+
};
|
|
54
|
+
const beforeCounts = countTexts(before);
|
|
55
|
+
const afterCounts = countTexts(after);
|
|
56
|
+
const textBefore = new Map(before.map((message) => [message.id, message.text]));
|
|
57
|
+
const isNew = (message) => {
|
|
58
|
+
if (newDocument)
|
|
59
|
+
return true;
|
|
60
|
+
const previous = textBefore.get(message.id);
|
|
61
|
+
if (previous === message.text)
|
|
62
|
+
return false;
|
|
63
|
+
if (previous !== undefined)
|
|
64
|
+
return true;
|
|
65
|
+
return (afterCounts.get(message.text) ?? 0) > (beforeCounts.get(message.text) ?? 0);
|
|
66
|
+
};
|
|
67
|
+
const reported = new Set();
|
|
68
|
+
const result = [];
|
|
69
|
+
for (const message of after) {
|
|
70
|
+
if (result.length >= MAX_NEW_MESSAGES)
|
|
71
|
+
break;
|
|
72
|
+
if (reported.has(message.text) || TICKING_TEXT.test(message.text))
|
|
73
|
+
continue;
|
|
74
|
+
if (!isNew(message))
|
|
75
|
+
continue;
|
|
76
|
+
reported.add(message.text);
|
|
77
|
+
result.push({ text: cutText(message.text), element: message.element });
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Cut a text to {@link MAX_MESSAGE_LENGTH} characters, marking the cut.
|
|
83
|
+
*
|
|
84
|
+
* @param text - Text
|
|
85
|
+
* @returns Text of at most that length
|
|
86
|
+
*/
|
|
87
|
+
function cutText(text) {
|
|
88
|
+
const characters = Array.from(text);
|
|
89
|
+
if (characters.length <= MAX_MESSAGE_LENGTH)
|
|
90
|
+
return text;
|
|
91
|
+
return `${characters.slice(0, MAX_MESSAGE_LENGTH - 1).join('')}…`;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* How the page's location changed: a new document committed in the main
|
|
95
|
+
* frame (also when it has the URL it had, as after a form POST that
|
|
96
|
+
* redirects back), or a same-document URL change (history API, hash).
|
|
97
|
+
*
|
|
98
|
+
* Without the URL before the action, a same-document change is reported
|
|
99
|
+
* only when Chrome announced one.
|
|
100
|
+
*
|
|
101
|
+
* @param startHref - URL before the action (undefined when not read)
|
|
102
|
+
* @param read - Page read after the action (undefined when not read)
|
|
103
|
+
* @param events - Main-frame navigation events
|
|
104
|
+
* @returns Navigation, or undefined when the location did not change
|
|
105
|
+
*/
|
|
106
|
+
export function pageNavigation(startHref, read, events) {
|
|
107
|
+
if (events.document) {
|
|
108
|
+
const status = events.statusByLoader.get(events.document.loaderId);
|
|
109
|
+
return {
|
|
110
|
+
url: read?.href ?? events.document.url,
|
|
111
|
+
sameDocument: false,
|
|
112
|
+
...(status !== undefined && { status }),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const url = read?.href ?? events.withinDocumentUrl;
|
|
116
|
+
if (url === undefined || url === startHref)
|
|
117
|
+
return undefined;
|
|
118
|
+
if (startHref === undefined && events.withinDocumentUrl === undefined)
|
|
119
|
+
return undefined;
|
|
120
|
+
return { url, sameDocument: true };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Whether an action had no visible effect: the page was read before and
|
|
124
|
+
* after in the same document, it counted no DOM change, nothing made the
|
|
125
|
+
* check uncertain, and no navigation, message, request, dialog or new window
|
|
126
|
+
* happened.
|
|
127
|
+
*
|
|
128
|
+
* @param read - Page read after the action
|
|
129
|
+
* @param effects - Navigation and messages found
|
|
130
|
+
* @param activity - Requests, dialogs and windows during the action
|
|
131
|
+
* @returns True to report `effect: "none"`
|
|
132
|
+
*/
|
|
133
|
+
export function hadNoEffect(read, effects, activity) {
|
|
134
|
+
return (read !== undefined &&
|
|
135
|
+
!read.fresh &&
|
|
136
|
+
read.changes === 0 &&
|
|
137
|
+
read.uncertain === undefined &&
|
|
138
|
+
effects.navigation === undefined &&
|
|
139
|
+
(effects.messages ?? []).length === 0 &&
|
|
140
|
+
activity.requests === 0 &&
|
|
141
|
+
activity.dialogs === 0 &&
|
|
142
|
+
!activity.opened);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Start watching an action's effects: listen for main-frame navigations,
|
|
146
|
+
* document statuses, requests and new windows, and send the page snapshot
|
|
147
|
+
* without waiting for it.
|
|
148
|
+
*
|
|
149
|
+
* @param cdp - CDP connection
|
|
150
|
+
* @returns Watch to collect from after the action
|
|
151
|
+
*/
|
|
152
|
+
export function watchActionEffects(cdp) {
|
|
153
|
+
const watch = {
|
|
154
|
+
cdp,
|
|
155
|
+
listener: listenForActivity(cdp),
|
|
156
|
+
start: evaluate(cdp, EFFECTS_START_SCRIPT),
|
|
157
|
+
stopConfirmed: false,
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
collect: (options) => collectEffects(watch, options),
|
|
161
|
+
dispose: () => disposeWatch(watch),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* What changed: the navigation (from CDP events even without a snapshot),
|
|
166
|
+
* new messages and, when asked, "no effect" after a second look.
|
|
167
|
+
*
|
|
168
|
+
* @param watch - The action's watch
|
|
169
|
+
* @param options - Dialogs the action opened, and whether to decide "no effect"
|
|
170
|
+
* @returns What changed
|
|
171
|
+
*/
|
|
172
|
+
async function collectEffects(watch, options) {
|
|
173
|
+
const start = await raceTimeout(watch.start, START_TIMEOUT_MS);
|
|
174
|
+
if (!start)
|
|
175
|
+
return effectsOf(undefined, undefined, watch.listener.events);
|
|
176
|
+
let snapshot = await readPage(watch, false);
|
|
177
|
+
let effects = effectsOf(start, snapshot, watch.listener.events);
|
|
178
|
+
const quiet = () => hadNoEffect(snapshot, effects, { ...watch.listener.activity(), dialogs: options.dialogs });
|
|
179
|
+
if (!options.detectNoEffect || !quiet())
|
|
180
|
+
return effects;
|
|
181
|
+
await delay(NO_EFFECT_RECHECK_MS);
|
|
182
|
+
snapshot = await readPage(watch, true);
|
|
183
|
+
effects = effectsOf(start, snapshot, watch.listener.events);
|
|
184
|
+
return quiet() ? { ...effects, effect: 'none' } : effects;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Navigation and new messages from the snapshots and CDP events.
|
|
188
|
+
*
|
|
189
|
+
* @param start - Snapshot before the action, if taken
|
|
190
|
+
* @param snapshot - Read after the action, if taken
|
|
191
|
+
* @param events - Main-frame navigation events
|
|
192
|
+
* @returns Effects, without empty parts
|
|
193
|
+
*/
|
|
194
|
+
function effectsOf(start, snapshot, events) {
|
|
195
|
+
const navigation = pageNavigation(start?.href, snapshot, events);
|
|
196
|
+
const messages = start && snapshot ? newMessages(start.messages, snapshot.messages, snapshot.fresh) : [];
|
|
197
|
+
return {
|
|
198
|
+
...(navigation && { navigation }),
|
|
199
|
+
...(messages.length > 0 && { messages }),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Read the page after the action, unless a main-frame load is pending (the
|
|
204
|
+
* read would wait for the new page). A stopping read that answered stops the
|
|
205
|
+
* page's watch, so disposing need not.
|
|
206
|
+
*
|
|
207
|
+
* @param watch - The action's watch
|
|
208
|
+
* @param stop - Also stop the page's watch
|
|
209
|
+
* @returns The read, or undefined
|
|
210
|
+
*/
|
|
211
|
+
async function readPage(watch, stop) {
|
|
212
|
+
if (watch.listener.navigationPending())
|
|
213
|
+
return undefined;
|
|
214
|
+
const expression = `(${EFFECTS_READ_SCRIPT})(${stop})`;
|
|
215
|
+
const snapshot = await raceTimeout(evaluate(watch.cdp, expression), READ_TIMEOUT_MS);
|
|
216
|
+
if (stop && snapshot)
|
|
217
|
+
watch.stopConfirmed = true;
|
|
218
|
+
return snapshot;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Stop listening, and stop the page's watch unless a read did. The stop is
|
|
222
|
+
* sent even when the snapshot never answered: CDP runs it after the
|
|
223
|
+
* snapshot, wherever that ran (the page also stops watching on its own
|
|
224
|
+
* after 30 s).
|
|
225
|
+
*
|
|
226
|
+
* @param watch - The action's watch
|
|
227
|
+
*/
|
|
228
|
+
function disposeWatch(watch) {
|
|
229
|
+
watch.listener.dispose();
|
|
230
|
+
if (watch.stopConfirmed)
|
|
231
|
+
return;
|
|
232
|
+
void watch.cdp
|
|
233
|
+
.send('Runtime.evaluate', { expression: EFFECTS_STOP_SCRIPT })
|
|
234
|
+
.catch((error) => log.debug(`Effects watch not stopped: ${getErrorMessage(error)}`));
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Evaluate a page script for its value (undefined on an exception or a
|
|
238
|
+
* failed call).
|
|
239
|
+
*
|
|
240
|
+
* @param cdp - CDP connection
|
|
241
|
+
* @param expression - Script
|
|
242
|
+
* @returns Its value, or undefined
|
|
243
|
+
*/
|
|
244
|
+
async function evaluate(cdp, expression) {
|
|
245
|
+
try {
|
|
246
|
+
const reply = (await cdp.send('Runtime.evaluate', { expression, returnByValue: true }));
|
|
247
|
+
if (!reply.exceptionDetails)
|
|
248
|
+
return reply.result?.value;
|
|
249
|
+
log.debug(`Effects script failed: ${reply.exceptionDetails.text}`);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
log.debug(`Effects script not run: ${getErrorMessage(error)}`);
|
|
253
|
+
}
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=actionEffects.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page scripts behind the "what changed" part of DOM action results: one
|
|
3
|
+
* snapshot before the action ({@link EFFECTS_START_SCRIPT}) and one read after
|
|
4
|
+
* it ({@link EFFECTS_READ_SCRIPT}).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Page-side test whether an element is part of a message's chrome rather
|
|
8
|
+
* than its text: aria-hidden parts, buttons, and elements whose class or
|
|
9
|
+
* aria-label names a close/dismiss control (`close`, `btn-close`, `close_x`;
|
|
10
|
+
* not `closeable`, `enclosed` or `disclosure`).
|
|
11
|
+
*/
|
|
12
|
+
export declare const MESSAGE_CHROME_JS = "(node) => {\n const closer = /(^|[-_\\s])(close|dismiss)($|[-_\\s])/i;\n return node.getAttribute('aria-hidden') === 'true' ||\n /^(button|script|style|template)$/.test(node.localName) ||\n node.getAttribute('role') === 'button' ||\n closer.test(node.getAttribute('class') || '') ||\n closer.test(node.getAttribute('aria-label') || '');\n}";
|
|
13
|
+
/**
|
|
14
|
+
* Page-side test whether a mutation is only focus/hover churn: a class
|
|
15
|
+
* change on an element the action's events hit (`targets`) that only adds
|
|
16
|
+
* or removes classes containing "focus" or "hover".
|
|
17
|
+
*/
|
|
18
|
+
export declare const CHURN_ONLY_JS = "(record, targets) => {\n if (record.type !== 'attributes' || record.attributeName !== 'class' || !targets.has(record.target)) return false;\n const tokens = (text) => new Set((text || '').split(/\\s+/).filter(Boolean));\n const before = tokens(record.oldValue);\n const after = tokens(record.target.getAttribute('class'));\n const changed = [...before].filter((c) => !after.has(c)).concat([...after].filter((c) => !before.has(c)));\n return changed.every((c) => /focus|hover/i.test(c));\n}";
|
|
19
|
+
/**
|
|
20
|
+
* Page-side reason why "no effect" can't be claimed even without DOM
|
|
21
|
+
* changes, or undefined: `clipboard` (a copy or cut happened), `no-event`
|
|
22
|
+
* (no event reached the page), `control` (form controls, labels, media,
|
|
23
|
+
* frames, popover/command buttons: their effect needs no DOM change),
|
|
24
|
+
* `new-window` (download or `target` links), `external-link` (mailto:, tel:,
|
|
25
|
+
* javascript: and other non-http links), `closed-shadow` (a custom element
|
|
26
|
+
* whose inside is not observed) or `focus` (focus moved to an element that
|
|
27
|
+
* may reveal content with CSS).
|
|
28
|
+
*/
|
|
29
|
+
export declare const UNCERTAIN_JS = "(state, active) => {\n if (state.copied) return 'clipboard';\n if (state.targets.size === 0) return 'no-event';\n const controls = /^(input|select|textarea|option|label|canvas|video|audio|iframe|embed|object)$/;\n for (const node of state.path) {\n if (controls.test(node.localName) || node.isContentEditable) return 'control';\n if (node.hasAttribute('popovertarget') || node.hasAttribute('commandfor')) return 'control';\n if (node.localName === 'a' && node.hasAttribute('href')) {\n if (node.hasAttribute('download') || (node.target && node.target !== '_self')) return 'new-window';\n if (!/^https?:$/.test(node.protocol)) return 'external-link';\n }\n }\n for (const node of state.targets) if (node.localName.includes('-') && !node.shadowRoot) return 'closed-shadow';\n const plain = (node) => /^(body|button|summary)$/.test(node.localName) ||\n (node.localName === 'a' && node.hasAttribute('href')) ||\n (node.localName === 'input' && /^(button|submit|reset)$/i.test(node.type || ''));\n if (active && active !== state.focus && !plain(active)) return 'focus';\n return undefined;\n}";
|
|
30
|
+
/**
|
|
31
|
+
* Snapshot before an action, left in `window.__bdgEffects`: the messages
|
|
32
|
+
* shown, and a MutationObserver (on the document, its open shadow roots and
|
|
33
|
+
* any shadow root attached while watching, which also counts as a change)
|
|
34
|
+
* counting changes other than {@link CHURN_ONLY_JS}. Capture listeners
|
|
35
|
+
* record which elements the action's events reached, copy/cut events, and
|
|
36
|
+
* the scroll position at the first press (a click scrolls its target into
|
|
37
|
+
* view first). The watch stops itself after {@link MAX_WATCH_MS}, so a
|
|
38
|
+
* snapshot that ran late (after a navigation, with nobody reading it)
|
|
39
|
+
* leaves nothing behind. Evaluates to the URL and the messages.
|
|
40
|
+
*/
|
|
41
|
+
export declare const EFFECTS_START_SCRIPT: string;
|
|
42
|
+
/**
|
|
43
|
+
* Read after an action (call with `true` to also stop watching): the URL,
|
|
44
|
+
* the messages shown and, when the snapshot is still there (same document),
|
|
45
|
+
* the number of changes counted (plus one when the page scrolled after the
|
|
46
|
+
* press) and why "no effect" could not be claimed ({@link UNCERTAIN_JS}).
|
|
47
|
+
* `fresh` means a new document (everything shown is new).
|
|
48
|
+
*/
|
|
49
|
+
export declare const EFFECTS_READ_SCRIPT: string;
|
|
50
|
+
/** Stops the watch {@link EFFECTS_START_SCRIPT} left (when no read stopped it) */
|
|
51
|
+
export declare const EFFECTS_STOP_SCRIPT = "if (window.__bdgEffects) { window.__bdgEffects.stop(); delete window.__bdgEffects; }";
|
|
52
|
+
//# sourceMappingURL=actionEffectsScripts.d.ts.map
|