browser-debugger-cli 0.9.0 → 0.10.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 (133) hide show
  1. package/README.md +4 -1
  2. package/dist/commands/dom/a11y.js +2 -1
  3. package/dist/commands/dom/formInteraction.js +56 -25
  4. package/dist/commands/dom/helpers/keyAttributes.d.ts +20 -0
  5. package/dist/commands/dom/helpers/keyAttributes.js +54 -0
  6. package/dist/commands/dom/helpers/query.d.ts +1 -1
  7. package/dist/commands/dom/helpers/query.js +66 -19
  8. package/dist/commands/dom/helpers/runElementCommand.js +4 -3
  9. package/dist/commands/dom/helpers/screenshot.js +85 -12
  10. package/dist/commands/dom/index.d.ts +1 -0
  11. package/dist/commands/dom/index.js +8 -3
  12. package/dist/commands/dom/inspect.d.ts +15 -0
  13. package/dist/commands/dom/inspect.js +82 -0
  14. package/dist/commands/dom/layout.js +2 -2
  15. package/dist/commands/dom/listeners.js +2 -2
  16. package/dist/commands/dom/semanticUtils.d.ts +14 -1
  17. package/dist/commands/dom/semanticUtils.js +44 -3
  18. package/dist/commands/network/list.js +13 -2
  19. package/dist/commands/optionBehaviors.js +48 -6
  20. package/dist/commands/page.d.ts +1 -1
  21. package/dist/commands/page.js +62 -3
  22. package/dist/commands/shared/commonOptions.d.ts +4 -0
  23. package/dist/commands/shared/commonOptions.js +9 -0
  24. package/dist/commands/shared/optionTypes.d.ts +21 -0
  25. package/dist/commands/shared/startHelpers.d.ts +66 -0
  26. package/dist/commands/shared/startHelpers.js +91 -10
  27. package/dist/commands/shared/validation.d.ts +11 -0
  28. package/dist/commands/shared/validation.js +16 -0
  29. package/dist/daemon/launcher.d.ts +8 -1
  30. package/dist/daemon/launcher.js +3 -1
  31. package/dist/daemon/session/Session.d.ts +7 -0
  32. package/dist/daemon/session/Session.js +23 -1
  33. package/dist/daemon/session/commandRegistry.d.ts +14 -1
  34. package/dist/daemon/session/commandRegistry.js +65 -9
  35. package/dist/daemon/session/interactions.d.ts +18 -5
  36. package/dist/daemon/session/interactions.js +22 -12
  37. package/dist/daemon.js +3565 -329
  38. package/dist/errors/messages.d.ts +69 -0
  39. package/dist/errors/messages.js +102 -1
  40. package/dist/index.js +2416 -1320
  41. package/dist/ipc/client.d.ts +9 -0
  42. package/dist/ipc/client.js +13 -0
  43. package/dist/ipc/protocol/commands.d.ts +56 -1
  44. package/dist/ipc/protocol/commands.js +2 -0
  45. package/dist/ipc/protocol/domTypes.d.ts +35 -2
  46. package/dist/ipc/protocol/inspectTypes.d.ts +388 -0
  47. package/dist/ipc/protocol/inspectTypes.js +10 -0
  48. package/dist/runtime/dom/actionEffects.d.ts +94 -15
  49. package/dist/runtime/dom/actionEffects.js +173 -27
  50. package/dist/runtime/dom/actionEffectsScripts.d.ts +52 -14
  51. package/dist/runtime/dom/actionEffectsScripts.js +224 -32
  52. package/dist/runtime/dom/elementInfo.d.ts +26 -0
  53. package/dist/runtime/dom/elementInfo.js +65 -0
  54. package/dist/runtime/dom/eventListeners.js +14 -4
  55. package/dist/runtime/dom/formFillHelpers/fill.d.ts +3 -4
  56. package/dist/runtime/dom/formFillHelpers/fill.js +77 -28
  57. package/dist/runtime/dom/frameSelection.d.ts +11 -0
  58. package/dist/runtime/dom/frameSelection.js +20 -1
  59. package/dist/runtime/dom/frames.d.ts +38 -5
  60. package/dist/runtime/dom/frames.js +136 -21
  61. package/dist/runtime/dom/inspect.d.ts +28 -0
  62. package/dist/runtime/dom/inspect.js +557 -0
  63. package/dist/runtime/dom/inspectAllStyles.d.ts +62 -0
  64. package/dist/runtime/dom/inspectAllStyles.js +385 -0
  65. package/dist/runtime/dom/inspectCascade.d.ts +94 -0
  66. package/dist/runtime/dom/inspectCascade.js +371 -0
  67. package/dist/runtime/dom/inspectCascadeModel.d.ts +39 -0
  68. package/dist/runtime/dom/inspectCascadeModel.js +232 -0
  69. package/dist/runtime/dom/inspectHints.d.ts +62 -0
  70. package/dist/runtime/dom/inspectHints.js +305 -0
  71. package/dist/runtime/dom/inspectLayoutModel.d.ts +87 -0
  72. package/dist/runtime/dom/inspectLayoutModel.js +346 -0
  73. package/dist/runtime/dom/inspectModel.d.ts +74 -0
  74. package/dist/runtime/dom/inspectModel.js +184 -0
  75. package/dist/runtime/dom/inspectPaintModel.d.ts +157 -0
  76. package/dist/runtime/dom/inspectPaintModel.js +461 -0
  77. package/dist/runtime/dom/inspectRules.d.ts +37 -0
  78. package/dist/runtime/dom/inspectRules.js +101 -0
  79. package/dist/runtime/dom/inspectScripts.d.ts +132 -0
  80. package/dist/runtime/dom/inspectScripts.js +263 -0
  81. package/dist/runtime/dom/inspectTree.d.ts +40 -0
  82. package/dist/runtime/dom/inspectTree.js +134 -0
  83. package/dist/runtime/dom/inspectVariables.d.ts +33 -0
  84. package/dist/runtime/dom/inspectVariables.js +94 -0
  85. package/dist/runtime/dom/inspectWhyModel.d.ts +20 -0
  86. package/dist/runtime/dom/inspectWhyModel.js +134 -0
  87. package/dist/runtime/dom/layout.d.ts +5 -1
  88. package/dist/runtime/dom/layout.js +10 -3
  89. package/dist/runtime/dom/listenerPageScripts.d.ts +11 -5
  90. package/dist/runtime/dom/listenerPageScripts.js +95 -9
  91. package/dist/runtime/dom/listenerSummary.d.ts +4 -0
  92. package/dist/runtime/dom/listenerSummary.js +26 -9
  93. package/dist/runtime/dom/reactEventHelpers.d.ts +5 -0
  94. package/dist/runtime/dom/reactEventHelpers.js +12 -4
  95. package/dist/runtime/page/emulation.d.ts +20 -0
  96. package/dist/runtime/page/emulation.js +37 -0
  97. package/dist/telemetry/a11y.d.ts +10 -0
  98. package/dist/telemetry/a11y.js +78 -1
  99. package/dist/telemetry/console.d.ts +1 -0
  100. package/dist/telemetry/console.js +100 -5
  101. package/dist/telemetry/network.js +3 -1
  102. package/dist/types.d.ts +32 -0
  103. package/dist/ui/formatters/details.d.ts +8 -0
  104. package/dist/ui/formatters/details.js +59 -3
  105. package/dist/ui/formatters/dom.d.ts +2 -1
  106. package/dist/ui/formatters/dom.js +25 -9
  107. package/dist/ui/formatters/inspect.d.ts +39 -0
  108. package/dist/ui/formatters/inspect.js +596 -0
  109. package/dist/ui/formatters/keyAttributes.d.ts +19 -0
  110. package/dist/ui/formatters/keyAttributes.js +84 -0
  111. package/dist/ui/formatters/layout.js +2 -2
  112. package/dist/ui/formatters/networkHeaders.d.ts +13 -0
  113. package/dist/ui/formatters/networkHeaders.js +23 -3
  114. package/dist/ui/formatters/networkList.d.ts +29 -1
  115. package/dist/ui/formatters/networkList.js +86 -20
  116. package/dist/ui/formatters/status.js +1 -1
  117. package/dist/ui/formatting.d.ts +9 -0
  118. package/dist/ui/formatting.js +6 -3
  119. package/dist/ui/messages/commands.d.ts +123 -7
  120. package/dist/ui/messages/commands.js +181 -10
  121. package/dist/ui/messages/networkMessages.d.ts +14 -0
  122. package/dist/ui/messages/networkMessages.js +18 -0
  123. package/dist/ui/messages/session.d.ts +14 -0
  124. package/dist/ui/messages/session.js +20 -0
  125. package/dist/utils/async.d.ts +9 -0
  126. package/dist/utils/async.js +17 -0
  127. package/dist/utils/color.d.ts +84 -0
  128. package/dist/utils/color.js +376 -0
  129. package/dist/utils/cssValues.d.ts +109 -0
  130. package/dist/utils/cssValues.js +236 -0
  131. package/dist/utils/selectorFilters.d.ts +12 -0
  132. package/dist/utils/selectorFilters.js +29 -0
  133. package/package.json +1 -1
@@ -595,6 +595,17 @@ export declare function unreachableElementsNote(selector: string, unsearched?: U
595
595
  * @returns e.g. `Did you mean #remove-backpack? (similar id on the page)`; empty without names
596
596
  */
597
597
  export declare function similarSelectorsLine(kind: 'id' | 'class', names: string[]): string;
598
+ /**
599
+ * A selector that would have to cross into a shadow root: selectors cannot,
600
+ * but bdg searches open shadow roots on its own.
601
+ *
602
+ * @param host - The compound matching the host, and the selector after it
603
+ * @returns e.g. `mdn-search-modal hosts a shadow root, which a selector cannot cross into; bdg searches open shadow roots itself: use "form"`
604
+ */
605
+ export declare function shadowBoundaryLine(host: {
606
+ compound: string;
607
+ rest: string;
608
+ }): string;
598
609
  /** What the page says about a selector that matched nothing */
599
610
  export interface NoMatchContext {
600
611
  /** Elements only its `:visible` filters excluded */
@@ -605,6 +616,11 @@ export interface NoMatchContext {
605
616
  unsearched?: UnsearchedContent;
606
617
  /** "Did you mean" line for a single id or class ({@link similarSelectorsLine}) */
607
618
  similar?: string;
619
+ /** A leading compound that matches a shadow host, and the selector after it */
620
+ shadowHost?: {
621
+ compound: string;
622
+ rest: string;
623
+ };
608
624
  }
609
625
  /**
610
626
  * No nodes found for selector.
@@ -768,6 +784,33 @@ export declare function clickableElementNotFoundError(selector: string): ErrorWi
768
784
  * Click target disappeared between locating and clicking it.
769
785
  */
770
786
  export declare function clickTargetDetachedError(selector: string): ErrorWithSuggestion;
787
+ /**
788
+ * A pointer action refused under `--strict` because a real mouse could not
789
+ * reach the element (covered, hidden, zero-size, pointer-events: none).
790
+ *
791
+ * @param target - Selector and element description, as the click located it
792
+ * @param reason - Why the mouse could not reach it, e.g. "covered by another element (div#shield)"
793
+ * @param verb - What was refused, e.g. "click", "hover"
794
+ * @returns Message naming the obstruction, and how to inspect it
795
+ */
796
+ export declare function unreachableElementError(target: {
797
+ selector: string;
798
+ element?: string | undefined;
799
+ }, reason: string | null | undefined, verb: string): ErrorWithSuggestion;
800
+ /**
801
+ * A mouse press refused under `--strict` because it did not reach the
802
+ * element: it was sent, but landed on another element, or the page never
803
+ * saw it (a browser dialog or bubble captured the input).
804
+ *
805
+ * @param target - Selector and element description, as the click located it
806
+ * @param verb - What was refused, e.g. "click"
807
+ * @param landedOn - The element the press landed on, when the page saw it
808
+ * @returns Message, and how to inspect the page
809
+ */
810
+ export declare function pressNotReceivedError(target: {
811
+ selector: string;
812
+ element?: string | undefined;
813
+ }, verb: string, landedOn?: string): ErrorWithSuggestion;
771
814
  /**
772
815
  * Key press failed.
773
816
  */
@@ -815,6 +858,13 @@ export declare function emptyFrameError(): ErrorWithSuggestion;
815
858
  * @param frames - Frames of the page
816
859
  */
817
860
  export declare function frameNotFoundError(query: string, frames: DomFrame[]): ErrorWithSuggestion;
861
+ /**
862
+ * A `dom eval --frame` index that names another frame (or none) than when
863
+ * `bdg dom frames` listed it.
864
+ *
865
+ * @param index - Requested index
866
+ */
867
+ export declare function staleFrameIndexError(index: number): ErrorWithSuggestion;
818
868
  /**
819
869
  * `dom eval --frame` matching more than one iframe.
820
870
  *
@@ -876,6 +926,14 @@ export declare function unexpectedResponseFormatError(context: string): ErrorWit
876
926
  * Generic operation failure with dynamic error message.
877
927
  */
878
928
  export declare function operationFailedError(operation: string, errorMessage: string): ErrorWithSuggestion;
929
+ /**
930
+ * `dom inspect --props` named a property the element has no value for.
931
+ *
932
+ * @param names - Unknown property names
933
+ * @param suggestions - Similar computed property names
934
+ * @returns Message and suggestion
935
+ */
936
+ export declare function unknownCssPropertyError(names: string[], suggestions: string[]): ErrorWithSuggestion;
879
937
  /**
880
938
  * The browser does not offer `DOMDebugger.getEventListeners` (non-Chrome
881
939
  * targets, or browsers that disable the DOMDebugger domain).
@@ -904,5 +962,16 @@ export declare function formDiscoveryFailedError(detail: string, readyState?: st
904
962
  * Form in iframe (cross-origin or same-origin).
905
963
  */
906
964
  export declare function formInIframeError(iframeUrl: string, crossOrigin: boolean): ErrorWithSuggestion;
965
+ /**
966
+ * `bdg cdp` when Chrome rejected the call: a missing node, target or
967
+ * frame, or wrong parameters.
968
+ *
969
+ * @param method - CDP method
970
+ * @param message - Chrome's error
971
+ * @returns Message, suggestion, and whether something named was not found
972
+ */
973
+ export declare function cdpCallError(method: string, message: string): ErrorWithSuggestion & {
974
+ notFound: boolean;
975
+ };
907
976
  export {};
908
977
  //# sourceMappingURL=messages.d.ts.map
@@ -999,6 +999,16 @@ export function similarSelectorsLine(kind, names) {
999
999
  const plural = names.length === 1 ? what : kind === 'id' ? 'ids' : 'classes';
1000
1000
  return `Did you mean ${names.map((name) => sigil + name).join(', ')}? (similar ${plural} on the page)`;
1001
1001
  }
1002
+ /**
1003
+ * A selector that would have to cross into a shadow root: selectors cannot,
1004
+ * but bdg searches open shadow roots on its own.
1005
+ *
1006
+ * @param host - The compound matching the host, and the selector after it
1007
+ * @returns e.g. `mdn-search-modal hosts a shadow root, which a selector cannot cross into; bdg searches open shadow roots itself: use "form"`
1008
+ */
1009
+ export function shadowBoundaryLine(host) {
1010
+ return `${host.compound} hosts a shadow root, which a selector cannot cross into; bdg searches open shadow roots itself: use "${host.rest}"`;
1011
+ }
1002
1012
  /**
1003
1013
  * No nodes found for selector.
1004
1014
  *
@@ -1015,7 +1025,7 @@ export function noNodesFoundError(selector, context = {}) {
1015
1025
  const note = unreachableElementsNote(selector, context.unsearched);
1016
1026
  return {
1017
1027
  message: `No nodes found matching "${selector}"`,
1018
- suggestion: withLoadingHint(joinLines(context.similar, `${hidden}Verify the CSS selector is correct.`, note ? note : undefined), context.readyState, selector),
1028
+ suggestion: withLoadingHint(joinLines(context.similar, context.shadowHost && shadowBoundaryLine(context.shadowHost), `${hidden}Verify the CSS selector is correct.`, note ? note : undefined), context.readyState, selector),
1019
1029
  };
1020
1030
  }
1021
1031
  /**
@@ -1326,6 +1336,42 @@ export function clickTargetDetachedError(selector) {
1326
1336
  suggestion: 'The page changed during the click; wait for it to settle and retry',
1327
1337
  };
1328
1338
  }
1339
+ /**
1340
+ * A pointer action refused under `--strict` because a real mouse could not
1341
+ * reach the element (covered, hidden, zero-size, pointer-events: none).
1342
+ *
1343
+ * @param target - Selector and element description, as the click located it
1344
+ * @param reason - Why the mouse could not reach it, e.g. "covered by another element (div#shield)"
1345
+ * @param verb - What was refused, e.g. "click", "hover"
1346
+ * @returns Message naming the obstruction, and how to inspect it
1347
+ */
1348
+ export function unreachableElementError(target, reason, verb) {
1349
+ const element = target.element ?? target.selector;
1350
+ return {
1351
+ message: `Did not ${verb} ${element}: it is ${reason ?? 'not reachable by the mouse'}, so a user could not ${verb} it (--strict)`,
1352
+ suggestion: `See what is in the way with ${sessionCommand(`bdg dom layout ${shellQuote(target.selector)}`)}, then close the overlay or scroll; without --strict bdg uses DOM events instead`,
1353
+ };
1354
+ }
1355
+ /**
1356
+ * A mouse press refused under `--strict` because it did not reach the
1357
+ * element: it was sent, but landed on another element, or the page never
1358
+ * saw it (a browser dialog or bubble captured the input).
1359
+ *
1360
+ * @param target - Selector and element description, as the click located it
1361
+ * @param verb - What was refused, e.g. "click"
1362
+ * @param landedOn - The element the press landed on, when the page saw it
1363
+ * @returns Message, and how to inspect the page
1364
+ */
1365
+ export function pressNotReceivedError(target, verb, landedOn) {
1366
+ const element = target.element ?? target.selector;
1367
+ const where = landedOn === undefined
1368
+ ? 'the page saw no press: the browser may be showing a dialog or bubble that captures input'
1369
+ : `landed on ${landedOn}`;
1370
+ return {
1371
+ message: `Did not ${verb} ${element}: the press did not reach the element (it was sent, but ${where}) (--strict)`,
1372
+ suggestion: `Check the page with ${sessionCommand('bdg dom screenshot page.png')} and ${sessionCommand(`bdg dom layout ${shellQuote(target.selector)}`)}`,
1373
+ };
1374
+ }
1329
1375
  /**
1330
1376
  * Key press failed.
1331
1377
  */
@@ -1425,6 +1471,18 @@ export function frameNotFoundError(query, frames) {
1425
1471
  suggestion: joinLines('Available frames:', ...frames.map((frame) => ` ${frameLabel(frame)}`)),
1426
1472
  };
1427
1473
  }
1474
+ /**
1475
+ * A `dom eval --frame` index that names another frame (or none) than when
1476
+ * `bdg dom frames` listed it.
1477
+ *
1478
+ * @param index - Requested index
1479
+ */
1480
+ export function staleFrameIndexError(index) {
1481
+ return {
1482
+ message: `Frame index ${index} is stale: the page's iframes changed since bdg dom frames listed them`,
1483
+ suggestion: 'Re-run bdg dom frames to refresh the indices, or pick the frame by name, id or URL (--frame <name>)',
1484
+ };
1485
+ }
1428
1486
  /**
1429
1487
  * `dom eval --frame` matching more than one iframe.
1430
1488
  *
@@ -1585,6 +1643,22 @@ export function operationFailedError(operation, errorMessage) {
1585
1643
  suggestion: errorMessage,
1586
1644
  };
1587
1645
  }
1646
+ /**
1647
+ * `dom inspect --props` named a property the element has no value for.
1648
+ *
1649
+ * @param names - Unknown property names
1650
+ * @param suggestions - Similar computed property names
1651
+ * @returns Message and suggestion
1652
+ */
1653
+ export function unknownCssPropertyError(names, suggestions) {
1654
+ const plural = names.length > 1;
1655
+ return {
1656
+ message: `Unknown CSS ${plural ? 'properties' : 'property'}: ${names.join(', ')}`,
1657
+ suggestion: suggestions.length > 0
1658
+ ? `Did you mean: ${suggestions.join(', ')}?`
1659
+ : 'Use CSS property names as in a stylesheet (e.g. --props padding-top,color,--brand); bdg dom inspect <selector> --all lists the set ones',
1660
+ };
1661
+ }
1588
1662
  /**
1589
1663
  * The browser does not offer `DOMDebugger.getEventListeners` (non-Chrome
1590
1664
  * targets, or browsers that disable the DOMDebugger domain).
@@ -1650,4 +1724,31 @@ export function formInIframeError(iframeUrl, crossOrigin) {
1650
1724
  : 'dom form lists forms of the main document only; its fields are reachable directly: bdg dom query "input, select, textarea", then bdg dom fill <index> <value>',
1651
1725
  };
1652
1726
  }
1727
+ /** CDP error messages that name something that does not exist (a node, target, frame…) */
1728
+ const CDP_NOT_FOUND_PATTERN = /could not find|cannot find|not found|no \w+ (with|for) (the )?given|does not exist|no such/i;
1729
+ /**
1730
+ * `bdg cdp` when Chrome rejected the call: a missing node, target or
1731
+ * frame, or wrong parameters.
1732
+ *
1733
+ * @param method - CDP method
1734
+ * @param message - Chrome's error
1735
+ * @returns Message, suggestion, and whether something named was not found
1736
+ */
1737
+ export function cdpCallError(method, message) {
1738
+ if (CDP_NOT_FOUND_PATTERN.test(message)) {
1739
+ const ids = /node/i.test(message)
1740
+ ? 'Node ids come from DOM.getDocument (the root) or DOM.querySelector, and a new DOM.getDocument or a navigation replaces them; '
1741
+ : '';
1742
+ return {
1743
+ message: `${method}: ${message}`,
1744
+ suggestion: `${ids}check the ids with ${sessionCommand(`bdg cdp ${method} --describe`)}`,
1745
+ notFound: true,
1746
+ };
1747
+ }
1748
+ return {
1749
+ message: `${method}: ${message}`,
1750
+ suggestion: `See the parameters with ${sessionCommand(`bdg cdp ${method} --describe`)}`,
1751
+ notFound: false,
1752
+ };
1753
+ }
1653
1754
  //# sourceMappingURL=messages.js.map