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
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* User-facing messages for the console command output and formatting.
|
|
5
5
|
*/
|
|
6
|
+
import type { ConsoleSkipped } from '../formatters/console/shared.js';
|
|
6
7
|
/**
|
|
7
8
|
* Generate message for following console output.
|
|
8
9
|
*
|
|
@@ -15,4 +16,13 @@ export declare function followingConsoleMessage(): string;
|
|
|
15
16
|
* @returns Status message for stderr
|
|
16
17
|
*/
|
|
17
18
|
export declare function stoppedFollowingConsoleMessage(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Note under a console list whose indices skip messages: the indices are
|
|
21
|
+
* positions in the session's message list (what `bdg details console <n>`
|
|
22
|
+
* takes), and the messages in between were left out by the filters.
|
|
23
|
+
*
|
|
24
|
+
* @param skipped - Messages left out between the first and last listed index
|
|
25
|
+
* @returns e.g. `[n] are positions in the session's message list; not listed in between: 1 message from another page load (-H lists all)`
|
|
26
|
+
*/
|
|
27
|
+
export declare function consoleIndexGapNote(skipped: ConsoleSkipped): string;
|
|
18
28
|
//# sourceMappingURL=consoleMessages.d.ts.map
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* User-facing messages for the console command output and formatting.
|
|
5
5
|
*/
|
|
6
|
+
import { pluralize } from '../formatting.js';
|
|
6
7
|
/**
|
|
7
8
|
* Generate message for following console output.
|
|
8
9
|
*
|
|
@@ -19,4 +20,20 @@ export function followingConsoleMessage() {
|
|
|
19
20
|
export function stoppedFollowingConsoleMessage() {
|
|
20
21
|
return 'Stopped streaming console messages';
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Note under a console list whose indices skip messages: the indices are
|
|
25
|
+
* positions in the session's message list (what `bdg details console <n>`
|
|
26
|
+
* takes), and the messages in between were left out by the filters.
|
|
27
|
+
*
|
|
28
|
+
* @param skipped - Messages left out between the first and last listed index
|
|
29
|
+
* @returns e.g. `[n] are positions in the session's message list; not listed in between: 1 message from another page load (-H lists all)`
|
|
30
|
+
*/
|
|
31
|
+
export function consoleIndexGapNote(skipped) {
|
|
32
|
+
const reasons = [
|
|
33
|
+
skipped.otherLevels > 0 && `${pluralize(skipped.otherLevels, 'message')} of another level`,
|
|
34
|
+
skipped.otherPages > 0 &&
|
|
35
|
+
`${pluralize(skipped.otherPages, 'message')} from another page load (-H lists all)`,
|
|
36
|
+
].filter(Boolean);
|
|
37
|
+
return `[n] are positions in the session's message list; not listed in between: ${reasons.join(', ')}`;
|
|
38
|
+
}
|
|
22
39
|
//# sourceMappingURL=consoleMessages.js.map
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* session stays free of UI imports.
|
|
7
7
|
*/
|
|
8
8
|
import { joinLines } from '../formatting.js';
|
|
9
|
+
import { sessionCommand } from './sessionCommand.js';
|
|
9
10
|
/**
|
|
10
11
|
* Format a structured hint into a user-facing string.
|
|
11
12
|
*
|
|
@@ -19,7 +20,7 @@ export function formatHint(hint) {
|
|
|
19
20
|
case 'PATTERN_HINT': {
|
|
20
21
|
const alternative = ctx['alternative'];
|
|
21
22
|
const cdpMethods = ctx['cdpMethods'] ?? [];
|
|
22
|
-
return joinLines('', `Hint: Consider using '${alternative}' instead of ${cdpMethods.join(' or ')}`, '');
|
|
23
|
+
return joinLines('', `Hint: Consider using '${sessionCommand(alternative)}' instead of ${cdpMethods.join(' or ')}`, '');
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* User-facing messages for the peek command, including empty states,
|
|
5
5
|
* tips, and interactive command suggestions.
|
|
6
6
|
* */
|
|
7
|
+
import { sessionCommand } from './sessionCommand.js';
|
|
7
8
|
export const PREVIEW_EMPTY_STATES = {
|
|
8
9
|
NO_DATA: '(none)',
|
|
9
10
|
NO_NETWORK_REQUESTS: 'No network requests yet',
|
|
@@ -18,7 +19,7 @@ export const PREVIEW_HEADERS = {
|
|
|
18
19
|
* @returns Single-line tip for basic peek usage
|
|
19
20
|
*/
|
|
20
21
|
export function compactTipsMessage() {
|
|
21
|
-
return
|
|
22
|
+
return `Tip: ${sessionCommand('bdg peek --last 50')} | ${sessionCommand('bdg peek --verbose')}`;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Generate verbose mode commands section.
|
|
@@ -28,9 +29,9 @@ export function compactTipsMessage() {
|
|
|
28
29
|
export function verboseCommandsMessage() {
|
|
29
30
|
return [
|
|
30
31
|
'Commands:',
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
` Full preview: ${sessionCommand('bdg peek --last 50')}`,
|
|
33
|
+
` Watch live: ${sessionCommand('bdg tail')}`,
|
|
34
|
+
` End session: ${sessionCommand('bdg stop')}`,
|
|
34
35
|
].join('\n');
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Centralized location for all session UI text including landing pages,
|
|
5
5
|
* status displays, and session management messages.
|
|
6
6
|
*/
|
|
7
|
+
import type { PageLoadingState } from '../../ipc/protocol/commands.js';
|
|
7
8
|
/**
|
|
8
9
|
* Options for the landing page display.
|
|
9
10
|
*/
|
|
@@ -12,41 +13,37 @@ export interface LandingPageOptions {
|
|
|
12
13
|
url: string;
|
|
13
14
|
/** HTTP status of the main document (a warning is shown for 4xx/5xx) */
|
|
14
15
|
documentStatus?: number;
|
|
16
|
+
/** The page had not finished loading (a warning names what it waits on) */
|
|
17
|
+
loading?: PageLoadingState;
|
|
15
18
|
/** When `--timeout` will stop the session */
|
|
16
19
|
autoStopAt?: Date;
|
|
20
|
+
/** Name of a named session (`--session`) */
|
|
21
|
+
session?: string;
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
19
24
|
* Lines shown under the target in both the full and the quiet start output:
|
|
20
|
-
* an HTTP error of the page,
|
|
25
|
+
* the session name, an HTTP error of the page, a page still loading, and
|
|
26
|
+
* when the session stops by itself.
|
|
21
27
|
*
|
|
22
28
|
* @param options - Landing page options
|
|
23
29
|
* @returns Lines (empty when there is nothing to say)
|
|
24
30
|
*/
|
|
25
31
|
export declare function startNotices(options: LandingPageOptions): string[];
|
|
26
32
|
/**
|
|
27
|
-
* Generate the
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* High-level commands are presented first to guide agents toward token-efficient
|
|
31
|
-
* wrappers before falling back to verbose CDP commands.
|
|
32
|
-
*
|
|
33
|
-
* Section order optimized for agent discoverability:
|
|
34
|
-
* 1. Common tasks with token savings estimates
|
|
35
|
-
* 2. Comprehensive domain command coverage (12+ commands)
|
|
36
|
-
* 3. Live monitoring capabilities
|
|
37
|
-
* 4. Session management
|
|
38
|
-
* 5. Advanced CDP access (positioned as fallback)
|
|
39
|
-
* 6. Discovery resources for agents
|
|
33
|
+
* Generate the start output: the target, the notices of {@link startNotices},
|
|
34
|
+
* one line of next commands and where to find the rest. Kept to a few lines
|
|
35
|
+
* because agents read it on every start; `bdg --help` lists everything.
|
|
40
36
|
*
|
|
41
37
|
* @param options - Landing page options
|
|
42
|
-
* @returns Formatted
|
|
38
|
+
* @returns Formatted start output
|
|
43
39
|
*
|
|
44
40
|
* @example
|
|
45
41
|
* ```typescript
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
42
|
+
* landingPage({ url: 'http://localhost:3000' });
|
|
43
|
+
* // Session Started
|
|
44
|
+
* // Target: http://localhost:3000
|
|
45
|
+
* // Next: bdg dom layout <selector>, bdg dom query <selector>, ...
|
|
46
|
+
* // More: bdg --help (bdg --help --json for agents)
|
|
50
47
|
* ```
|
|
51
48
|
*/
|
|
52
49
|
export declare function landingPage(options: LandingPageOptions): string;
|
|
@@ -61,9 +58,7 @@ export declare function sessionStopped(): string;
|
|
|
61
58
|
*/
|
|
62
59
|
export declare const STOP_MESSAGES: {
|
|
63
60
|
readonly SUCCESS: "Session stopped successfully";
|
|
64
|
-
readonly NO_SESSION: "No active session found";
|
|
65
61
|
readonly FAILED: "Failed to stop session";
|
|
66
|
-
readonly DAEMON_NOT_RUNNING: "No active session";
|
|
67
62
|
};
|
|
68
63
|
/**
|
|
69
64
|
* Generate stop session failed error message.
|
|
@@ -4,54 +4,58 @@
|
|
|
4
4
|
* Centralized location for all session UI text including landing pages,
|
|
5
5
|
* status displays, and session management messages.
|
|
6
6
|
*/
|
|
7
|
-
import { buildCommonTasksSection, buildDomainCommandsSection, buildLiveMonitoringSection, buildSessionManagementSection, buildCdpSection, buildDiscoverySection, } from '../formatters/sessionFormatters.js';
|
|
8
7
|
import { joinLines } from '../formatting.js';
|
|
8
|
+
import { pageLoadingWarning } from './commands.js';
|
|
9
9
|
/**
|
|
10
10
|
* Lines shown under the target in both the full and the quiet start output:
|
|
11
|
-
* an HTTP error of the page,
|
|
11
|
+
* the session name, an HTTP error of the page, a page still loading, and
|
|
12
|
+
* when the session stops by itself.
|
|
12
13
|
*
|
|
13
14
|
* @param options - Landing page options
|
|
14
15
|
* @returns Lines (empty when there is nothing to say)
|
|
15
16
|
*/
|
|
16
17
|
export function startNotices(options) {
|
|
17
|
-
const { documentStatus, autoStopAt } = options;
|
|
18
|
+
const { documentStatus, loading, autoStopAt, session } = options;
|
|
18
19
|
return [
|
|
20
|
+
...(session
|
|
21
|
+
? [
|
|
22
|
+
`Session: ${session} (pass --session ${session} or set BDG_SESSION=${session} on every command)`,
|
|
23
|
+
]
|
|
24
|
+
: []),
|
|
19
25
|
...(documentStatus !== undefined && documentStatus >= 400
|
|
20
26
|
? [`⚠ The page responded with HTTP ${documentStatus}`]
|
|
21
27
|
: []),
|
|
28
|
+
...(loading ? [`⚠ ${pageLoadingWarning(loading)}`] : []),
|
|
22
29
|
...(autoStopAt ? [`Auto-stop: at ${autoStopAt.toLocaleTimeString()} (--timeout)`] : []),
|
|
23
30
|
];
|
|
24
31
|
}
|
|
32
|
+
/** Most useful commands after a start, cheapest first (screenshots cost the most tokens) */
|
|
33
|
+
const START_NEXT_COMMANDS = [
|
|
34
|
+
'bdg dom layout <selector>',
|
|
35
|
+
'bdg dom query <selector>',
|
|
36
|
+
'bdg dom form',
|
|
37
|
+
'bdg peek',
|
|
38
|
+
'bdg dom screenshot out.png',
|
|
39
|
+
];
|
|
25
40
|
/**
|
|
26
|
-
* Generate the
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* High-level commands are presented first to guide agents toward token-efficient
|
|
30
|
-
* wrappers before falling back to verbose CDP commands.
|
|
31
|
-
*
|
|
32
|
-
* Section order optimized for agent discoverability:
|
|
33
|
-
* 1. Common tasks with token savings estimates
|
|
34
|
-
* 2. Comprehensive domain command coverage (12+ commands)
|
|
35
|
-
* 3. Live monitoring capabilities
|
|
36
|
-
* 4. Session management
|
|
37
|
-
* 5. Advanced CDP access (positioned as fallback)
|
|
38
|
-
* 6. Discovery resources for agents
|
|
41
|
+
* Generate the start output: the target, the notices of {@link startNotices},
|
|
42
|
+
* one line of next commands and where to find the rest. Kept to a few lines
|
|
43
|
+
* because agents read it on every start; `bdg --help` lists everything.
|
|
39
44
|
*
|
|
40
45
|
* @param options - Landing page options
|
|
41
|
-
* @returns Formatted
|
|
46
|
+
* @returns Formatted start output
|
|
42
47
|
*
|
|
43
48
|
* @example
|
|
44
49
|
* ```typescript
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
50
|
+
* landingPage({ url: 'http://localhost:3000' });
|
|
51
|
+
* // Session Started
|
|
52
|
+
* // Target: http://localhost:3000
|
|
53
|
+
* // Next: bdg dom layout <selector>, bdg dom query <selector>, ...
|
|
54
|
+
* // More: bdg --help (bdg --help --json for agents)
|
|
49
55
|
* ```
|
|
50
56
|
*/
|
|
51
57
|
export function landingPage(options) {
|
|
52
|
-
|
|
53
|
-
const notices = startNotices(options);
|
|
54
|
-
return joinLines('', 'Session Started', '', `Target: ${url}`, '', ...(notices.length > 0 ? [...notices, ''] : []), buildCommonTasksSection(), '', buildDomainCommandsSection(), '', buildLiveMonitoringSection(), '', buildSessionManagementSection(), '', buildCdpSection(), '', buildDiscoverySection(), '');
|
|
58
|
+
return joinLines('Session Started', `Target: ${options.url}`, ...startNotices(options), `Next: ${START_NEXT_COMMANDS.join(', ')}`, 'More: bdg --help (bdg --help --json for agents)');
|
|
55
59
|
}
|
|
56
60
|
/**
|
|
57
61
|
* Generate "session stopped" success message.
|
|
@@ -66,9 +70,7 @@ export function sessionStopped() {
|
|
|
66
70
|
*/
|
|
67
71
|
export const STOP_MESSAGES = {
|
|
68
72
|
SUCCESS: 'Session stopped successfully',
|
|
69
|
-
NO_SESSION: 'No active session found',
|
|
70
73
|
FAILED: 'Failed to stop session',
|
|
71
|
-
DAEMON_NOT_RUNNING: 'No active session',
|
|
72
74
|
};
|
|
73
75
|
/**
|
|
74
76
|
* Generate stop session failed error message.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bdg command lines and wording for the selected session.
|
|
3
|
+
*
|
|
4
|
+
* Every hint, suggestion and error that tells the user to run a bdg command
|
|
5
|
+
* goes through {@link sessionCommand}, so a named session's hints carry
|
|
6
|
+
* `--session <name>` and following them never acts on the default session.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* A bdg command for the selected session: ` --session <name>` is appended
|
|
10
|
+
* when a named session is selected.
|
|
11
|
+
*
|
|
12
|
+
* @param command - Command line, e.g. `bdg stop`
|
|
13
|
+
* @param session - Session name (defaults to the selected one; null for the default session)
|
|
14
|
+
* @returns The command, scoped to the session
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* sessionCommand('bdg stop'); // 'bdg stop' (default session)
|
|
19
|
+
* sessionCommand('bdg stop', 'agent-1'); // 'bdg stop --session agent-1'
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function sessionCommand(command: string, session?: string | null): string;
|
|
23
|
+
/**
|
|
24
|
+
* "No active session", naming a named session.
|
|
25
|
+
*
|
|
26
|
+
* @param session - Session name (defaults to the selected one; null for the default session)
|
|
27
|
+
* @returns `No active session` or `No active session "<name>"`
|
|
28
|
+
*/
|
|
29
|
+
export declare function noActiveSessionMessage(session?: string | null): string;
|
|
30
|
+
/**
|
|
31
|
+
* Shell command that deletes a directory by hand (single-quoted).
|
|
32
|
+
*
|
|
33
|
+
* @param dir - Directory
|
|
34
|
+
* @returns Command line
|
|
35
|
+
*/
|
|
36
|
+
export declare function removeDirCommand(dir: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* How to start the selected session.
|
|
39
|
+
*
|
|
40
|
+
* @returns Suggestion
|
|
41
|
+
*/
|
|
42
|
+
export declare function startSessionSuggestion(): string;
|
|
43
|
+
//# sourceMappingURL=sessionCommand.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bdg command lines and wording for the selected session.
|
|
3
|
+
*
|
|
4
|
+
* Every hint, suggestion and error that tells the user to run a bdg command
|
|
5
|
+
* goes through {@link sessionCommand}, so a named session's hints carry
|
|
6
|
+
* `--session <name>` and following them never acts on the default session.
|
|
7
|
+
*/
|
|
8
|
+
import { getSessionName } from '../../session/paths.js';
|
|
9
|
+
/**
|
|
10
|
+
* A bdg command for the selected session: ` --session <name>` is appended
|
|
11
|
+
* when a named session is selected.
|
|
12
|
+
*
|
|
13
|
+
* @param command - Command line, e.g. `bdg stop`
|
|
14
|
+
* @param session - Session name (defaults to the selected one; null for the default session)
|
|
15
|
+
* @returns The command, scoped to the session
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* sessionCommand('bdg stop'); // 'bdg stop' (default session)
|
|
20
|
+
* sessionCommand('bdg stop', 'agent-1'); // 'bdg stop --session agent-1'
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function sessionCommand(command, session = getSessionName()) {
|
|
24
|
+
return session === null ? command : `${command} --session ${session}`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* "No active session", naming a named session.
|
|
28
|
+
*
|
|
29
|
+
* @param session - Session name (defaults to the selected one; null for the default session)
|
|
30
|
+
* @returns `No active session` or `No active session "<name>"`
|
|
31
|
+
*/
|
|
32
|
+
export function noActiveSessionMessage(session = getSessionName()) {
|
|
33
|
+
return session === null ? 'No active session' : `No active session "${session}"`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Shell command that deletes a directory by hand (single-quoted).
|
|
37
|
+
*
|
|
38
|
+
* @param dir - Directory
|
|
39
|
+
* @returns Command line
|
|
40
|
+
*/
|
|
41
|
+
export function removeDirCommand(dir) {
|
|
42
|
+
return `rm -rf '${dir.replaceAll("'", "'\\''")}'`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* How to start the selected session.
|
|
46
|
+
*
|
|
47
|
+
* @returns Suggestion
|
|
48
|
+
*/
|
|
49
|
+
export function startSessionSuggestion() {
|
|
50
|
+
return `Start a session with: ${sessionCommand('bdg <url>')}`;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=sessionCommand.js.map
|
package/dist/utils/async.d.ts
CHANGED
|
@@ -7,4 +7,12 @@
|
|
|
7
7
|
* @param ms - Milliseconds to delay
|
|
8
8
|
*/
|
|
9
9
|
export declare function delay(ms: number): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Wait for a promise, giving up after a time; the timer is cleared either way.
|
|
12
|
+
*
|
|
13
|
+
* @param promise - Work to wait for
|
|
14
|
+
* @param ms - Milliseconds to wait at most
|
|
15
|
+
* @returns The promise's result, or undefined when the time ran out first
|
|
16
|
+
*/
|
|
17
|
+
export declare function raceTimeout<T>(promise: Promise<T>, ms: number): Promise<T | undefined>;
|
|
10
18
|
//# sourceMappingURL=async.d.ts.map
|
package/dist/utils/async.js
CHANGED
|
@@ -9,4 +9,23 @@
|
|
|
9
9
|
export function delay(ms) {
|
|
10
10
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Wait for a promise, giving up after a time; the timer is cleared either way.
|
|
14
|
+
*
|
|
15
|
+
* @param promise - Work to wait for
|
|
16
|
+
* @param ms - Milliseconds to wait at most
|
|
17
|
+
* @returns The promise's result, or undefined when the time ran out first
|
|
18
|
+
*/
|
|
19
|
+
export async function raceTimeout(promise, ms) {
|
|
20
|
+
let timer;
|
|
21
|
+
const timeout = new Promise((resolve) => {
|
|
22
|
+
timer = setTimeout(() => resolve(undefined), ms);
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
return await Promise.race([promise, timeout]);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
12
31
|
//# sourceMappingURL=async.js.map
|
package/dist/utils/http.d.ts
CHANGED
|
@@ -30,13 +30,34 @@ export interface FetchCDPTargetsOptions {
|
|
|
30
30
|
* - Network errors are logged to help diagnose Chrome connectivity issues
|
|
31
31
|
*/
|
|
32
32
|
export declare function fetchCDPTargets(port?: number, logger?: Logger, options?: FetchCDPTargetsOptions): Promise<CDPTarget[]>;
|
|
33
|
+
/**
|
|
34
|
+
* What answers on a DevTools HTTP endpoint: a Chrome (with its browser-level
|
|
35
|
+
* WebSocket URL), an HTTP server that is not DevTools, or nothing.
|
|
36
|
+
*/
|
|
37
|
+
export type DevToolsProbe = {
|
|
38
|
+
kind: 'devtools';
|
|
39
|
+
wsUrl: string;
|
|
40
|
+
} | {
|
|
41
|
+
kind: 'not-devtools';
|
|
42
|
+
} | {
|
|
43
|
+
kind: 'unreachable';
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Ask an endpoint for its DevTools version (`/json/version`).
|
|
47
|
+
*
|
|
48
|
+
* @param port - Chrome debugging port
|
|
49
|
+
* @param logger - Optional logger for debug output
|
|
50
|
+
* @param options - Host and HTTPS
|
|
51
|
+
* @returns What answered
|
|
52
|
+
*/
|
|
53
|
+
export declare function probeDevToolsEndpoint(port: number, logger?: Logger, options?: Pick<FetchCDPTargetsOptions, 'host' | 'secure'>): Promise<DevToolsProbe>;
|
|
33
54
|
/**
|
|
34
55
|
* The browser-level DevTools WebSocket URL of a Chrome (`/json/version`).
|
|
35
56
|
*
|
|
36
57
|
* @param port - Chrome debugging port
|
|
37
58
|
* @param logger - Optional logger for debug output
|
|
38
59
|
* @param options - Host and HTTPS
|
|
39
|
-
* @returns The URL, or null if Chrome
|
|
60
|
+
* @returns The URL, or null if no Chrome answered
|
|
40
61
|
*/
|
|
41
62
|
export declare function fetchBrowserWsUrl(port: number, logger?: Logger, options?: Pick<FetchCDPTargetsOptions, 'host' | 'secure'>): Promise<string | null>;
|
|
42
63
|
/**
|
package/dist/utils/http.js
CHANGED
|
@@ -63,26 +63,45 @@ export async function fetchCDPTargets(port = DEFAULT_CDP_PORT, logger, options)
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
66
|
+
* Ask an endpoint for its DevTools version (`/json/version`).
|
|
67
67
|
*
|
|
68
68
|
* @param port - Chrome debugging port
|
|
69
69
|
* @param logger - Optional logger for debug output
|
|
70
70
|
* @param options - Host and HTTPS
|
|
71
|
-
* @returns
|
|
71
|
+
* @returns What answered
|
|
72
72
|
*/
|
|
73
|
-
export async function
|
|
73
|
+
export async function probeDevToolsEndpoint(port, logger, options) {
|
|
74
74
|
const url = `${options?.secure ? 'https' : 'http'}://${options?.host ?? HTTP_LOCALHOST}:${port}/json/version`;
|
|
75
|
+
let response;
|
|
75
76
|
try {
|
|
76
|
-
|
|
77
|
-
if (!response.ok)
|
|
78
|
-
return null;
|
|
79
|
-
const data = (await response.json());
|
|
80
|
-
return typeof data.webSocketDebuggerUrl === 'string' ? data.webSocketDebuggerUrl : null;
|
|
77
|
+
response = await fetch(url, { signal: AbortSignal.timeout(CDP_HTTP_TIMEOUT_MS) });
|
|
81
78
|
}
|
|
82
79
|
catch (error) {
|
|
83
80
|
logger?.debug(`Chrome version request failed: ${getErrorMessage(error)} (${url})`);
|
|
84
|
-
return
|
|
81
|
+
return { kind: 'unreachable' };
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const data = (await response.json());
|
|
85
|
+
const wsUrl = data?.webSocketDebuggerUrl;
|
|
86
|
+
if (response.ok && typeof wsUrl === 'string')
|
|
87
|
+
return { kind: 'devtools', wsUrl };
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
logger?.debug(`Chrome version response is not JSON: ${getErrorMessage(error)} (${url})`);
|
|
85
91
|
}
|
|
92
|
+
return { kind: 'not-devtools' };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The browser-level DevTools WebSocket URL of a Chrome (`/json/version`).
|
|
96
|
+
*
|
|
97
|
+
* @param port - Chrome debugging port
|
|
98
|
+
* @param logger - Optional logger for debug output
|
|
99
|
+
* @param options - Host and HTTPS
|
|
100
|
+
* @returns The URL, or null if no Chrome answered
|
|
101
|
+
*/
|
|
102
|
+
export async function fetchBrowserWsUrl(port, logger, options) {
|
|
103
|
+
const probe = await probeDevToolsEndpoint(port, logger, options);
|
|
104
|
+
return probe.kind === 'devtools' ? probe.wsUrl : null;
|
|
86
105
|
}
|
|
87
106
|
/**
|
|
88
107
|
* Fetch specific CDP target by ID from Chrome's HTTP API.
|
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
* `:visible`.
|
|
4
4
|
*
|
|
5
5
|
* They are not CSS, so the selector is split here (in Node) into the CSS the
|
|
6
|
-
* browser runs and the filters the page applies to its matches.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* browser runs and the filters the page applies to its matches. A filter
|
|
7
|
+
* applies to the compound it is written in (`li.item:has-text("x"):visible`,
|
|
8
|
+
* `a:visible.active`). On the last compound it narrows down the matches; on an
|
|
9
|
+
* earlier one it scopes the rest of the selector, which is then matched under
|
|
10
|
+
* each element passing the filter: `li:has-text("Buy milk") .toggle` is the
|
|
11
|
+
* `.toggle` inside the row that says "Buy milk". Only descendant and child
|
|
12
|
+
* combinators can follow a filtered compound. Inside `:has()` filters test
|
|
13
|
+
* what an element contains (`li:has(label:text-is("x"))`); inside other
|
|
14
|
+
* pseudo-classes (`:not(:visible)`) they would have to be evaluated by the
|
|
15
|
+
* browser's selector matching, which bdg cannot do.
|
|
12
16
|
*/
|
|
13
17
|
/** Filter applied in the page to the elements the CSS part matched. */
|
|
14
18
|
export type SelectorFilter = {
|
|
@@ -19,11 +23,27 @@ export type SelectorFilter = {
|
|
|
19
23
|
text: string;
|
|
20
24
|
} | {
|
|
21
25
|
kind: 'visible';
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'has';
|
|
28
|
+
selectors: ScopedStep[][];
|
|
22
29
|
};
|
|
23
|
-
/**
|
|
30
|
+
/** Combinators a scoped step can follow: descendant (` `) and child (`>`). */
|
|
31
|
+
export type ScopeCombinator = ' ' | '>';
|
|
32
|
+
/** CSS matched under a scope element (`:scope <combinator> <css>`), then filtered. */
|
|
33
|
+
export interface ScopedStep {
|
|
34
|
+
combinator: ScopeCombinator;
|
|
35
|
+
css: string;
|
|
36
|
+
filters: SelectorFilter[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* One selector of a selector list: the CSS to run and the filters for its
|
|
40
|
+
* matches; `steps` (when a filtered compound is not the last) are matched
|
|
41
|
+
* under each of them in turn, and the last step's matches are the result.
|
|
42
|
+
*/
|
|
24
43
|
export interface SelectorPart {
|
|
25
44
|
css: string;
|
|
26
45
|
filters: SelectorFilter[];
|
|
46
|
+
steps?: ScopedStep[];
|
|
27
47
|
}
|
|
28
48
|
/**
|
|
29
49
|
* Split a selector into the CSS part and filters of each selector of its
|
|
@@ -31,9 +51,17 @@ export interface SelectorPart {
|
|
|
31
51
|
*
|
|
32
52
|
* @param selector - Selector as the user gave it
|
|
33
53
|
* @returns The parts, or null for plain CSS (no filters anywhere), which runs unchanged
|
|
34
|
-
* @throws CommandError (81) for a
|
|
54
|
+
* @throws CommandError (81) for a misplaced or malformed filter
|
|
35
55
|
*/
|
|
36
56
|
export declare function parseSelectorFilters(selector: string): SelectorPart[] | null;
|
|
57
|
+
/**
|
|
58
|
+
* The parts with every `:visible` filter removed, to count what only
|
|
59
|
+
* visibility excluded.
|
|
60
|
+
*
|
|
61
|
+
* @param parts - Parsed selector parts
|
|
62
|
+
* @returns Parts without `:visible`, or null when they have none
|
|
63
|
+
*/
|
|
64
|
+
export declare function withoutVisibleFilters(parts: SelectorPart[]): SelectorPart[] | null;
|
|
37
65
|
/**
|
|
38
66
|
* Split a selector list at its top-level commas (not inside quotes,
|
|
39
67
|
* attribute brackets or parentheses).
|