browser-debugger-cli 0.12.0 → 0.14.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.
Files changed (224) hide show
  1. package/.claude/skills/bdg/SKILL.md +100 -186
  2. package/README.md +5 -4
  3. package/dist/commands/cdp.d.ts +22 -1
  4. package/dist/commands/cdp.js +100 -43
  5. package/dist/commands/console.d.ts +12 -0
  6. package/dist/commands/console.js +67 -13
  7. package/dist/commands/dom/DomElementResolver.d.ts +3 -1
  8. package/dist/commands/dom/DomElementResolver.js +10 -3
  9. package/dist/commands/dom/a11y.d.ts +1 -1
  10. package/dist/commands/dom/a11y.js +23 -22
  11. package/dist/commands/dom/eval.d.ts +4 -2
  12. package/dist/commands/dom/eval.js +31 -7
  13. package/dist/commands/dom/form.js +10 -9
  14. package/dist/commands/dom/formInteraction.js +9 -8
  15. package/dist/commands/dom/get.js +32 -14
  16. package/dist/commands/dom/helpers/index.d.ts +1 -1
  17. package/dist/commands/dom/helpers/index.js +1 -1
  18. package/dist/commands/dom/helpers/query.d.ts +27 -3
  19. package/dist/commands/dom/helpers/query.js +152 -64
  20. package/dist/commands/dom/helpers/screenshot.js +13 -13
  21. package/dist/commands/dom/index.js +10 -3
  22. package/dist/commands/dom/query.d.ts +20 -2
  23. package/dist/commands/dom/query.js +39 -6
  24. package/dist/commands/dom/screenshot.js +3 -1
  25. package/dist/commands/dom/semanticUtils.d.ts +3 -2
  26. package/dist/commands/dom/semanticUtils.js +40 -9
  27. package/dist/commands/helpJson.d.ts +82 -19
  28. package/dist/commands/helpJson.js +112 -41
  29. package/dist/commands/helpTopic.d.ts +16 -1
  30. package/dist/commands/helpTopic.js +59 -1
  31. package/dist/commands/installSkill.d.ts +15 -5
  32. package/dist/commands/installSkill.js +86 -16
  33. package/dist/commands/network/list.js +65 -12
  34. package/dist/commands/optionBehaviors.d.ts +25 -2
  35. package/dist/commands/optionBehaviors.js +81 -46
  36. package/dist/commands/peek.js +3 -0
  37. package/dist/commands/shared/CommandRunner.js +13 -13
  38. package/dist/commands/shared/daemonErrorHandler.d.ts +5 -2
  39. package/dist/commands/shared/daemonErrorHandler.js +21 -10
  40. package/dist/commands/shared/dataFetcher.d.ts +14 -4
  41. package/dist/commands/shared/dataFetcher.js +20 -4
  42. package/dist/commands/shared/followMode.d.ts +9 -1
  43. package/dist/commands/shared/followMode.js +22 -4
  44. package/dist/commands/shared/handleValidationError.js +3 -3
  45. package/dist/commands/shared/optionTypes.d.ts +17 -3
  46. package/dist/commands/shared/outputFile.js +6 -1
  47. package/dist/commands/shared/startHelpers.js +3 -3
  48. package/dist/commands/start.d.ts +7 -5
  49. package/dist/commands/start.js +65 -21
  50. package/dist/commands/stop.d.ts +11 -0
  51. package/dist/commands/stop.js +24 -1
  52. package/dist/commands.js +1 -1
  53. package/dist/connection/cdp.d.ts +7 -0
  54. package/dist/connection/cdp.js +9 -0
  55. package/dist/connection/chromeIdentity.d.ts +8 -2
  56. package/dist/connection/chromeIdentity.js +85 -13
  57. package/dist/connection/launcher.js +3 -2
  58. package/dist/constants.d.ts +29 -1
  59. package/dist/constants.js +35 -1
  60. package/dist/daemon/SessionController.js +8 -1
  61. package/dist/daemon/launcher.d.ts +3 -2
  62. package/dist/daemon/launcher.js +47 -3
  63. package/dist/daemon/session/Session.d.ts +5 -1
  64. package/dist/daemon/session/Session.js +42 -3
  65. package/dist/daemon/session/TelemetryStore.d.ts +15 -1
  66. package/dist/daemon/session/TelemetryStore.js +19 -1
  67. package/dist/daemon/session/commandRegistry.js +52 -18
  68. package/dist/daemon/session/interactions.d.ts +2 -1
  69. package/dist/daemon/session/interactions.js +13 -1
  70. package/dist/daemon/session/matchedStylesReset.d.ts +26 -0
  71. package/dist/daemon/session/matchedStylesReset.js +46 -0
  72. package/dist/daemon/session/plugins.js +17 -2
  73. package/dist/daemon/session/teardown.js +1 -1
  74. package/dist/daemon/session/triggeredRequests.d.ts +0 -5
  75. package/dist/daemon/session/triggeredRequests.js +13 -7
  76. package/dist/daemon.js +2385 -1229
  77. package/dist/errors/messages.d.ts +62 -11
  78. package/dist/errors/messages.js +119 -22
  79. package/dist/index.js +14995 -9866
  80. package/dist/ipc/client.d.ts +18 -2
  81. package/dist/ipc/client.js +26 -5
  82. package/dist/ipc/protocol/auditTypes.d.ts +8 -2
  83. package/dist/ipc/protocol/commands.d.ts +16 -0
  84. package/dist/ipc/protocol/domTypes.d.ts +12 -0
  85. package/dist/ipc/protocol/inspectTypes.d.ts +7 -2
  86. package/dist/ipc/session/types.d.ts +7 -1
  87. package/dist/program.d.ts +14 -0
  88. package/dist/program.js +53 -0
  89. package/dist/runtime/dom/actionEffects.d.ts +5 -1
  90. package/dist/runtime/dom/actionEffects.js +26 -14
  91. package/dist/runtime/dom/audit.js +3 -2
  92. package/dist/runtime/dom/auditModel.js +6 -1
  93. package/dist/runtime/dom/auditScripts.d.ts +9 -3
  94. package/dist/runtime/dom/auditScripts.js +41 -5
  95. package/dist/runtime/dom/elementGeometry.d.ts +33 -3
  96. package/dist/runtime/dom/elementGeometry.js +44 -19
  97. package/dist/runtime/dom/elementInfo.d.ts +76 -18
  98. package/dist/runtime/dom/elementInfo.js +190 -40
  99. package/dist/runtime/dom/evalHelpers.d.ts +12 -2
  100. package/dist/runtime/dom/evalHelpers.js +67 -7
  101. package/dist/runtime/dom/formDiscovery.d.ts +6 -2
  102. package/dist/runtime/dom/formDiscovery.js +20 -3
  103. package/dist/runtime/dom/formFillHelpers/fill.js +7 -11
  104. package/dist/runtime/dom/formFillHelpers/pressKey.js +2 -2
  105. package/dist/runtime/dom/formFillHelpers/shared.d.ts +16 -10
  106. package/dist/runtime/dom/formFillHelpers/shared.js +19 -52
  107. package/dist/runtime/dom/formSubmitHelpers.js +4 -3
  108. package/dist/runtime/dom/frameLayout.js +1 -0
  109. package/dist/runtime/dom/frameScopedConnection.d.ts +7 -0
  110. package/dist/runtime/dom/frameScopedConnection.js +2 -2
  111. package/dist/runtime/dom/inspect.d.ts +17 -3
  112. package/dist/runtime/dom/inspect.js +45 -32
  113. package/dist/runtime/dom/inspectAllStyles.js +1 -0
  114. package/dist/runtime/dom/inspectHints.d.ts +1 -1
  115. package/dist/runtime/dom/inspectModel.d.ts +5 -4
  116. package/dist/runtime/dom/inspectModel.js +7 -3
  117. package/dist/runtime/dom/inspectPaintModel.d.ts +2 -0
  118. package/dist/runtime/dom/inspectPaintModel.js +3 -1
  119. package/dist/runtime/dom/inspectRules.d.ts +29 -3
  120. package/dist/runtime/dom/inspectRules.js +205 -11
  121. package/dist/runtime/dom/inspectScripts.d.ts +29 -2
  122. package/dist/runtime/dom/inspectScripts.js +49 -10
  123. package/dist/runtime/dom/layout.d.ts +0 -2
  124. package/dist/runtime/dom/layout.js +10 -9
  125. package/dist/runtime/dom/reactEventHelpers.d.ts +17 -4
  126. package/dist/runtime/dom/reactEventHelpers.js +71 -28
  127. package/dist/runtime/dom/targetNode.d.ts +27 -10
  128. package/dist/runtime/dom/targetNode.js +283 -16
  129. package/dist/runtime/dom/wait.js +2 -1
  130. package/dist/runtime/page/bdgWorld.d.ts +57 -0
  131. package/dist/runtime/page/bdgWorld.js +180 -0
  132. package/dist/runtime/page/replacedBuiltins.d.ts +28 -0
  133. package/dist/runtime/page/replacedBuiltins.js +136 -0
  134. package/dist/session/QueryCacheManager.d.ts +4 -1
  135. package/dist/session/QueryCacheManager.js +5 -2
  136. package/dist/session/chrome.d.ts +4 -1
  137. package/dist/session/chrome.js +7 -1
  138. package/dist/session/cleanup/staleSession.d.ts +21 -4
  139. package/dist/session/cleanup/staleSession.js +79 -9
  140. package/dist/session/cleanup/userCommands.d.ts +4 -1
  141. package/dist/session/cleanup/userCommands.js +10 -5
  142. package/dist/session/daemonSocket.d.ts +10 -0
  143. package/dist/session/daemonSocket.js +22 -0
  144. package/dist/session/lastSession.d.ts +6 -3
  145. package/dist/session/lastSession.js +11 -5
  146. package/dist/session/paths.d.ts +3 -1
  147. package/dist/session/paths.js +5 -5
  148. package/dist/session/portClaims.js +4 -3
  149. package/dist/session/sessionList.d.ts +13 -5
  150. package/dist/session/sessionList.js +31 -7
  151. package/dist/telemetry/a11y.d.ts +15 -1
  152. package/dist/telemetry/a11y.js +85 -2
  153. package/dist/telemetry/console.d.ts +2 -1
  154. package/dist/telemetry/console.js +30 -21
  155. package/dist/telemetry/har/builder.js +1 -1
  156. package/dist/telemetry/network.d.ts +13 -16
  157. package/dist/telemetry/network.js +30 -52
  158. package/dist/telemetry/networkRetention.d.ts +83 -0
  159. package/dist/telemetry/networkRetention.js +117 -0
  160. package/dist/telemetry/pageCrash.d.ts +26 -0
  161. package/dist/telemetry/pageCrash.js +53 -0
  162. package/dist/types.d.ts +42 -0
  163. package/dist/ui/OutputBuilder.d.ts +10 -0
  164. package/dist/ui/OutputBuilder.js +12 -0
  165. package/dist/ui/formatters/a11y.d.ts +5 -7
  166. package/dist/ui/formatters/a11y.js +7 -61
  167. package/dist/ui/formatters/audit.js +14 -5
  168. package/dist/ui/formatters/cdp.d.ts +138 -0
  169. package/dist/ui/formatters/cdp.js +131 -0
  170. package/dist/ui/formatters/console/chronological.js +7 -5
  171. package/dist/ui/formatters/console/follow.d.ts +5 -2
  172. package/dist/ui/formatters/console/follow.js +7 -4
  173. package/dist/ui/formatters/console/json.d.ts +4 -7
  174. package/dist/ui/formatters/console/json.js +16 -14
  175. package/dist/ui/formatters/console/shared.d.ts +47 -2
  176. package/dist/ui/formatters/console/shared.js +33 -0
  177. package/dist/ui/formatters/console/summarize.d.ts +9 -2
  178. package/dist/ui/formatters/console/summarize.js +57 -11
  179. package/dist/ui/formatters/console.d.ts +3 -2
  180. package/dist/ui/formatters/console.js +8 -10
  181. package/dist/ui/formatters/details.js +4 -2
  182. package/dist/ui/formatters/dom.d.ts +14 -5
  183. package/dist/ui/formatters/dom.js +30 -13
  184. package/dist/ui/formatters/helpFormatters.js +1 -1
  185. package/dist/ui/formatters/inspect.js +9 -3
  186. package/dist/ui/formatters/installSkill.d.ts +9 -1
  187. package/dist/ui/formatters/installSkill.js +32 -6
  188. package/dist/ui/formatters/layout.js +4 -2
  189. package/dist/ui/formatters/longValues.d.ts +14 -0
  190. package/dist/ui/formatters/longValues.js +23 -0
  191. package/dist/ui/formatters/networkList.d.ts +8 -2
  192. package/dist/ui/formatters/networkList.js +11 -3
  193. package/dist/ui/formatters/preview.d.ts +6 -1
  194. package/dist/ui/formatters/preview.js +67 -15
  195. package/dist/ui/formatters/sessions.d.ts +2 -2
  196. package/dist/ui/formatters/sessions.js +9 -2
  197. package/dist/ui/formatters/status.js +7 -0
  198. package/dist/ui/formatters/triggeredRequests.js +2 -1
  199. package/dist/ui/logging/logger.d.ts +1 -1
  200. package/dist/ui/messages/chrome.d.ts +20 -1
  201. package/dist/ui/messages/chrome.js +29 -3
  202. package/dist/ui/messages/commands.d.ts +153 -12
  203. package/dist/ui/messages/commands.js +198 -15
  204. package/dist/ui/messages/consoleMessages.d.ts +24 -0
  205. package/dist/ui/messages/consoleMessages.js +32 -0
  206. package/dist/ui/messages/networkMessages.d.ts +24 -0
  207. package/dist/ui/messages/networkMessages.js +45 -0
  208. package/dist/ui/messages/preview.d.ts +6 -0
  209. package/dist/ui/messages/preview.js +9 -1
  210. package/dist/ui/messages/session.d.ts +13 -2
  211. package/dist/ui/messages/session.js +22 -3
  212. package/dist/utils/directories.d.ts +34 -0
  213. package/dist/utils/directories.js +88 -0
  214. package/dist/utils/display.d.ts +16 -0
  215. package/dist/utils/display.js +42 -0
  216. package/dist/utils/exitCodes.d.ts +1 -0
  217. package/dist/utils/exitCodes.js +6 -0
  218. package/dist/utils/http.d.ts +9 -2
  219. package/dist/utils/http.js +4 -3
  220. package/dist/utils/process.d.ts +12 -0
  221. package/dist/utils/process.js +25 -0
  222. package/dist/utils/strings.d.ts +19 -0
  223. package/dist/utils/strings.js +16 -0
  224. package/package.json +2 -2
@@ -258,6 +258,21 @@ export declare function invalidSelectorFilterError(selector: string, filter: str
258
258
  * @param closest - Most similar existing command path, if any
259
259
  */
260
260
  export declare function unknownHelpTopicError(topic: string, closest?: string): ErrorWithSuggestion;
261
+ /**
262
+ * Suggestion for a command-line usage error (missing argument, invalid value,
263
+ * unknown option without a close match).
264
+ *
265
+ * @param path - Command path, e.g. "bdg dom query"
266
+ */
267
+ export declare function usageHelpSuggestion(path: string): string;
268
+ /**
269
+ * A command group was run without one of its subcommands.
270
+ */
271
+ export declare function missingSubcommandMessage(): string;
272
+ /**
273
+ * `bdg cdp --search` with an empty or blank query (which would match every method).
274
+ */
275
+ export declare function emptyCdpSearchError(): ErrorWithSuggestion;
261
276
  /**
262
277
  * Chrome rejected a CDP method or its parameters.
263
278
  *
@@ -442,15 +457,22 @@ export declare function conflictingTargetError(option: string, positional: strin
442
457
  *
443
458
  * @param first - First option
444
459
  * @param second - Option it conflicts with
445
- * @returns Message
460
+ * @returns Message and suggestion
446
461
  */
447
- export declare function conflictingOptionsMessage(first: string, second: string): string;
462
+ export declare function conflictingOptionsError(first: string, second: string): ErrorWithSuggestion;
448
463
  /**
449
464
  * A Chrome flag bdg cannot pass on.
450
465
  *
451
466
  * @param flag - The flag
452
467
  */
453
468
  export declare function invalidChromeFlagError(flag: string): ErrorWithSuggestion;
469
+ /**
470
+ * A page command on a page whose renderer crashed.
471
+ *
472
+ * @param crashedAt - When it crashed (epoch ms)
473
+ * @returns Message and the way back
474
+ */
475
+ export declare function pageCrashedError(crashedAt: number): ErrorWithSuggestion;
454
476
  /**
455
477
  * The session (its browser or daemon) went away while a command was running.
456
478
  */
@@ -460,13 +482,21 @@ export declare function sessionEndedDuringCommandError(): ErrorWithSuggestion;
460
482
  *
461
483
  * @param option - Option given
462
484
  * @param required - Option it needs
463
- * @returns Message
485
+ * @returns Message and suggestion
464
486
  */
465
- export declare function optionRequiresMessage(option: string, required: string): string;
487
+ export declare function optionRequiresError(option: string, required: string): ErrorWithSuggestion;
466
488
  /**
467
489
  * `bdg page navigate javascript:…`: scripts run with dom eval.
468
490
  */
469
491
  export declare function javascriptNavigationError(): ErrorWithSuggestion;
492
+ /**
493
+ * A daemon request named a command the session does not have (the IPC
494
+ * server validates names, so this guards direct callers).
495
+ *
496
+ * @param name - Requested command name
497
+ * @returns Error message
498
+ */
499
+ export declare function unknownSessionCommandMessage(name: string): string;
470
500
  /**
471
501
  * A bare word given where a URL is expected, most likely a mistyped command.
472
502
  *
@@ -556,9 +586,10 @@ export declare function staleNodeError(index?: number, source?: IndexSource): Er
556
586
  *
557
587
  * @param source - The index and the list it refers to
558
588
  * @param count - Number of cached results
589
+ * @param total - Matches the query found, when more than it cached (`dom query` caches the first 1000)
559
590
  * @returns Message and suggestion
560
591
  */
561
- export declare function cachedIndexOutOfRangeError(source: IndexSource, count: number): ErrorWithSuggestion;
592
+ export declare function cachedIndexOutOfRangeError(source: IndexSource, count: number, total?: number): ErrorWithSuggestion;
562
593
  /**
563
594
  * Note for a form command (fill, submit) whose index refers to results of
564
595
  * another command and hit an element it cannot act on.
@@ -785,14 +816,32 @@ export declare const FILL_REFUSALS: {
785
816
  readonly suggestion: "Only input, textarea, select, and contenteditable elements can be filled";
786
817
  };
787
818
  };
788
- /**
789
- * Clickable element not found.
790
- */
791
- export declare function clickableElementNotFoundError(selector: string): ErrorWithSuggestion;
792
819
  /**
793
820
  * Click target disappeared between locating and clicking it.
794
821
  */
795
822
  export declare function clickTargetDetachedError(selector: string): ErrorWithSuggestion;
823
+ /**
824
+ * An action's page script threw (on a page whose built-ins all look like the
825
+ * browser's).
826
+ *
827
+ * @param action - The action, e.g. `fill`
828
+ * @param exception - What the script threw, e.g. `TypeError: x is not a function`
829
+ * @param selector - Selector the action was for
830
+ * @returns Error naming the exception
831
+ */
832
+ export declare function actionScriptFailedError(action: string, exception: string, selector: string): ErrorWithSuggestion;
833
+ /**
834
+ * An action's page script threw on a page that replaced built-ins it uses
835
+ * (anti-bot scripts make `getBoundingClientRect`, `focus` or
836
+ * `dispatchEvent` throw; old libraries such as MooTools 1.2 replace
837
+ * `Event`). All replaced built-ins are named.
838
+ *
839
+ * @param action - The action, e.g. `fill`
840
+ * @param exception - What the script threw, e.g. `Error: anti-bot: focus`
841
+ * @param replaced - Dotted names of the replaced built-ins
842
+ * @returns Error naming the replaced built-ins and the exception
843
+ */
844
+ export declare function actionBrokenByPageError(action: string, exception: string, replaced: readonly string[]): ErrorWithSuggestion;
796
845
  /**
797
846
  * A pointer action refused under `--strict` because a real mouse could not
798
847
  * reach the element (covered, hidden, zero-size, pointer-events: none).
@@ -999,11 +1048,13 @@ export declare function skillSourceMissingError(source: string): ErrorWithSugges
999
1048
  /**
1000
1049
  * The skill could not be written to an agent's skill directory.
1001
1050
  *
1002
- * @param path - Destination SKILL.md
1051
+ * @param path - File that could not be written
1003
1052
  * @param reason - The file system error
1053
+ * @param pathIsFile - Whether a part of the path is a file (ENOTDIR, EEXIST)
1054
+ * @param otherTargetFlag - Flag installing for the other agent only, when both were picked
1004
1055
  * @returns Message and suggestion
1005
1056
  */
1006
- export declare function skillWriteFailedError(path: string, reason: string): ErrorWithSuggestion;
1057
+ export declare function skillWriteFailedError(path: string, reason: string, pathIsFile: boolean, otherTargetFlag?: string): ErrorWithSuggestion;
1007
1058
  /**
1008
1059
  * `bdg peek --interval` without `--follow`.
1009
1060
  *
@@ -370,6 +370,30 @@ export function unknownHelpTopicError(topic, closest) {
370
370
  : `Run "bdg ${parent ? `${parent} ` : ''}--help" for commands`,
371
371
  };
372
372
  }
373
+ /**
374
+ * Suggestion for a command-line usage error (missing argument, invalid value,
375
+ * unknown option without a close match).
376
+ *
377
+ * @param path - Command path, e.g. "bdg dom query"
378
+ */
379
+ export function usageHelpSuggestion(path) {
380
+ return `Run "${path} --help" for usage`;
381
+ }
382
+ /**
383
+ * A command group was run without one of its subcommands.
384
+ */
385
+ export function missingSubcommandMessage() {
386
+ return 'Missing subcommand';
387
+ }
388
+ /**
389
+ * `bdg cdp --search` with an empty or blank query (which would match every method).
390
+ */
391
+ export function emptyCdpSearchError() {
392
+ return {
393
+ message: 'Empty search query',
394
+ suggestion: 'Search for a keyword, e.g. bdg cdp --search cookie; list domains: bdg cdp --list',
395
+ };
396
+ }
373
397
  /**
374
398
  * Chrome rejected a CDP method or its parameters.
375
399
  *
@@ -687,10 +711,13 @@ export function conflictingTargetError(option, positional) {
687
711
  *
688
712
  * @param first - First option
689
713
  * @param second - Option it conflicts with
690
- * @returns Message
714
+ * @returns Message and suggestion
691
715
  */
692
- export function conflictingOptionsMessage(first, second) {
693
- return `${first} cannot be combined with ${second}; use one of them`;
716
+ export function conflictingOptionsError(first, second) {
717
+ return {
718
+ message: `${first} cannot be combined with ${second}`,
719
+ suggestion: `Use one of them: drop ${first} or ${second}`,
720
+ };
694
721
  }
695
722
  /**
696
723
  * A Chrome flag bdg cannot pass on.
@@ -708,6 +735,18 @@ export function invalidChromeFlagError(flag) {
708
735
  suggestion: 'Give Chrome flags as one quoted value: --chrome-flags="--lang=pl --disable-gpu"',
709
736
  };
710
737
  }
738
+ /**
739
+ * A page command on a page whose renderer crashed.
740
+ *
741
+ * @param crashedAt - When it crashed (epoch ms)
742
+ * @returns Message and the way back
743
+ */
744
+ export function pageCrashedError(crashedAt) {
745
+ return {
746
+ message: `The page crashed at ${new Date(crashedAt).toLocaleTimeString()} (its renderer is gone), so page commands cannot run`,
747
+ suggestion: `Load it again with: ${sessionCommand('bdg page reload')} (or start a new session: ${sessionCommand('bdg <url>')})`,
748
+ };
749
+ }
711
750
  /**
712
751
  * The session (its browser or daemon) went away while a command was running.
713
752
  */
@@ -722,10 +761,13 @@ export function sessionEndedDuringCommandError() {
722
761
  *
723
762
  * @param option - Option given
724
763
  * @param required - Option it needs
725
- * @returns Message
764
+ * @returns Message and suggestion
726
765
  */
727
- export function optionRequiresMessage(option, required) {
728
- return `${option} only works with ${required}; add ${required} or drop ${option}`;
766
+ export function optionRequiresError(option, required) {
767
+ return {
768
+ message: `${option} only works with ${required}`,
769
+ suggestion: `Add ${required}, or drop ${option}`,
770
+ };
729
771
  }
730
772
  /**
731
773
  * `bdg page navigate javascript:…`: scripts run with dom eval.
@@ -736,6 +778,16 @@ export function javascriptNavigationError() {
736
778
  suggestion: `Run the script in the page instead: bdg dom eval '...'`,
737
779
  };
738
780
  }
781
+ /**
782
+ * A daemon request named a command the session does not have (the IPC
783
+ * server validates names, so this guards direct callers).
784
+ *
785
+ * @param name - Requested command name
786
+ * @returns Error message
787
+ */
788
+ export function unknownSessionCommandMessage(name) {
789
+ return `Unknown session command: "${name}"`;
790
+ }
739
791
  /**
740
792
  * A bare word given where a URL is expected, most likely a mistyped command.
741
793
  *
@@ -935,15 +987,24 @@ export function staleNodeError(index, source) {
935
987
  *
936
988
  * @param source - The index and the list it refers to
937
989
  * @param count - Number of cached results
990
+ * @param total - Matches the query found, when more than it cached (`dom query` caches the first 1000)
938
991
  * @returns Message and suggestion
939
992
  */
940
- export function cachedIndexOutOfRangeError(source, count) {
941
- const results = count === 1 ? '1 result' : `${count} results`;
993
+ export function cachedIndexOutOfRangeError(source, count, total) {
994
+ if (total !== undefined && total > count && source.index < total) {
995
+ return {
996
+ message: `Index ${source.index} is past the ${count} matches of ${cachedListText(source)} that can be used by index (${total} in all)`,
997
+ suggestion: `Re-run it with --limit ${source.index + 1} (or --limit 0) to index that many`,
998
+ };
999
+ }
1000
+ const all = total !== undefined && total > count ? total : count;
1001
+ const results = all === 1 ? '1 result' : `${all} results`;
1002
+ const range = all > count
1003
+ ? `between 0 and ${count - 1}, or up to ${all - 1} after re-running it with --limit 0`
1004
+ : `between 0 and ${count - 1}, or re-run "${refreshCommand(source)}"`;
942
1005
  return {
943
1006
  message: `Index ${source.index} is out of range for ${cachedListText(source)} (${results})`,
944
- suggestion: count > 0
945
- ? `Use an index between 0 and ${count - 1}, or re-run "${refreshCommand(source)}"`
946
- : `Re-run "${refreshCommand(source)}"`,
1007
+ suggestion: count > 0 ? `Use an index ${range}` : `Re-run "${refreshCommand(source)}"`,
947
1008
  };
948
1009
  }
949
1010
  /**
@@ -1349,21 +1410,50 @@ export const FILL_REFUSALS = {
1349
1410
  },
1350
1411
  };
1351
1412
  /**
1352
- * Clickable element not found.
1413
+ * Click target disappeared between locating and clicking it.
1353
1414
  */
1354
- export function clickableElementNotFoundError(selector) {
1415
+ export function clickTargetDetachedError(selector) {
1355
1416
  return {
1356
- message: `Element not found: ${selector}`,
1357
- suggestion: 'Verify the selector matches a clickable element',
1417
+ message: `Element was removed before it could be clicked: ${selector}`,
1418
+ suggestion: 'The page changed during the click; wait for it to settle and retry',
1358
1419
  };
1359
1420
  }
1360
1421
  /**
1361
- * Click target disappeared between locating and clicking it.
1422
+ * An action's page script threw (on a page whose built-ins all look like the
1423
+ * browser's).
1424
+ *
1425
+ * @param action - The action, e.g. `fill`
1426
+ * @param exception - What the script threw, e.g. `TypeError: x is not a function`
1427
+ * @param selector - Selector the action was for
1428
+ * @returns Error naming the exception
1362
1429
  */
1363
- export function clickTargetDetachedError(selector) {
1430
+ export function actionScriptFailedError(action, exception, selector) {
1431
+ const damage = detectSelectorQuoteDamage(selector);
1364
1432
  return {
1365
- message: `Element was removed before it could be clicked: ${selector}`,
1366
- suggestion: 'The page changed during the click; wait for it to settle and retry',
1433
+ message: `The ${action} script failed in the page: ${exception}`,
1434
+ suggestion: damage.damaged
1435
+ ? `The selector looks damaged by shell quoting${damage.details ? ` (${damage.details})` : ''}; query it first with ${sessionCommand(`bdg dom query ${JSON.stringify(selector)}`)}, then act on the index`
1436
+ : `Check the element with ${sessionCommand(`bdg dom get ${JSON.stringify(selector)}`)}, or act on it with ${sessionCommand("bdg dom eval '…'")}`,
1437
+ };
1438
+ }
1439
+ /**
1440
+ * An action's page script threw on a page that replaced built-ins it uses
1441
+ * (anti-bot scripts make `getBoundingClientRect`, `focus` or
1442
+ * `dispatchEvent` throw; old libraries such as MooTools 1.2 replace
1443
+ * `Event`). All replaced built-ins are named.
1444
+ *
1445
+ * @param action - The action, e.g. `fill`
1446
+ * @param exception - What the script threw, e.g. `Error: anti-bot: focus`
1447
+ * @param replaced - Dotted names of the replaced built-ins
1448
+ * @returns Error naming the replaced built-ins and the exception
1449
+ */
1450
+ export function actionBrokenByPageError(action, exception, replaced) {
1451
+ const fill = action === 'fill'
1452
+ ? ' The field may already hold the value without the page having seen input or change events.'
1453
+ : '';
1454
+ return {
1455
+ message: `The page replaced built-ins bdg's ${action} script uses (${replaced.join(', ')}), and the script failed: ${exception}`,
1456
+ suggestion: `The page blocks or changes these APIs (an anti-bot script or an old library).${fill} If the page still lets scripts act, use ${sessionCommand("bdg dom eval '…'")}`,
1367
1457
  };
1368
1458
  }
1369
1459
  /**
@@ -1808,14 +1898,21 @@ export function skillSourceMissingError(source) {
1808
1898
  /**
1809
1899
  * The skill could not be written to an agent's skill directory.
1810
1900
  *
1811
- * @param path - Destination SKILL.md
1901
+ * @param path - File that could not be written
1812
1902
  * @param reason - The file system error
1903
+ * @param pathIsFile - Whether a part of the path is a file (ENOTDIR, EEXIST)
1904
+ * @param otherTargetFlag - Flag installing for the other agent only, when both were picked
1813
1905
  * @returns Message and suggestion
1814
1906
  */
1815
- export function skillWriteFailedError(path, reason) {
1907
+ export function skillWriteFailedError(path, reason, pathIsFile, otherTargetFlag) {
1908
+ const fix = pathIsFile
1909
+ ? 'A part of that path is a file, not a directory: move it away'
1910
+ : 'Check the permissions of that directory';
1816
1911
  return {
1817
1912
  message: `Could not write ${path}: ${reason}`,
1818
- suggestion: 'Check the permissions of that directory, or install for the other agent only (--claude or --agents)',
1913
+ suggestion: otherTargetFlag
1914
+ ? `${fix}, or install for the other agent only (${otherTargetFlag})`
1915
+ : fix,
1819
1916
  };
1820
1917
  }
1821
1918
  /**