@chenpx976/chrome-devtools-mcp 0.0.0-stage → 1.13.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 (398) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +223 -2
  3. package/out/Default/gen/src/ArcBrowser.js +128 -0
  4. package/out/Default/gen/src/BrowserManager.js +562 -0
  5. package/out/Default/gen/src/LogpointManager.js +287 -0
  6. package/out/Default/gen/src/McpContext.js +1031 -0
  7. package/out/Default/gen/src/McpPage.js +1427 -0
  8. package/out/Default/gen/src/McpResponse.js +1350 -0
  9. package/out/Default/gen/src/McpWorker.js +66 -0
  10. package/out/Default/gen/src/NetworkOverrideManager.js +447 -0
  11. package/out/Default/gen/src/SlimMcpResponse.js +23 -0
  12. package/out/Default/gen/src/TextSnapshot.js +336 -0
  13. package/out/Default/gen/src/ToolHandler.js +531 -0
  14. package/out/Default/gen/src/bin/check-latest-version.js +53 -0
  15. package/out/Default/gen/src/bin/chrome-devtools-mcp-main.js +80 -0
  16. package/out/Default/gen/src/bin/chrome-devtools-mcp.js +23 -0
  17. package/out/Default/gen/src/bin/chrome-devtools.js +213 -0
  18. package/out/Default/gen/src/collectors/PageCollector.js +325 -0
  19. package/out/Default/gen/src/collectors/ServiceWorkerCollector.js +198 -0
  20. package/out/Default/gen/src/collectors/constants.js +7 -0
  21. package/out/Default/gen/src/config/ConfigLocator.js +70 -0
  22. package/out/Default/gen/src/config/ConfigParser.js +163 -0
  23. package/out/Default/gen/src/config/ConfigWatcher.js +94 -0
  24. package/out/Default/gen/src/config/ServerConfig.js +284 -0
  25. package/out/Default/gen/src/config/browser-options.js +135 -0
  26. package/out/Default/gen/src/config/category-options.js +84 -0
  27. package/out/Default/gen/src/config/cli-commands.js +208 -0
  28. package/out/Default/gen/src/config/cli-options.js +2090 -0
  29. package/out/Default/gen/src/config/mcp-options.js +371 -0
  30. package/out/Default/gen/src/config/puppeteer-options.js +69 -0
  31. package/out/Default/gen/src/config/tool-options.js +60 -0
  32. package/out/Default/gen/src/daemon/client.js +281 -0
  33. package/out/Default/gen/src/daemon/daemon.js +280 -0
  34. package/out/Default/gen/src/daemon/types.js +7 -0
  35. package/out/Default/gen/src/daemon/utils.js +173 -0
  36. package/out/Default/gen/src/devtools/DevToolsCommentBridge.js +151 -0
  37. package/out/Default/gen/src/devtools/DevtoolsUtils.js +413 -0
  38. package/out/Default/gen/src/devtools/McpHostBindingAdapter.js +164 -0
  39. package/out/Default/gen/src/devtools/issueDescriptions.js +42 -0
  40. package/out/Default/gen/src/formatters/CommentFormatter.js +73 -0
  41. package/out/Default/gen/src/formatters/ConsoleFormatter.js +363 -0
  42. package/out/Default/gen/src/formatters/CssFormatter.js +883 -0
  43. package/out/Default/gen/src/formatters/HeapSnapshotFormatter.js +239 -0
  44. package/out/Default/gen/src/formatters/IssueFormatter.js +194 -0
  45. package/out/Default/gen/src/formatters/LogpointFormatter.js +62 -0
  46. package/out/Default/gen/src/formatters/NetworkFormatter.js +295 -0
  47. package/out/Default/gen/src/formatters/NetworkOverridesFormatter.js +57 -0
  48. package/out/Default/gen/src/formatters/RemoteObjectFormatter.js +231 -0
  49. package/out/Default/gen/src/formatters/SnapshotFormatter.js +172 -0
  50. package/out/Default/gen/src/formatters/WebAuthnFormatter.js +56 -0
  51. package/out/Default/gen/src/formatters/constants.js +8 -0
  52. package/out/Default/gen/src/index.js +434 -0
  53. package/out/Default/gen/src/processors/ChunkedTraceParser.js +361 -0
  54. package/out/Default/gen/src/processors/HeapSnapshotManager.js +595 -0
  55. package/out/Default/gen/src/processors/PerformanceTrace.js +132 -0
  56. package/out/Default/gen/src/telemetry/ClearcutLogger.js +271 -0
  57. package/out/Default/gen/src/telemetry/WatchdogClient.js +60 -0
  58. package/out/Default/gen/src/telemetry/errors.js +18 -0
  59. package/out/Default/gen/src/telemetry/flagUtils.js +89 -0
  60. package/out/Default/gen/src/telemetry/metricsRegistry.js +85 -0
  61. package/out/Default/gen/src/telemetry/persistence.js +82 -0
  62. package/out/Default/gen/src/telemetry/transformation.js +229 -0
  63. package/out/Default/gen/src/telemetry/types.js +36 -0
  64. package/out/Default/gen/src/telemetry/watchdog/ClearcutSender.js +213 -0
  65. package/out/Default/gen/src/telemetry/watchdog/main.js +142 -0
  66. package/out/Default/gen/src/third_party/THIRD_PARTY_NOTICES +3774 -0
  67. package/out/Default/gen/src/third_party/browser.js +808 -0
  68. package/out/Default/gen/src/third_party/bundled-packages.json +11 -0
  69. package/out/Default/gen/src/third_party/cli.js +139 -0
  70. package/out/Default/gen/src/third_party/devtools-formatter-worker.js +125 -0
  71. package/out/Default/gen/src/third_party/devtools-heap-snapshot-worker.js +111 -0
  72. package/out/Default/gen/src/third_party/index.js +128 -0
  73. package/out/Default/gen/src/third_party/issue-descriptions/CoepCoopSandboxedIframeCannotNavigateToCoopPage.md +4 -0
  74. package/out/Default/gen/src/third_party/issue-descriptions/CoepCorpNotSameOrigin.md +8 -0
  75. package/out/Default/gen/src/third_party/issue-descriptions/CoepCorpNotSameOriginAfterDefaultedToSameOriginByCoep.md +18 -0
  76. package/out/Default/gen/src/third_party/issue-descriptions/CoepCorpNotSameSite.md +7 -0
  77. package/out/Default/gen/src/third_party/issue-descriptions/CoepFrameResourceNeedsCoepHeader.md +10 -0
  78. package/out/Default/gen/src/third_party/issue-descriptions/CompatibilityModeQuirks.md +5 -0
  79. package/out/Default/gen/src/third_party/issue-descriptions/CookieAttributeValueExceedsMaxSize.md +5 -0
  80. package/out/Default/gen/src/third_party/issue-descriptions/LowTextContrast.md +5 -0
  81. package/out/Default/gen/src/third_party/issue-descriptions/SameSiteNoneInsecureErrorRead.md +8 -0
  82. package/out/Default/gen/src/third_party/issue-descriptions/SameSiteNoneInsecureErrorSet.md +8 -0
  83. package/out/Default/gen/src/third_party/issue-descriptions/SameSiteNoneInsecureWarnRead.md +8 -0
  84. package/out/Default/gen/src/third_party/issue-descriptions/SameSiteNoneInsecureWarnSet.md +8 -0
  85. package/out/Default/gen/src/third_party/issue-descriptions/SameSiteUnspecifiedLaxAllowUnsafeRead.md +9 -0
  86. package/out/Default/gen/src/third_party/issue-descriptions/SameSiteUnspecifiedLaxAllowUnsafeSet.md +9 -0
  87. package/out/Default/gen/src/third_party/issue-descriptions/bounceTrackingMitigations.md +3 -0
  88. package/out/Default/gen/src/third_party/issue-descriptions/clientHintMetaTagAllowListInvalidOrigin.md +4 -0
  89. package/out/Default/gen/src/third_party/issue-descriptions/clientHintMetaTagModifiedHTML.md +4 -0
  90. package/out/Default/gen/src/third_party/issue-descriptions/connectionAllowlistEmbeddingRequirementNotSatisfied.md +26 -0
  91. package/out/Default/gen/src/third_party/issue-descriptions/connectionAllowlistIFrameAttributeLoosensEmbeddingRequirement.md +19 -0
  92. package/out/Default/gen/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowConnectionAllowlistFrom.md +21 -0
  93. package/out/Default/gen/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowlistItemType.md +12 -0
  94. package/out/Default/gen/src/third_party/issue-descriptions/connectionAllowlistInvalidHeader.md +12 -0
  95. package/out/Default/gen/src/third_party/issue-descriptions/connectionAllowlistInvalidUrlPattern.md +8 -0
  96. package/out/Default/gen/src/third_party/issue-descriptions/connectionAllowlistItemNotInnerList.md +12 -0
  97. package/out/Default/gen/src/third_party/issue-descriptions/connectionAllowlistMoreThanOneList.md +7 -0
  98. package/out/Default/gen/src/third_party/issue-descriptions/connectionAllowlistReportingEndpointNotToken.md +10 -0
  99. package/out/Default/gen/src/third_party/issue-descriptions/cookieCrossSiteRedirectDowngrade.md +12 -0
  100. package/out/Default/gen/src/third_party/issue-descriptions/cookieExcludeDomainNonAscii.md +11 -0
  101. package/out/Default/gen/src/third_party/issue-descriptions/cookieExcludePortMismatch.md +8 -0
  102. package/out/Default/gen/src/third_party/issue-descriptions/cookieExcludeSchemeMismatch.md +7 -0
  103. package/out/Default/gen/src/third_party/issue-descriptions/cookieExcludeThirdPartyPhaseoutRead.md +6 -0
  104. package/out/Default/gen/src/third_party/issue-descriptions/cookieExcludeThirdPartyPhaseoutSet.md +6 -0
  105. package/out/Default/gen/src/third_party/issue-descriptions/cookieWarnDomainNonAscii.md +11 -0
  106. package/out/Default/gen/src/third_party/issue-descriptions/cookieWarnMetadataGrantRead.md +3 -0
  107. package/out/Default/gen/src/third_party/issue-descriptions/cookieWarnMetadataGrantReadOptOut.md +5 -0
  108. package/out/Default/gen/src/third_party/issue-descriptions/cookieWarnMetadataGrantSet.md +3 -0
  109. package/out/Default/gen/src/third_party/issue-descriptions/cookieWarnMetadataGrantSetOptOut.md +5 -0
  110. package/out/Default/gen/src/third_party/issue-descriptions/cookieWarnThirdPartyPhaseoutRead.md +6 -0
  111. package/out/Default/gen/src/third_party/issue-descriptions/cookieWarnThirdPartyPhaseoutSet.md +6 -0
  112. package/out/Default/gen/src/third_party/issue-descriptions/corsAllowCredentialsRequired.md +6 -0
  113. package/out/Default/gen/src/third_party/issue-descriptions/corsDisabledScheme.md +7 -0
  114. package/out/Default/gen/src/third_party/issue-descriptions/corsDisallowedByMode.md +7 -0
  115. package/out/Default/gen/src/third_party/issue-descriptions/corsHeaderDisallowedByPreflightResponse.md +5 -0
  116. package/out/Default/gen/src/third_party/issue-descriptions/corsInvalidHeaderValues.md +7 -0
  117. package/out/Default/gen/src/third_party/issue-descriptions/corsLocalNetworkAccessPermissionDenied.md +19 -0
  118. package/out/Default/gen/src/third_party/issue-descriptions/corsMethodDisallowedByPreflightResponse.md +5 -0
  119. package/out/Default/gen/src/third_party/issue-descriptions/corsNoCorsRedirectModeNotFollow.md +5 -0
  120. package/out/Default/gen/src/third_party/issue-descriptions/corsOriginMismatch.md +6 -0
  121. package/out/Default/gen/src/third_party/issue-descriptions/corsPreflightResponseInvalid.md +5 -0
  122. package/out/Default/gen/src/third_party/issue-descriptions/corsRedirectContainsCredentials.md +5 -0
  123. package/out/Default/gen/src/third_party/issue-descriptions/corsWildcardOriginNotAllowed.md +9 -0
  124. package/out/Default/gen/src/third_party/issue-descriptions/cspEvalViolation.md +9 -0
  125. package/out/Default/gen/src/third_party/issue-descriptions/cspInlineViolation.md +10 -0
  126. package/out/Default/gen/src/third_party/issue-descriptions/cspTrustedTypesPolicyViolation.md +5 -0
  127. package/out/Default/gen/src/third_party/issue-descriptions/cspTrustedTypesSinkViolation.md +8 -0
  128. package/out/Default/gen/src/third_party/issue-descriptions/cspURLViolation.md +10 -0
  129. package/out/Default/gen/src/third_party/issue-descriptions/deprecation.md +3 -0
  130. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestAccountsEmptyList.md +1 -0
  131. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestAccountsHttpNotFound.md +1 -0
  132. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestAccountsInvalidContentType.md +1 -0
  133. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestAccountsInvalidResponse.md +1 -0
  134. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestAccountsNoResponse.md +1 -0
  135. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestDnsFetchFailed.md +1 -0
  136. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestDnsInvalidRecord.md +1 -0
  137. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownHttpNotFound.md +1 -0
  138. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownInvalidContentType.md +1 -0
  139. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownInvalidResponse.md +1 -0
  140. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownNoResponse.md +1 -0
  141. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestInvalidEmail.md +1 -0
  142. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestJwksHttpNotFound.md +1 -0
  143. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestJwksInvalidResponse.md +1 -0
  144. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestKeyBindingSigningFailed.md +1 -0
  145. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestRpOriginIsOpaque.md +1 -0
  146. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenHttpNotFound.md +1 -0
  147. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidContentType.md +1 -0
  148. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidResponse.md +1 -0
  149. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidSdJwt.md +1 -0
  150. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenMalformedSdJwt.md +1 -0
  151. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenNoResponse.md +1 -0
  152. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidAudience.md +1 -0
  153. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidIssuedAt.md +1 -0
  154. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidNonce.md +1 -0
  155. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidSdHash.md +1 -0
  156. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidTyp.md +1 -0
  157. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingAud.md +1 -0
  158. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingCnf.md +1 -0
  159. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingIat.md +1 -0
  160. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingNonce.md +1 -0
  161. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingSdHash.md +1 -0
  162. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbSignatureFailed.md +1 -0
  163. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidEmail.md +1 -0
  164. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidEmailVerified.md +1 -0
  165. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidHolderKey.md +1 -0
  166. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidIssuedAt.md +1 -0
  167. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidIssuer.md +1 -0
  168. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtJwksMissingKeys.md +1 -0
  169. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingCnf.md +1 -0
  170. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingEmail.md +1 -0
  171. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingIat.md +1 -0
  172. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingIss.md +1 -0
  173. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtSignatureFailed.md +1 -0
  174. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtUnsupportedHeaderAlg.md +1 -0
  175. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestUserLoggedOut.md +1 -0
  176. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestWellKnownAccountsEndpointCrossOrigin.md +1 -0
  177. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestWellKnownHttpNotFound.md +1 -0
  178. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestWellKnownInvalidContentType.md +1 -0
  179. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestWellKnownInvalidResponse.md +1 -0
  180. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestWellKnownIssuanceEndpointCrossOrigin.md +1 -0
  181. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestWellKnownListEmpty.md +1 -0
  182. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestWellKnownMissingAccountsEndpoint.md +1 -0
  183. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestWellKnownMissingIssuanceEndpoint.md +1 -0
  184. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestWellKnownNoResponse.md +1 -0
  185. package/out/Default/gen/src/third_party/issue-descriptions/emailVerificationRequestWellKnownUnsupportedSigningAlgorithm.md +1 -0
  186. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestAccountsBlockedByConnectionAllowlist.md +1 -0
  187. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestAccountsHttpNotFound.md +1 -0
  188. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestAccountsInvalidResponse.md +1 -0
  189. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestAccountsNoResponse.md +1 -0
  190. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestApprovalDeclined.md +1 -0
  191. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestCanceled.md +1 -0
  192. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestConfigBlockedByConnectionAllowlist.md +1 -0
  193. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestErrorFetchingSignin.md +1 -0
  194. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestErrorIdToken.md +1 -0
  195. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestIdTokenBlockedByConnectionAllowlist.md +1 -0
  196. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestIdTokenHttpNotFound.md +1 -0
  197. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestIdTokenInvalidRequest.md +1 -0
  198. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestIdTokenInvalidResponse.md +1 -0
  199. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestIdTokenNoResponse.md +1 -0
  200. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestInvalidSigninResponse.md +1 -0
  201. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestManifestHttpNotFound.md +1 -0
  202. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestManifestInvalidResponse.md +1 -0
  203. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestManifestNoResponse.md +1 -0
  204. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestTooManyRequests.md +1 -0
  205. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthRequestWellKnownBlockedByConnectionAllowlist.md +1 -0
  206. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthUserInfoRequestInvalidAccountsResponse.md +1 -0
  207. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthUserInfoRequestInvalidConfigOrWellKnown.md +1 -0
  208. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoAccountSharingPermission.md +1 -0
  209. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoApiPermission.md +1 -0
  210. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoReturningUserFromFetchedAccounts.md +1 -0
  211. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotIframe.md +1 -0
  212. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotPotentiallyTrustworthy.md +1 -0
  213. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotSameOrigin.md +1 -0
  214. package/out/Default/gen/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotSignedInWithIdp.md +1 -0
  215. package/out/Default/gen/src/third_party/issue-descriptions/fetchingPartitionedBlobURL.md +7 -0
  216. package/out/Default/gen/src/third_party/issue-descriptions/genericBackUINavigationWouldSkipAd.md +4 -0
  217. package/out/Default/gen/src/third_party/issue-descriptions/genericFormAriaLabelledByToNonExistingIdError.md +8 -0
  218. package/out/Default/gen/src/third_party/issue-descriptions/genericFormAutocompleteAttributeEmptyError.md +5 -0
  219. package/out/Default/gen/src/third_party/issue-descriptions/genericFormDuplicateIdForInputError.md +5 -0
  220. package/out/Default/gen/src/third_party/issue-descriptions/genericFormEmptyIdAndNameAttributesForInputError.md +5 -0
  221. package/out/Default/gen/src/third_party/issue-descriptions/genericFormInputAssignedAutocompleteValueToIdOrNameAttributeError.md +5 -0
  222. package/out/Default/gen/src/third_party/issue-descriptions/genericFormInputHasWrongButWellIntendedAutocompleteValueError.md +5 -0
  223. package/out/Default/gen/src/third_party/issue-descriptions/genericFormInputWithNoLabelError.md +5 -0
  224. package/out/Default/gen/src/third_party/issue-descriptions/genericFormLabelForMatchesNonExistingIdError.md +5 -0
  225. package/out/Default/gen/src/third_party/issue-descriptions/genericFormLabelForNameError.md +5 -0
  226. package/out/Default/gen/src/third_party/issue-descriptions/genericFormLabelHasNeitherForNorNestedInputError.md +5 -0
  227. package/out/Default/gen/src/third_party/issue-descriptions/genericFormModelContextMissingToolDescription.md +5 -0
  228. package/out/Default/gen/src/third_party/issue-descriptions/genericFormModelContextMissingToolName.md +5 -0
  229. package/out/Default/gen/src/third_party/issue-descriptions/genericFormModelContextParameterMissingName.md +5 -0
  230. package/out/Default/gen/src/third_party/issue-descriptions/genericFormModelContextParameterMissingTitleAndDescription.md +5 -0
  231. package/out/Default/gen/src/third_party/issue-descriptions/genericFormModelContextRequiredParameterMissingName.md +5 -0
  232. package/out/Default/gen/src/third_party/issue-descriptions/genericGeolocationPromptWithoutUserGesture.md +5 -0
  233. package/out/Default/gen/src/third_party/issue-descriptions/genericNavigationEntryMarkedSkippable.md +7 -0
  234. package/out/Default/gen/src/third_party/issue-descriptions/genericResponseWasBlockedByORB.md +4 -0
  235. package/out/Default/gen/src/third_party/issue-descriptions/heavyAd.md +10 -0
  236. package/out/Default/gen/src/third_party/issue-descriptions/lazyLoadImageZeroSize.md +7 -0
  237. package/out/Default/gen/src/third_party/issue-descriptions/mixedContent.md +5 -0
  238. package/out/Default/gen/src/third_party/issue-descriptions/navigatingPartitionedBlobURL.md +5 -0
  239. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementActivationDisabled.md +7 -0
  240. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementActivationDisabledWithOccluder.md +9 -0
  241. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementActivationDisabledWithOccluderParent.md +9 -0
  242. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementCspFrameAncestorsMissing.md +5 -0
  243. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementFencedFrameDisallowed.md +5 -0
  244. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementFontSizeTooLarge.md +5 -0
  245. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementFontSizeTooSmall.md +5 -0
  246. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementGeolocationDeprecated.md +5 -0
  247. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementInsetBoxShadowUnsupported.md +5 -0
  248. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementInvalidDisplayStyle.md +5 -0
  249. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementInvalidSizeValue.md +5 -0
  250. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementInvalidType.md +5 -0
  251. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementInvalidTypeActivation.md +5 -0
  252. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementLowContrast.md +5 -0
  253. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementNonOpaqueColor.md +5 -0
  254. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementPaddingBottomUnsupported.md +6 -0
  255. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementPaddingRightUnsupported.md +6 -0
  256. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementPermissionsPolicyBlocked.md +5 -0
  257. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementRegistrationFailed.md +5 -0
  258. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementRequestInProgress.md +5 -0
  259. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementSecurityChecksFailed.md +5 -0
  260. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementTypeNotSupported.md +5 -0
  261. package/out/Default/gen/src/third_party/issue-descriptions/permissionElementUntrustedEvent.md +7 -0
  262. package/out/Default/gen/src/third_party/issue-descriptions/placeholderDescriptionForInvisibleIssues.md +3 -0
  263. package/out/Default/gen/src/third_party/issue-descriptions/propertyRuleInvalidNameIssue.md +3 -0
  264. package/out/Default/gen/src/third_party/issue-descriptions/propertyRuleIssue.md +7 -0
  265. package/out/Default/gen/src/third_party/issue-descriptions/selectElementAccessibilityDisallowedOptGroupChild.md +7 -0
  266. package/out/Default/gen/src/third_party/issue-descriptions/selectElementAccessibilityDisallowedSelectChild.md +7 -0
  267. package/out/Default/gen/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentAttributesSelectDescendant.md +3 -0
  268. package/out/Default/gen/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentLegendChild.md +3 -0
  269. package/out/Default/gen/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentOptionChild.md +3 -0
  270. package/out/Default/gen/src/third_party/issue-descriptions/selectElementAccessibilityNonPhrasingContentOptionChild.md +3 -0
  271. package/out/Default/gen/src/third_party/issue-descriptions/selectivePermissionsIntervention.md +7 -0
  272. package/out/Default/gen/src/third_party/issue-descriptions/sharedArrayBuffer.md +7 -0
  273. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryUseErrorCrossOriginNoCorsRequest.md +1 -0
  274. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryUseErrorDictionaryLoadFailure.md +3 -0
  275. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryUseErrorMatchingDictionaryNotUsed.md +3 -0
  276. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryUseErrorUnexpectedContentDictionaryHeader.md +1 -0
  277. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorCossOriginNoCorsRequest.md +1 -0
  278. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorDisallowedBySettings.md +1 -0
  279. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorExpiredResponse.md +3 -0
  280. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorFeatureDisabled.md +3 -0
  281. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorInsufficientResources.md +1 -0
  282. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorInvalidMatchField.md +1 -0
  283. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorInvalidStructuredHeader.md +1 -0
  284. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorInvalidTTLField.md +1 -0
  285. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNavigationRequest.md +3 -0
  286. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNoMatchField.md +1 -0
  287. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonIntegerTTLField.md +1 -0
  288. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonListMatchDestField.md +1 -0
  289. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonSecureContext.md +3 -0
  290. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonStringIdField.md +1 -0
  291. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonStringInMatchDestList.md +1 -0
  292. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonStringMatchField.md +1 -0
  293. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonTokenTypeField.md +1 -0
  294. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorRequestAborted.md +1 -0
  295. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorShuttingDown.md +1 -0
  296. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorTooLongIdField.md +3 -0
  297. package/out/Default/gen/src/third_party/issue-descriptions/sharedDictionaryWriteErrorUnsupportedType.md +3 -0
  298. package/out/Default/gen/src/third_party/issue-descriptions/sriInvalidSignatureHeader.md +14 -0
  299. package/out/Default/gen/src/third_party/issue-descriptions/sriInvalidSignatureInputHeader.md +15 -0
  300. package/out/Default/gen/src/third_party/issue-descriptions/sriMissingSignatureHeader.md +8 -0
  301. package/out/Default/gen/src/third_party/issue-descriptions/sriMissingSignatureInputHeader.md +7 -0
  302. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureHeaderValueIsIncorrectLength.md +11 -0
  303. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureHeaderValueIsNotByteSequence.md +14 -0
  304. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureHeaderValueIsParameterized.md +15 -0
  305. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidComponentName.md +8 -0
  306. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidComponentType.md +13 -0
  307. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidDerivedComponentParameter.md +4 -0
  308. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidHeaderComponentParameter.md +5 -0
  309. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidParameter.md +11 -0
  310. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureInputHeaderKeyIdLength.md +12 -0
  311. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureInputHeaderMissingLabel.md +6 -0
  312. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureInputHeaderMissingRequiredParameters.md +8 -0
  313. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureInputHeaderValueMissingComponents.md +11 -0
  314. package/out/Default/gen/src/third_party/issue-descriptions/sriSignatureInputHeaderValueNotInnerList.md +11 -0
  315. package/out/Default/gen/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +12 -0
  316. package/out/Default/gen/src/third_party/issue-descriptions/sriValidationFailedInvalidLength.md +5 -0
  317. package/out/Default/gen/src/third_party/issue-descriptions/sriValidationFailedSignatureExpired.md +6 -0
  318. package/out/Default/gen/src/third_party/issue-descriptions/sriValidationFailedSignatureMismatch.md +11 -0
  319. package/out/Default/gen/src/third_party/issue-descriptions/stylesheetLateImport.md +4 -0
  320. package/out/Default/gen/src/third_party/issue-descriptions/stylesheetRequestFailed.md +3 -0
  321. package/out/Default/gen/src/third_party/issue-descriptions/summaryElementAccessibilityInteractiveContentSummaryDescendant.md +3 -0
  322. package/out/Default/gen/src/third_party/issue-descriptions/unencodedDigestIncorrectDigestLength.md +12 -0
  323. package/out/Default/gen/src/third_party/issue-descriptions/unencodedDigestIncorrectDigestType.md +17 -0
  324. package/out/Default/gen/src/third_party/issue-descriptions/unencodedDigestMalformedDictionary.md +14 -0
  325. package/out/Default/gen/src/third_party/issue-descriptions/unencodedDigestUnknownAlgorithm.md +15 -0
  326. package/out/Default/gen/src/third_party/issue-descriptions/webInstallManifestMissingId.md +3 -0
  327. package/out/Default/gen/src/third_party/issue-descriptions/webInstallManifestMissingNameOrShortName.md +3 -0
  328. package/out/Default/gen/src/third_party/issue-descriptions/webInstallManifestParsingOrNetworkError.md +3 -0
  329. package/out/Default/gen/src/third_party/issue-descriptions/webInstallNoManifest.md +3 -0
  330. package/out/Default/gen/src/third_party/issue-descriptions/webInstallStartUrlInvalid.md +3 -0
  331. package/out/Default/gen/src/third_party/lighthouse-devtools-mcp-bundle.js +60395 -0
  332. package/out/Default/gen/src/tools/ToolDefinition.js +180 -0
  333. package/out/Default/gen/src/tools/categories.js +37 -0
  334. package/out/Default/gen/src/tools/comments.js +230 -0
  335. package/out/Default/gen/src/tools/console.js +122 -0
  336. package/out/Default/gen/src/tools/css.js +54 -0
  337. package/out/Default/gen/src/tools/emulation.js +98 -0
  338. package/out/Default/gen/src/tools/extensions.js +108 -0
  339. package/out/Default/gen/src/tools/input.js +658 -0
  340. package/out/Default/gen/src/tools/lighthouse.js +279 -0
  341. package/out/Default/gen/src/tools/logpoints.js +51 -0
  342. package/out/Default/gen/src/tools/memory.js +531 -0
  343. package/out/Default/gen/src/tools/network.js +325 -0
  344. package/out/Default/gen/src/tools/pages.js +420 -0
  345. package/out/Default/gen/src/tools/performance.js +258 -0
  346. package/out/Default/gen/src/tools/pwa.js +152 -0
  347. package/out/Default/gen/src/tools/screencast.js +160 -0
  348. package/out/Default/gen/src/tools/screenshot.js +315 -0
  349. package/out/Default/gen/src/tools/script.js +319 -0
  350. package/out/Default/gen/src/tools/slim/tools.js +110 -0
  351. package/out/Default/gen/src/tools/snapshot.js +88 -0
  352. package/out/Default/gen/src/tools/thirdPartyDeveloper.js +73 -0
  353. package/out/Default/gen/src/tools/toolNames.js +10 -0
  354. package/out/Default/gen/src/tools/tools.js +72 -0
  355. package/out/Default/gen/src/tools/webauthn.js +51 -0
  356. package/out/Default/gen/src/tools/webmcp.js +55 -0
  357. package/out/Default/gen/src/types.js +21 -0
  358. package/out/Default/gen/src/utils/TaskRunner.js +151 -0
  359. package/out/Default/gen/src/utils/WaitForHelper.js +343 -0
  360. package/out/Default/gen/src/utils/bytes.js +95 -0
  361. package/out/Default/gen/src/utils/check-for-updates.js +81 -0
  362. package/out/Default/gen/src/utils/disclaimers.js +27 -0
  363. package/out/Default/gen/src/utils/errorHandling.js +23 -0
  364. package/out/Default/gen/src/utils/files.js +81 -0
  365. package/out/Default/gen/src/utils/id.js +16 -0
  366. package/out/Default/gen/src/utils/keyboard.js +307 -0
  367. package/out/Default/gen/src/utils/logger.js +145 -0
  368. package/out/Default/gen/src/utils/logpoint.js +44 -0
  369. package/out/Default/gen/src/utils/network.js +81 -0
  370. package/out/Default/gen/src/utils/pagination.js +50 -0
  371. package/out/Default/gen/src/utils/polyfill.js +11 -0
  372. package/out/Default/gen/src/utils/raceWithSignal.js +26 -0
  373. package/out/Default/gen/src/utils/resourceType.js +27 -0
  374. package/out/Default/gen/src/utils/text.js +43 -0
  375. package/out/Default/gen/src/utils/timeout.js +14 -0
  376. package/out/Default/gen/src/utils/url.js +311 -0
  377. package/out/Default/gen/src/version.js +11 -0
  378. package/package.json +125 -4
  379. package/skills/a11y-debugging/SKILL.md +86 -0
  380. package/skills/a11y-debugging/references/a11y-snippets.md +92 -0
  381. package/skills/arc-compatibility/SKILL.md +168 -0
  382. package/skills/arc-compatibility/SOURCES.md +216 -0
  383. package/skills/arc-compatibility/references/compatibility.md +113 -0
  384. package/skills/arc-compatibility/references/output-contract.md +62 -0
  385. package/skills/arc-compatibility/references/workflows.md +105 -0
  386. package/skills/chrome-devtools/SKILL.md +80 -0
  387. package/skills/chrome-devtools-cli/SKILL.md +208 -0
  388. package/skills/chrome-devtools-cli/references/installation.md +24 -0
  389. package/skills/cookie-debugging/SKILL.md +152 -0
  390. package/skills/debug-optimize-lcp/SKILL.md +121 -0
  391. package/skills/debug-optimize-lcp/references/elements-and-size.md +27 -0
  392. package/skills/debug-optimize-lcp/references/lcp-breakdown.md +23 -0
  393. package/skills/debug-optimize-lcp/references/lcp-snippets.md +79 -0
  394. package/skills/debug-optimize-lcp/references/optimization-strategies.md +38 -0
  395. package/skills/inspect-in-devtools/SKILL.md +82 -0
  396. package/skills/memory-leak-debugging/SKILL.md +58 -0
  397. package/skills/memory-leak-debugging/references/common-leaks.md +33 -0
  398. package/skills/troubleshooting/SKILL.md +107 -0
@@ -0,0 +1,1350 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { CommentFormatter, } from './formatters/CommentFormatter.js';
7
+ import { ConsoleFormatter } from './formatters/ConsoleFormatter.js';
8
+ import { CssFormatter, resolveContainerQueries, } from './formatters/CssFormatter.js';
9
+ import { collectRankedContexts, formatName, HeapSnapshotFormatter, isEdgeLike, isNodeLike, } from './formatters/HeapSnapshotFormatter.js';
10
+ import { IssueFormatter } from './formatters/IssueFormatter.js';
11
+ import { NetworkFormatter } from './formatters/NetworkFormatter.js';
12
+ import { SnapshotFormatter } from './formatters/SnapshotFormatter.js';
13
+ import { WebAuthnFormatter } from './formatters/WebAuthnFormatter.js';
14
+ import { UncaughtError } from './collectors/PageCollector.js';
15
+ import { TextSnapshot } from './TextSnapshot.js';
16
+ import { getToonEncode, getGcfEncode, } from './third_party/index.js';
17
+ import { DevTools, } from './third_party/browser.js';
18
+ import { handleDialog, listPages } from './tools/pages.js';
19
+ import { LIST_CONSOLE_MESSAGES_TOOL_NAME } from './tools/toolNames.js';
20
+ import { getInsightOutput, getTraceSummary, } from './processors/PerformanceTrace.js';
21
+ import { stableIdSymbol } from './utils/id.js';
22
+ import { paginate } from './utils/pagination.js';
23
+ import { getFilterableResourceType } from './utils/resourceType.js';
24
+ import { truncateText } from './utils/text.js';
25
+ import { PACKAGE_NAME } from './version.js';
26
+ const { formatBytesToKb } = DevTools.I18n.ByteUtilities;
27
+ /** How many errors raised during a call the response lists. */
28
+ const MAX_CONSOLE_ERRORS = 10;
29
+ export class McpResponse {
30
+ #includePages = false;
31
+ #includeExtensionServiceWorkers = false;
32
+ #includeExtensionPages = false;
33
+ #snapshotParams;
34
+ #attachedNetworkRequestId;
35
+ #attachedNetworkRequestOptions;
36
+ #attachedConsoleMessageId;
37
+ #attachedConsoleMessageServiceWorkerId;
38
+ #attachedTraceSummary;
39
+ #attachedTraceInsight;
40
+ #attachedLighthouseResult;
41
+ #textResponseLines = [];
42
+ #images = [];
43
+ #heapSnapshotOptions;
44
+ #networkRequestsOptions;
45
+ #consoleDataOptions;
46
+ #cssStylesData;
47
+ #listExtensions;
48
+ #listThirdPartyDeveloperTools;
49
+ #listWebMcpTools;
50
+ #devToolsData;
51
+ #tabId;
52
+ #config;
53
+ #page;
54
+ #error;
55
+ #attachedWaitForResult;
56
+ #consoleErrorsFrom;
57
+ #reconnectNotice = false;
58
+ #devToolsComments;
59
+ #webAuthnFormatter;
60
+ get #deviceScope() {
61
+ return this.#page?.viewport?.isMobile ? 'PHONE' : 'DESKTOP';
62
+ }
63
+ constructor(config) {
64
+ this.#config = config;
65
+ }
66
+ setPage(page) {
67
+ this.#page = page;
68
+ }
69
+ /**
70
+ * Surfaces a one-time note that the browser reconnected and page ids changed.
71
+ * Set by the tool handler when the context reports a pending reconnect notice.
72
+ */
73
+ setReconnectNotice() {
74
+ this.#reconnectNotice = true;
75
+ }
76
+ attachDevToolsData(data) {
77
+ this.#devToolsData = data;
78
+ }
79
+ setTabId(tabId) {
80
+ this.#tabId = tabId;
81
+ }
82
+ setIncludePages(value) {
83
+ this.#includePages = value;
84
+ if (this.#config.resolved.categoryExtensions) {
85
+ this.#includeExtensionServiceWorkers = value;
86
+ this.#includeExtensionPages = value;
87
+ }
88
+ }
89
+ setIncludeExtensionServiceWorkers(value) {
90
+ this.#includeExtensionServiceWorkers = value;
91
+ }
92
+ includeSnapshot(params) {
93
+ this.#snapshotParams = params ?? {
94
+ verbose: false,
95
+ };
96
+ }
97
+ setListExtensions() {
98
+ this.#listExtensions = true;
99
+ }
100
+ setListThirdPartyDeveloperTools() {
101
+ this.#listThirdPartyDeveloperTools = true;
102
+ }
103
+ setListWebMcpTools() {
104
+ this.#listWebMcpTools = true;
105
+ }
106
+ setIncludeNetworkRequests(value, options) {
107
+ if (!value) {
108
+ this.#networkRequestsOptions = undefined;
109
+ return;
110
+ }
111
+ this.#networkRequestsOptions = {
112
+ include: value,
113
+ pagination: options?.pageSize !== undefined
114
+ ? {
115
+ pageSize: options.pageSize,
116
+ pageIdx: options.pageIdx,
117
+ }
118
+ : undefined,
119
+ resourceTypes: options?.resourceTypes,
120
+ includePreservedRequests: options?.includePreservedRequests,
121
+ networkRequestIdInDevToolsUI: options?.networkRequestIdInDevToolsUI,
122
+ serviceWorkerId: options?.serviceWorkerId,
123
+ };
124
+ }
125
+ setIncludeConsoleData(value, options) {
126
+ if (!value) {
127
+ this.#consoleDataOptions = undefined;
128
+ return;
129
+ }
130
+ this.#consoleDataOptions = {
131
+ include: value,
132
+ pagination: options?.pageSize !== undefined
133
+ ? {
134
+ pageSize: options.pageSize,
135
+ pageIdx: options.pageIdx,
136
+ }
137
+ : undefined,
138
+ types: options?.types,
139
+ includePreservedMessages: options?.includePreservedMessages,
140
+ includeStackTraces: options?.includeStackTraces,
141
+ serviceWorkerId: options?.serviceWorkerId,
142
+ };
143
+ }
144
+ includeConsoleErrorsFrom(page) {
145
+ this.#consoleErrorsFrom = {
146
+ page,
147
+ lastMessageId: page.getLatestConsoleMessageId(),
148
+ };
149
+ }
150
+ setIncludeCssStyles(styles, options) {
151
+ this.#cssStylesData = {
152
+ styles,
153
+ options,
154
+ };
155
+ }
156
+ setError(error) {
157
+ this.#error = error;
158
+ }
159
+ attachNetworkRequest(reqId, options) {
160
+ this.#attachedNetworkRequestId = reqId;
161
+ this.#attachedNetworkRequestOptions = options;
162
+ }
163
+ attachConsoleMessage(msgid, options) {
164
+ this.#attachedConsoleMessageId = msgid;
165
+ this.#attachedConsoleMessageServiceWorkerId = options?.serviceWorkerId;
166
+ }
167
+ attachWebAuthnAuthenticator(authenticator) {
168
+ this.#webAuthnFormatter = new WebAuthnFormatter(authenticator);
169
+ }
170
+ attachTraceSummary(result) {
171
+ this.#attachedTraceSummary = result;
172
+ }
173
+ attachTraceInsight(trace, insightSetId, insightName) {
174
+ this.#attachedTraceInsight = {
175
+ trace,
176
+ insightSetId,
177
+ insightName,
178
+ };
179
+ }
180
+ attachLighthouseResult(result) {
181
+ this.#attachedLighthouseResult = result;
182
+ }
183
+ get includePages() {
184
+ return this.#includePages;
185
+ }
186
+ get attachedTraceSummary() {
187
+ return this.#attachedTraceSummary;
188
+ }
189
+ get attachedTracedInsight() {
190
+ return this.#attachedTraceInsight;
191
+ }
192
+ get attachedLighthouseResult() {
193
+ return this.#attachedLighthouseResult;
194
+ }
195
+ get includeNetworkRequests() {
196
+ return this.#networkRequestsOptions?.include ?? false;
197
+ }
198
+ get includeConsoleData() {
199
+ return this.#consoleDataOptions?.include ?? false;
200
+ }
201
+ get attachedNetworkRequestId() {
202
+ return this.#attachedNetworkRequestId;
203
+ }
204
+ get networkRequestsPageIdx() {
205
+ return this.#networkRequestsOptions?.pagination?.pageIdx;
206
+ }
207
+ get consoleMessagesPageIdx() {
208
+ return this.#consoleDataOptions?.pagination?.pageIdx;
209
+ }
210
+ get consoleMessagesTypes() {
211
+ return this.#consoleDataOptions?.types;
212
+ }
213
+ get error() {
214
+ return this.#error;
215
+ }
216
+ appendResponseLine(value) {
217
+ this.#textResponseLines.push(value);
218
+ }
219
+ attachWaitForResult(result) {
220
+ this.#attachedWaitForResult = result;
221
+ }
222
+ setDevToolsComments(threads) {
223
+ this.#devToolsComments = threads;
224
+ }
225
+ get devToolsComments() {
226
+ return this.#devToolsComments;
227
+ }
228
+ setHeapSnapshotAggregates(aggregateData, options) {
229
+ this.#heapSnapshotOptions = {
230
+ ...this.#heapSnapshotOptions,
231
+ include: true,
232
+ aggregateData,
233
+ pagination: options,
234
+ formatOptions: options,
235
+ };
236
+ }
237
+ setHeapSnapshotStats(stats, staticData, nativeContextSizes, retainedByContextSummary, options) {
238
+ this.#heapSnapshotOptions = {
239
+ ...this.#heapSnapshotOptions,
240
+ include: true,
241
+ stats,
242
+ staticData,
243
+ nativeContextSizes,
244
+ retainedByContextSummary,
245
+ formatOptions: options,
246
+ };
247
+ }
248
+ setHeapSnapshotNodes(nodes, options) {
249
+ this.#heapSnapshotOptions = {
250
+ ...this.#heapSnapshotOptions,
251
+ include: true,
252
+ nodes,
253
+ pagination: options,
254
+ formatOptions: options,
255
+ };
256
+ }
257
+ setHeapSnapshotDuplicateStrings(duplicateStrings, options) {
258
+ this.#heapSnapshotOptions = {
259
+ ...this.#heapSnapshotOptions,
260
+ include: true,
261
+ duplicateStrings,
262
+ pagination: options,
263
+ formatOptions: options,
264
+ };
265
+ }
266
+ setHeapSnapshotRetainingPaths(retainingPaths, options) {
267
+ this.#heapSnapshotOptions = {
268
+ ...this.#heapSnapshotOptions,
269
+ include: true,
270
+ retainingPaths,
271
+ formatOptions: options,
272
+ };
273
+ }
274
+ setHeapSnapshotDominators(dominators, options) {
275
+ this.#heapSnapshotOptions = {
276
+ ...this.#heapSnapshotOptions,
277
+ include: true,
278
+ dominators,
279
+ formatOptions: options,
280
+ };
281
+ }
282
+ setHeapSnapshotClassDiffs(diff, options) {
283
+ this.#heapSnapshotOptions = {
284
+ ...this.#heapSnapshotOptions,
285
+ include: true,
286
+ diff,
287
+ pagination: options,
288
+ formatOptions: options,
289
+ };
290
+ }
291
+ setHeapSnapshotDetailedClassDiff(detailedClassDiff, options) {
292
+ this.#heapSnapshotOptions = {
293
+ ...this.#heapSnapshotOptions,
294
+ include: true,
295
+ detailedClassDiff,
296
+ pagination: options,
297
+ formatOptions: options,
298
+ };
299
+ }
300
+ setHeapSnapshotObjectDetails(objectInfo, options) {
301
+ this.#heapSnapshotOptions = {
302
+ ...this.#heapSnapshotOptions,
303
+ include: true,
304
+ objectInfo,
305
+ formatOptions: options,
306
+ };
307
+ }
308
+ setHeapSnapshotContextAnalysis(contextAnalysis, options) {
309
+ this.#heapSnapshotOptions = {
310
+ ...this.#heapSnapshotOptions,
311
+ include: true,
312
+ contextAnalysis,
313
+ contextAnalysisOptions: options,
314
+ formatOptions: options,
315
+ };
316
+ }
317
+ attachImage(value) {
318
+ this.#images.push(value);
319
+ }
320
+ get responseLines() {
321
+ return this.#textResponseLines;
322
+ }
323
+ get images() {
324
+ return this.#images;
325
+ }
326
+ get snapshotParams() {
327
+ return this.#snapshotParams;
328
+ }
329
+ get listWebMcpTools() {
330
+ return this.#listWebMcpTools;
331
+ }
332
+ async #handleSnapshot(context) {
333
+ if (!this.#snapshotParams) {
334
+ return undefined;
335
+ }
336
+ if (!this.#page) {
337
+ throw new Error('Response must have a page');
338
+ }
339
+ this.#page.textSnapshot = await TextSnapshot.create(this.#page, {
340
+ verbose: this.#snapshotParams.verbose,
341
+ devtoolsData: this.#devToolsData,
342
+ });
343
+ const formatter = new SnapshotFormatter(this.#page.textSnapshot);
344
+ if (this.#snapshotParams.filePath) {
345
+ const result = await context.saveFile(new TextEncoder().encode(formatter.toString()), this.#snapshotParams.filePath, '.txt');
346
+ return result.filename;
347
+ }
348
+ return formatter;
349
+ }
350
+ async #handleAttachedNetworkRequest(context) {
351
+ if (!this.#attachedNetworkRequestId) {
352
+ return undefined;
353
+ }
354
+ const serviceWorkerId = this.#attachedNetworkRequestOptions?.serviceWorkerId;
355
+ let request;
356
+ if (serviceWorkerId) {
357
+ request = context.getServiceWorkerNetworkRequestById(serviceWorkerId, this.#attachedNetworkRequestId);
358
+ }
359
+ else {
360
+ if (!this.#page) {
361
+ throw new Error(`Response must have an McpPage`);
362
+ }
363
+ request = this.#page.getNetworkRequestById(this.#attachedNetworkRequestId);
364
+ }
365
+ return await NetworkFormatter.from(request, {
366
+ requestId: this.#attachedNetworkRequestId,
367
+ requestIdResolver: req => this.getNetworkRequestStableId(req),
368
+ fetchData: true,
369
+ requestFilePath: this.#attachedNetworkRequestOptions?.requestFilePath,
370
+ responseFilePath: this.#attachedNetworkRequestOptions?.responseFilePath,
371
+ saveFile: (data, filename, extension) => context.saveFile(data, filename, extension),
372
+ redactNetworkHeaders: this.#config.resolved.redactNetworkHeaders,
373
+ });
374
+ }
375
+ async #handleAttachedConsoleMessage(context) {
376
+ if (!this.#attachedConsoleMessageId) {
377
+ return undefined;
378
+ }
379
+ const consoleMessageStableId = this.#attachedConsoleMessageId;
380
+ if (this.#attachedConsoleMessageServiceWorkerId) {
381
+ // Service workers have no DevTools universe, so no stack trace is resolved.
382
+ return await ConsoleFormatter.from(context.getServiceWorkerConsoleMessageById(this.#attachedConsoleMessageServiceWorkerId, consoleMessageStableId), { id: consoleMessageStableId, fetchDetailedData: true });
383
+ }
384
+ if (!this.#page) {
385
+ throw new Error(`Response must have an McpPage`);
386
+ }
387
+ const message = this.#page.getConsoleMessageById(consoleMessageStableId);
388
+ if ('args' in message || message instanceof UncaughtError) {
389
+ const consoleMessage = message;
390
+ return await ConsoleFormatter.from(consoleMessage, {
391
+ id: consoleMessageStableId,
392
+ fetchDetailedData: true,
393
+ devTools: this.#page.devtoolsUniverse,
394
+ });
395
+ }
396
+ if (message instanceof DevTools.AggregatedIssue) {
397
+ const formatter = new IssueFormatter(message, {
398
+ id: consoleMessageStableId,
399
+ requestIdResolver: this.#page.resolveCdpRequestId.bind(this.#page),
400
+ elementIdResolver: this.#page.textSnapshot?.resolveCdpElementId.bind(this.#page.textSnapshot),
401
+ });
402
+ if (!formatter.isValid()) {
403
+ throw new Error("Can't provide details for the msgid " + consoleMessageStableId);
404
+ }
405
+ return formatter;
406
+ }
407
+ return undefined;
408
+ }
409
+ async #handleThirdPartyDeveloperTools() {
410
+ if (this.#config.resolved.categoryExperimentalThirdParty &&
411
+ this.#listThirdPartyDeveloperTools &&
412
+ this.#page) {
413
+ return await this.#page.discoverThirdPartyDeveloperTools();
414
+ }
415
+ return undefined;
416
+ }
417
+ async #handleWebMCP() {
418
+ if (this.#config.resolved.categoryExperimentalWebmcp &&
419
+ this.#listWebMcpTools &&
420
+ this.#page) {
421
+ return this.#page.getWebMcpTools();
422
+ }
423
+ return undefined;
424
+ }
425
+ async #handleConsoleList(context) {
426
+ if (!this.#consoleDataOptions?.include) {
427
+ return undefined;
428
+ }
429
+ let messages;
430
+ let page;
431
+ if (this.#consoleDataOptions.serviceWorkerId) {
432
+ messages = context.getServiceWorkerConsoleData(this.#consoleDataOptions.serviceWorkerId);
433
+ }
434
+ else {
435
+ page = this.#page;
436
+ if (!page) {
437
+ throw new Error(`Response must have an McpPage`);
438
+ }
439
+ messages = page.getConsoleData(this.#consoleDataOptions.includePreservedMessages);
440
+ }
441
+ return await this.#formatConsoleData(messages, page, this.#consoleDataOptions);
442
+ }
443
+ async #handleConsoleErrors() {
444
+ const errorsFrom = this.#consoleErrorsFrom;
445
+ // A tool that lists or shows console messages itself already covers these.
446
+ if (!errorsFrom ||
447
+ this.#consoleDataOptions?.include ||
448
+ this.#attachedConsoleMessageId !== undefined ||
449
+ errorsFrom.page.isClosed()) {
450
+ return undefined;
451
+ }
452
+ return await this.#formatConsoleData(errorsFrom.page.getConsoleDataAfter(errorsFrom.lastMessageId), errorsFrom.page, { types: ['error'] });
453
+ }
454
+ async #formatConsoleData(messages, page, options) {
455
+ if (options.types?.length) {
456
+ const normalizedTypes = new Set(options.types);
457
+ messages = messages.filter(message => {
458
+ if ('type' in message) {
459
+ return normalizedTypes.has(message.type());
460
+ }
461
+ if (message instanceof DevTools.AggregatedIssue) {
462
+ return normalizedTypes.has('issue');
463
+ }
464
+ return normalizedTypes.has('error');
465
+ });
466
+ }
467
+ return (await Promise.all(messages.map(async (item) => {
468
+ const consoleMessageStableId = this.getConsoleMessageStableId(item);
469
+ if ('args' in item || item instanceof UncaughtError) {
470
+ const consoleMessage = item;
471
+ return await ConsoleFormatter.from(consoleMessage, {
472
+ id: consoleMessageStableId,
473
+ fetchDetailedData: false,
474
+ fetchStackTrace: options.includeStackTraces,
475
+ devTools: page ? page.devtoolsUniverse : undefined,
476
+ });
477
+ }
478
+ if (item instanceof DevTools.AggregatedIssue) {
479
+ const formatter = new IssueFormatter(item, {
480
+ id: consoleMessageStableId,
481
+ });
482
+ if (!formatter.isValid()) {
483
+ return null;
484
+ }
485
+ return formatter;
486
+ }
487
+ return null;
488
+ }))).filter(item => item !== null);
489
+ }
490
+ async #handleNetworkRequestList(context) {
491
+ if (!this.#networkRequestsOptions?.include) {
492
+ return undefined;
493
+ }
494
+ let requests;
495
+ if (this.#networkRequestsOptions.serviceWorkerId) {
496
+ requests = context.getServiceWorkerNetworkData(this.#networkRequestsOptions.serviceWorkerId);
497
+ }
498
+ else {
499
+ if (!this.#page) {
500
+ throw new Error(`Response must have an McpPage`);
501
+ }
502
+ requests = this.#page.getNetworkRequests(this.#networkRequestsOptions.includePreservedRequests);
503
+ }
504
+ // Apply resource type filtering if specified
505
+ if (this.#networkRequestsOptions.resourceTypes?.length) {
506
+ const normalizedTypes = new Set(this.#networkRequestsOptions.resourceTypes);
507
+ requests = requests.filter(request => {
508
+ return normalizedTypes.has(getFilterableResourceType(request));
509
+ });
510
+ }
511
+ return await Promise.all(requests.map(request => NetworkFormatter.from(request, {
512
+ requestId: this.getNetworkRequestStableId(request),
513
+ selectedInDevToolsUI: this.getNetworkRequestStableId(request) ===
514
+ this.#networkRequestsOptions?.networkRequestIdInDevToolsUI,
515
+ fetchData: false,
516
+ saveFile: (data, filename, extension) => context.saveFile(data, filename, extension),
517
+ redactNetworkHeaders: this.#config.resolved.redactNetworkHeaders,
518
+ })));
519
+ }
520
+ async #handleComments() {
521
+ const comments = this.#devToolsComments;
522
+ if (!comments) {
523
+ return undefined;
524
+ }
525
+ const page = this.#page;
526
+ const initialSnapshot = page?.textSnapshot;
527
+ const formatter = await CommentFormatter.from(comments, {
528
+ resolveBackendNodeId: page
529
+ ? (id) => page.resolveBackendNodeId(id)
530
+ : undefined,
531
+ resolveCdpRequestId: page
532
+ ? (id) => page.resolveCdpRequestId(id)
533
+ : undefined,
534
+ });
535
+ let commentsSnapshotRegenerated;
536
+ if (page?.textSnapshot && page.textSnapshot !== initialSnapshot) {
537
+ commentsSnapshotRegenerated = page.textSnapshot.verbose
538
+ ? 'verbose'
539
+ : 'standard';
540
+ }
541
+ return { formatter, commentsSnapshotRegenerated };
542
+ }
543
+ async handle(context, dataFormat = 'default') {
544
+ if (this.#includePages || this.#attachedWaitForResult?.openedPages) {
545
+ await context.createPagesSnapshot();
546
+ }
547
+ if (this.#includePages && (!this.#page || this.#page.isClosed())) {
548
+ try {
549
+ this.#page = context.getSelectedMcpPage();
550
+ }
551
+ catch {
552
+ this.#page = undefined;
553
+ }
554
+ }
555
+ const [snapshot, detailedNetworkRequest, detailedConsoleMessage, thirdPartyDeveloperTools, webmcpTools, consoleMessages, consoleErrors, networkRequests, commentsResult,] = await Promise.all([
556
+ this.#handleSnapshot(context),
557
+ this.#handleAttachedNetworkRequest(context),
558
+ this.#handleAttachedConsoleMessage(context),
559
+ this.#handleThirdPartyDeveloperTools(),
560
+ this.#handleWebMCP(),
561
+ this.#handleConsoleList(context),
562
+ this.#handleConsoleErrors(),
563
+ this.#handleNetworkRequestList(context),
564
+ this.#handleComments(),
565
+ ]);
566
+ if (this.#includeExtensionServiceWorkers) {
567
+ context.createWorkersSnapshot();
568
+ }
569
+ let extensions;
570
+ if (this.#listExtensions) {
571
+ extensions = await context.listExtensions();
572
+ }
573
+ return await this.format(context, {
574
+ detailedConsoleMessage,
575
+ consoleMessages,
576
+ consoleErrors,
577
+ snapshot,
578
+ detailedNetworkRequest,
579
+ networkRequests,
580
+ traceInsight: this.#attachedTraceInsight,
581
+ traceSummary: this.#attachedTraceSummary,
582
+ extensions,
583
+ lighthouseResult: this.#attachedLighthouseResult,
584
+ thirdPartyDeveloperTools,
585
+ webmcpTools,
586
+ comments: commentsResult?.formatter,
587
+ commentsSnapshotRegenerated: commentsResult?.commentsSnapshotRegenerated,
588
+ errorMessage: this.#error?.message,
589
+ }, dataFormat);
590
+ }
591
+ getConsoleMessageStableId(message) {
592
+ return message[stableIdSymbol] ?? -1;
593
+ }
594
+ getNetworkRequestStableId(request) {
595
+ return request[stableIdSymbol] ?? -1;
596
+ }
597
+ async format(context, data, dataFormat = 'default') {
598
+ const structuredContent = {};
599
+ // Resolve the compact encoder based on the chosen format
600
+ let compactEncode;
601
+ if (dataFormat === 'toon') {
602
+ try {
603
+ compactEncode = await getToonEncode();
604
+ }
605
+ catch {
606
+ throw new Error('The `@toon-format/toon` package is required to use --experimentalDataFormat=toon. ' +
607
+ 'Make sure the peer dependency is installed:\n' +
608
+ `- For npx: npx --package ${PACKAGE_NAME}@latest --package @toon-format/toon@latest chrome-devtools-mcp --experimentalDataFormat=toon\n` +
609
+ '- For npm: npm install @toon-format/toon (add -g if installed globally)');
610
+ }
611
+ }
612
+ else if (dataFormat === 'gcf') {
613
+ try {
614
+ compactEncode = await getGcfEncode();
615
+ }
616
+ catch {
617
+ throw new Error('The `@blackwell-systems/gcf` package is required to use --experimentalDataFormat=gcf. ' +
618
+ 'Make sure the peer dependency is installed:\n' +
619
+ `- For npx: npx --package ${PACKAGE_NAME}@latest --package @blackwell-systems/gcf@latest chrome-devtools-mcp --experimentalDataFormat=gcf\n` +
620
+ '- For npm: npm install @blackwell-systems/gcf (add -g if installed globally)');
621
+ }
622
+ }
623
+ const response = [];
624
+ if (this.#reconnectNotice) {
625
+ structuredContent.reconnected = true;
626
+ response.push(`Note: the browser was restarted or reconnected since the last call. Page ids have changed. Call ${listPages(this.#config.resolved).name} to see open pages.`);
627
+ }
628
+ if (this.#textResponseLines.length) {
629
+ structuredContent.message = this.#textResponseLines.join('\n');
630
+ response.push(...this.#textResponseLines);
631
+ }
632
+ if (this.#attachedWaitForResult) {
633
+ if (this.#attachedWaitForResult.navigatedToUrl) {
634
+ response.push(`Page navigated to ${this.#attachedWaitForResult.navigatedToUrl}.`);
635
+ structuredContent.navigatedToUrl =
636
+ this.#attachedWaitForResult.navigatedToUrl;
637
+ }
638
+ if (this.#attachedWaitForResult.openedPages) {
639
+ const openedPages = this.#attachedWaitForResult.openedPages;
640
+ const openedMcpPages = context
641
+ .getPages()
642
+ .filter(mcpPage => openedPages.has(mcpPage.target));
643
+ if (openedMcpPages.length) {
644
+ const targetInfos = await context.getTargetInfos();
645
+ response.push('## Opened pages');
646
+ const structuredPages = [];
647
+ for (const mcpPage of openedMcpPages) {
648
+ const page = formatPage(mcpPage, context, targetInfos.get(mcpPage.targetId));
649
+ response.push(page.text);
650
+ structuredPages.push(page.structured);
651
+ }
652
+ structuredContent.openedPages = structuredPages;
653
+ }
654
+ }
655
+ }
656
+ const page = this.#page;
657
+ const networkConditions = page?.networkConditions;
658
+ if (page && networkConditions) {
659
+ const timeout = page.pptrPage.getDefaultNavigationTimeout();
660
+ response.push(`Emulating network conditions: ${networkConditions}`);
661
+ response.push(`Default navigation timeout set to ${timeout} ms`);
662
+ structuredContent.networkConditions = networkConditions;
663
+ structuredContent.navigationTimeout = timeout;
664
+ }
665
+ const geolocation = this.#page?.geolocation;
666
+ if (geolocation) {
667
+ response.push(`Emulating geolocation: latitude=${geolocation.latitude}, longitude=${geolocation.longitude}`);
668
+ structuredContent.geolocation = geolocation;
669
+ }
670
+ const viewport = this.#page?.viewport;
671
+ if (viewport) {
672
+ response.push(`Emulating viewport: ${JSON.stringify(viewport)}`);
673
+ structuredContent.viewport = viewport;
674
+ }
675
+ const userAgent = this.#page?.userAgent;
676
+ if (userAgent) {
677
+ response.push(`Emulating user agent: ${userAgent}`);
678
+ structuredContent.userAgent = userAgent;
679
+ }
680
+ const cpuThrottlingRate = this.#page?.cpuThrottlingRate ?? 1;
681
+ if (cpuThrottlingRate > 1) {
682
+ response.push(`Emulating CPU throttling: ${cpuThrottlingRate}x slowdown`);
683
+ structuredContent.cpuThrottlingRate = cpuThrottlingRate;
684
+ }
685
+ const colorScheme = this.#page?.colorScheme;
686
+ if (colorScheme) {
687
+ response.push(`Emulating color scheme: ${colorScheme}`);
688
+ structuredContent.colorScheme = colorScheme;
689
+ }
690
+ const forcedColors = this.#page?.forcedColors;
691
+ if (forcedColors) {
692
+ response.push(`Emulating forced-colors: ${forcedColors}`);
693
+ structuredContent.forcedColors = forcedColors;
694
+ }
695
+ const prefersContrast = this.#page?.prefersContrast;
696
+ if (prefersContrast) {
697
+ response.push(`Emulating prefers-contrast: ${prefersContrast}`);
698
+ structuredContent.prefersContrast = prefersContrast;
699
+ }
700
+ const prefersReducedMotion = this.#page?.prefersReducedMotion;
701
+ if (prefersReducedMotion) {
702
+ response.push(`Emulating prefers-reduced-motion: ${prefersReducedMotion}`);
703
+ structuredContent.prefersReducedMotion = prefersReducedMotion;
704
+ }
705
+ const dialog = this.#page?.getDialog();
706
+ if (dialog) {
707
+ const defaultValueIfNeeded = dialog.type() === 'prompt'
708
+ ? ` (default value: "${dialog.defaultValue()}")`
709
+ : '';
710
+ response.push(`# Open dialog
711
+ ${dialog.type()}: ${dialog.message()}${defaultValueIfNeeded}.
712
+ Call ${handleDialog(this.#config.resolved).name} to handle it before continuing.`);
713
+ structuredContent.dialog = {
714
+ type: dialog.type(),
715
+ message: dialog.message(),
716
+ defaultValue: dialog.defaultValue(),
717
+ };
718
+ }
719
+ if (this.#includePages) {
720
+ const allPages = context.getPages();
721
+ const { regularPages, extensionPages } = allPages.reduce((acc, mcpPage) => {
722
+ if (mcpPage.url().startsWith('chrome-extension://')) {
723
+ acc.extensionPages.push(mcpPage);
724
+ }
725
+ else {
726
+ acc.regularPages.push(mcpPage);
727
+ }
728
+ return acc;
729
+ }, { regularPages: [], extensionPages: [] });
730
+ const selectionFallback = context.getSelectedPageFallback();
731
+ if (selectionFallback) {
732
+ let selectedPageId;
733
+ try {
734
+ selectedPageId = context.getSelectedMcpPage().id;
735
+ }
736
+ catch {
737
+ selectedPageId = undefined;
738
+ }
739
+ response.push(`Note: the previously selected page ${selectionFallback.wasClosed ? 'was closed' : 'is no longer listed'}.${selectedPageId !== undefined ? ` Page ${selectedPageId} is now selected.` : ''}`);
740
+ }
741
+ const targetInfos = regularPages.length ||
742
+ (this.#includeExtensionPages && extensionPages.length)
743
+ ? await context.getTargetInfos()
744
+ : new Map();
745
+ if (regularPages.length) {
746
+ const parts = [`## Pages`];
747
+ const structuredPages = [];
748
+ for (const mcpPage of regularPages) {
749
+ const isolatedContextName = mcpPage.isolatedContextName;
750
+ const contextLabel = isolatedContextName
751
+ ? ` isolatedContext=${isolatedContextName}`
752
+ : '';
753
+ const page = formatPage(mcpPage, context, targetInfos.get(mcpPage.targetId));
754
+ parts.push(`${page.text}${context.isPageSelected(mcpPage) ? ' [selected]' : ''}${contextLabel}${formatWebAuthnLabel(mcpPage)}`);
755
+ structuredPages.push(page.structured);
756
+ }
757
+ response.push(...parts);
758
+ structuredContent.pages = structuredPages;
759
+ }
760
+ if (this.#includeExtensionPages) {
761
+ if (extensionPages.length) {
762
+ response.push(`## Extension Pages`);
763
+ const structuredExtensionPages = [];
764
+ for (const mcpPage of extensionPages) {
765
+ const isolatedContextName = mcpPage.isolatedContextName;
766
+ const contextLabel = isolatedContextName
767
+ ? ` isolatedContext=${isolatedContextName}`
768
+ : '';
769
+ const page = formatPage(mcpPage, context, targetInfos.get(mcpPage.targetId));
770
+ response.push(`${page.text}${context.isPageSelected(mcpPage) ? ' [selected]' : ''}${contextLabel}${formatWebAuthnLabel(mcpPage)}`);
771
+ structuredExtensionPages.push(page.structured);
772
+ }
773
+ structuredContent.extensionPages = structuredExtensionPages;
774
+ }
775
+ }
776
+ }
777
+ if (this.#includeExtensionServiceWorkers) {
778
+ const extensionServiceWorkers = context
779
+ .getWorkers()
780
+ .filter(worker => worker.type === 'service_worker');
781
+ if (extensionServiceWorkers.length) {
782
+ response.push(`## Extension Service Workers`);
783
+ }
784
+ for (const extensionServiceWorker of extensionServiceWorkers) {
785
+ response.push(`${extensionServiceWorker.id}: ${extensionServiceWorker.url}`);
786
+ }
787
+ structuredContent.extensionServiceWorkers = extensionServiceWorkers.map(extensionServiceWorker => {
788
+ return {
789
+ id: extensionServiceWorker.id,
790
+ url: extensionServiceWorker.url,
791
+ };
792
+ });
793
+ }
794
+ if (this.#tabId) {
795
+ structuredContent.tabId = this.#tabId;
796
+ }
797
+ if (data.traceSummary) {
798
+ const summary = getTraceSummary(data.traceSummary, this.#deviceScope);
799
+ response.push(summary);
800
+ structuredContent.traceSummary = summary;
801
+ structuredContent.traceInsights = [];
802
+ for (const insightSet of data.traceSummary.insights?.values() ?? []) {
803
+ for (const [insightName, model] of Object.entries(insightSet.model)) {
804
+ structuredContent.traceInsights.push({
805
+ insightName,
806
+ insightKey: typeof model === 'object' &&
807
+ model !== null &&
808
+ 'insightKey' in model
809
+ ? model.insightKey
810
+ : undefined,
811
+ });
812
+ }
813
+ }
814
+ }
815
+ if (data.traceInsight) {
816
+ const insightOutput = getInsightOutput(data.traceInsight.trace, data.traceInsight.insightSetId, data.traceInsight.insightName, this.#deviceScope);
817
+ if ('error' in insightOutput) {
818
+ response.push(insightOutput.error);
819
+ structuredContent.error = insightOutput.error;
820
+ }
821
+ else {
822
+ response.push(insightOutput.output);
823
+ structuredContent.traceInsight = insightOutput.output;
824
+ }
825
+ }
826
+ if (data.lighthouseResult) {
827
+ structuredContent.lighthouseResult = data.lighthouseResult;
828
+ const { summary, failedAudits, reports } = data.lighthouseResult;
829
+ response.push('## Lighthouse audit results');
830
+ response.push(`Mode: ${summary.mode}`);
831
+ response.push(`Device: ${summary.device}`);
832
+ response.push(`URL: ${summary.url}`);
833
+ response.push('### Category scores');
834
+ for (const score of summary.scores) {
835
+ // Lighthouse uses a null score for categories that could not be
836
+ // scored and renders scores as Math.round(score * 100).
837
+ const formattedScore = score.score === null ? 'n/a' : Math.round(score.score * 100);
838
+ response.push(`- ${score.title}: ${formattedScore} (${score.id})`);
839
+ }
840
+ response.push('### Audit summary');
841
+ response.push(`Passed: ${summary.audits.passed}`);
842
+ response.push(`Failed: ${summary.audits.failed}`);
843
+ response.push(`Total timing: ${summary.timing.total}ms`);
844
+ if (failedAudits.length) {
845
+ response.push('### Failed audits');
846
+ for (const audit of failedAudits) {
847
+ const categories = audit.categories.length
848
+ ? ` [${audit.categories.join(', ')}]`
849
+ : '';
850
+ const displayValue = audit.displayValue
851
+ ? ` (${audit.displayValue})`
852
+ : '';
853
+ response.push(`- ${audit.id}${categories}: ${audit.title}${displayValue} (score: ${audit.score})`);
854
+ if (audit.description) {
855
+ response.push(` ${collapseWhitespace(audit.description)}`);
856
+ }
857
+ if (audit.totalNodes) {
858
+ const shown = audit.totalNodes > audit.nodes.length
859
+ ? `, showing ${audit.nodes.length}`
860
+ : '';
861
+ response.push(` Nodes (${audit.totalNodes}${shown}):`);
862
+ }
863
+ for (const node of audit.nodes) {
864
+ // Values are JSON-encoded so that quotes or spaces within them
865
+ // cannot be confused with the `key=value` delimiters.
866
+ const parts = [];
867
+ if (node.selector) {
868
+ parts.push(`selector=${JSON.stringify(node.selector)}`);
869
+ }
870
+ if (node.nodeLabel) {
871
+ parts.push(`label=${JSON.stringify(collapseWhitespace(node.nodeLabel))}`);
872
+ }
873
+ if (node.snippet) {
874
+ parts.push(`snippet=${JSON.stringify(collapseWhitespace(node.snippet))}`);
875
+ }
876
+ response.push(` - ${parts.join(' ')}`);
877
+ if (node.explanation) {
878
+ response.push(` ${collapseWhitespace(node.explanation)}`);
879
+ }
880
+ }
881
+ }
882
+ }
883
+ response.push('### Reports');
884
+ for (const report of reports) {
885
+ response.push(`- ${report}`);
886
+ }
887
+ }
888
+ if (data.snapshot) {
889
+ if (typeof data.snapshot === 'string') {
890
+ response.push(`Saved snapshot to ${data.snapshot}.`);
891
+ structuredContent.snapshotFilePath = data.snapshot;
892
+ }
893
+ else {
894
+ structuredContent.snapshot = data.snapshot.toJSON();
895
+ response.push('## Latest page snapshot');
896
+ response.push(compactEncode
897
+ ? compactEncode(structuredContent.snapshot)
898
+ : data.snapshot.toString());
899
+ }
900
+ }
901
+ if (this.#heapSnapshotOptions?.include) {
902
+ response.push('## Heap Snapshot Data');
903
+ const formatOptions = this.#heapSnapshotOptions.formatOptions ?? {};
904
+ const stats = this.#heapSnapshotOptions.stats;
905
+ const staticData = this.#heapSnapshotOptions.staticData;
906
+ if (stats) {
907
+ response.push(`Statistics: ${JSON.stringify(stats, null, 2)}`);
908
+ structuredContent.heapSnapshot = structuredContent.heapSnapshot || {};
909
+ structuredContent.heapSnapshot.stats = stats;
910
+ }
911
+ if (staticData) {
912
+ response.push(`Static Data: ${JSON.stringify(staticData, null, 2)}`);
913
+ structuredContent.heapSnapshot = structuredContent.heapSnapshot || {};
914
+ structuredContent.heapSnapshot.staticData = staticData;
915
+ }
916
+ const nativeContextSizes = this.#heapSnapshotOptions.nativeContextSizes;
917
+ if (nativeContextSizes) {
918
+ response.push('### Native Contexts');
919
+ response.push(HeapSnapshotFormatter.formatNativeContextSizes(nativeContextSizes, formatOptions));
920
+ structuredContent.heapSnapshot = structuredContent.heapSnapshot || {};
921
+ structuredContent.heapSnapshot.nativeContextSizes = nativeContextSizes;
922
+ }
923
+ const retainedByContextSummary = this.#heapSnapshotOptions.retainedByContextSummary;
924
+ if (retainedByContextSummary) {
925
+ response.push('### Retained by Context Summary');
926
+ response.push(HeapSnapshotFormatter.formatRetainedByContextSummary(retainedByContextSummary));
927
+ structuredContent.heapSnapshot = structuredContent.heapSnapshot || {};
928
+ structuredContent.heapSnapshot.retainedByContextSummary =
929
+ retainedByContextSummary;
930
+ }
931
+ const aggregateData = this.#heapSnapshotOptions.aggregateData;
932
+ if (aggregateData) {
933
+ const paginationData = this.#dataWithPagination(aggregateData.aggregates, this.#heapSnapshotOptions.pagination);
934
+ response.push(`Objects: ${aggregateData.objectCount}`);
935
+ response.push(`Total shallow size: ${formatBytesToKb(aggregateData.totalSelfSize)}`);
936
+ structuredContent.heapSnapshot = structuredContent.heapSnapshot || {};
937
+ structuredContent.heapSnapshot.aggregateStats = {
938
+ objectCount: aggregateData.objectCount,
939
+ totalSelfSize: aggregateData.totalSelfSize,
940
+ };
941
+ structuredContent.pagination = paginationData.pagination;
942
+ response.push(...paginationData.info);
943
+ structuredContent.heapSnapshotAggregates = paginationData.items;
944
+ response.push(compactEncode
945
+ ? compactEncode(paginationData.items.map(aggregate => ({
946
+ ...aggregate,
947
+ className: formatName(aggregate.className, formatOptions),
948
+ })))
949
+ : HeapSnapshotFormatter.formatAggregates(paginationData.items, formatOptions));
950
+ }
951
+ const nodes = this.#heapSnapshotOptions.nodes;
952
+ if (nodes) {
953
+ let items = Array.from(nodes.items);
954
+ const firstItem = nodes.items[0];
955
+ if (firstItem) {
956
+ if (isNodeLike(firstItem)) {
957
+ items = items
958
+ .filter(isNodeLike)
959
+ .sort((a, b) => b.retainedSize - a.retainedSize);
960
+ }
961
+ else if (isEdgeLike(firstItem)) {
962
+ items = items.filter(isEdgeLike);
963
+ }
964
+ }
965
+ const paginationData = this.#dataWithPagination(items, this.#heapSnapshotOptions.pagination);
966
+ response.push(HeapSnapshotFormatter.formatNodes(paginationData.items, formatOptions));
967
+ structuredContent.pagination = paginationData.pagination;
968
+ response.push(...paginationData.info);
969
+ structuredContent.heapSnapshotNodes = paginationData.items;
970
+ }
971
+ const retainingPaths = this.#heapSnapshotOptions.retainingPaths;
972
+ if (retainingPaths) {
973
+ response.push('### Retaining Paths');
974
+ const { paths, limitsReached } = retainingPaths;
975
+ if (paths.length === 0) {
976
+ response.push('No retaining paths found.');
977
+ }
978
+ else {
979
+ response.push(HeapSnapshotFormatter.formatRetainingPaths(paths, formatOptions));
980
+ }
981
+ const reached = Object.entries(limitsReached)
982
+ .filter(([, hit]) => hit)
983
+ .map(([limit]) => limit);
984
+ if (reached.length > 0) {
985
+ response.push(`Note: results are truncated, the following limits were reached: ${reached.join(', ')}.`);
986
+ }
987
+ structuredContent.heapSnapshotRetainingPaths =
988
+ retainingPaths;
989
+ }
990
+ const dominators = this.#heapSnapshotOptions.dominators;
991
+ if (dominators) {
992
+ response.push('### Dominator Chain');
993
+ if (dominators.length === 0) {
994
+ response.push('No dominators found.');
995
+ }
996
+ else {
997
+ response.push(HeapSnapshotFormatter.formatDominators(dominators, formatOptions));
998
+ }
999
+ structuredContent.heapSnapshotDominators = dominators;
1000
+ }
1001
+ const diff = this.#heapSnapshotOptions.diff;
1002
+ if (diff) {
1003
+ response.push('### Heap Snapshot Diff');
1004
+ response.push(HeapSnapshotFormatter.formatDiffTotals(diff.totals));
1005
+ structuredContent.heapSnapshot = structuredContent.heapSnapshot || {};
1006
+ structuredContent.heapSnapshot.classDiffStats = diff.totals;
1007
+ const paginationData = this.#dataWithPagination(diff.classDiffs, this.#heapSnapshotOptions.pagination);
1008
+ structuredContent.pagination = paginationData.pagination;
1009
+ response.push(...paginationData.info);
1010
+ response.push(compactEncode
1011
+ ? compactEncode(paginationData.items.map(diff => ({
1012
+ ...diff,
1013
+ className: formatName(diff.className, formatOptions),
1014
+ })))
1015
+ : HeapSnapshotFormatter.formatDiffSummary(paginationData.items, formatOptions));
1016
+ structuredContent.heapSnapshotClassDiffs = paginationData.items;
1017
+ }
1018
+ const detailedClassDiff = this.#heapSnapshotOptions.detailedClassDiff;
1019
+ if (detailedClassDiff) {
1020
+ response.push('### Heap Snapshot Detailed Diff');
1021
+ const { classDiff, objects } = detailedClassDiff;
1022
+ const paginationData = this.#dataWithPagination(objects, this.#heapSnapshotOptions.pagination);
1023
+ structuredContent.pagination = paginationData.pagination;
1024
+ response.push(compactEncode
1025
+ ? compactEncode({
1026
+ ...classDiff,
1027
+ className: formatName(classDiff.className, formatOptions),
1028
+ })
1029
+ : HeapSnapshotFormatter.formatDetailedClassDiffHeader(classDiff, formatOptions));
1030
+ response.push(...paginationData.info);
1031
+ response.push(compactEncode
1032
+ ? compactEncode(paginationData.items)
1033
+ : HeapSnapshotFormatter.formatDetailedClassDiffObjects(paginationData.items));
1034
+ structuredContent.heapSnapshotDetailedClassDiff = {
1035
+ classDiff,
1036
+ objects: paginationData.items,
1037
+ };
1038
+ }
1039
+ const duplicateStrings = this.#heapSnapshotOptions.duplicateStrings;
1040
+ if (duplicateStrings) {
1041
+ response.push('### Duplicate Strings');
1042
+ const paginationData = this.#dataWithPagination(duplicateStrings, this.#heapSnapshotOptions.pagination);
1043
+ structuredContent.pagination = paginationData.pagination;
1044
+ response.push(...paginationData.info);
1045
+ const formatted = HeapSnapshotFormatter.formatDuplicateStrings(paginationData.items, formatOptions);
1046
+ response.push(formatted);
1047
+ structuredContent.heapSnapshotDuplicateStrings = paginationData.items;
1048
+ }
1049
+ const objectInfo = this.#heapSnapshotOptions.objectInfo;
1050
+ if (objectInfo) {
1051
+ response.push('### Object Details');
1052
+ if (compactEncode) {
1053
+ response.push(compactEncode({
1054
+ ...objectInfo,
1055
+ name: formatName(objectInfo.name, formatOptions),
1056
+ }));
1057
+ }
1058
+ else {
1059
+ response.push(HeapSnapshotFormatter.formatObjectInfo(objectInfo, formatOptions));
1060
+ }
1061
+ structuredContent.heapSnapshotObjectDetails = objectInfo;
1062
+ }
1063
+ const contextAnalysis = this.#heapSnapshotOptions.contextAnalysis;
1064
+ if (contextAnalysis) {
1065
+ const contextAnalysisOptions = this.#heapSnapshotOptions.contextAnalysisOptions;
1066
+ const rankedContexts = collectRankedContexts(contextAnalysis, {
1067
+ retainedSize: contextAnalysisOptions?.retainedSize,
1068
+ scopeInfoNodeId: contextAnalysisOptions?.scopeInfoNodeId,
1069
+ });
1070
+ const paginationData = this.#dataWithPagination(rankedContexts, {
1071
+ pageIdx: contextAnalysisOptions?.pageIdx ?? 0,
1072
+ pageSize: contextAnalysisOptions?.pageSize,
1073
+ });
1074
+ const report = {
1075
+ contexts: paginationData.items,
1076
+ scriptsWithoutScopes: contextAnalysis.scriptsWithoutScopes,
1077
+ };
1078
+ response.push('### Context Analysis');
1079
+ structuredContent.pagination = paginationData.pagination;
1080
+ response.push(...paginationData.info);
1081
+ response.push(compactEncode
1082
+ ? compactEncode(report)
1083
+ : HeapSnapshotFormatter.formatContextAnalysis(report, formatOptions));
1084
+ structuredContent.heapSnapshotContextAnalysis = report;
1085
+ }
1086
+ }
1087
+ if (data.detailedNetworkRequest) {
1088
+ response.push(data.detailedNetworkRequest.toStringDetailed());
1089
+ structuredContent.networkRequest =
1090
+ data.detailedNetworkRequest.toJSONDetailed();
1091
+ }
1092
+ if (data.detailedConsoleMessage) {
1093
+ response.push(data.detailedConsoleMessage.toStringDetailed());
1094
+ structuredContent.consoleMessage =
1095
+ data.detailedConsoleMessage.toJSONDetailed();
1096
+ }
1097
+ if (data.extensions) {
1098
+ const extensionArray = Array.from(data.extensions.values());
1099
+ structuredContent.extensions = extensionArray;
1100
+ response.push('## Extensions');
1101
+ if (extensionArray.length === 0) {
1102
+ response.push('No unpacked extensions found.');
1103
+ }
1104
+ else {
1105
+ const extensionsMessage = extensionArray
1106
+ .map(extension => {
1107
+ return `id=${extension.id} "${extension.name}" v${extension.version} ${extension.enabled ? 'Enabled' : 'Disabled'}`;
1108
+ })
1109
+ .join('\n');
1110
+ response.push(extensionsMessage);
1111
+ }
1112
+ }
1113
+ const thirdPartyDeveloperTools = data.thirdPartyDeveloperTools;
1114
+ if (this.#listThirdPartyDeveloperTools && thirdPartyDeveloperTools) {
1115
+ structuredContent.thirdPartyDeveloperTools = thirdPartyDeveloperTools;
1116
+ response.push('## Third-party developer tools');
1117
+ if (thirdPartyDeveloperTools.length === 0) {
1118
+ response.push('No third-party developer tools available.');
1119
+ }
1120
+ else {
1121
+ for (const toolGroup of thirdPartyDeveloperTools) {
1122
+ response.push(`${toolGroup.name}: ${toolGroup.description}`);
1123
+ response.push('Available tools:');
1124
+ const toolDefinitionsMessage = toolGroup.tools
1125
+ .map(tool => {
1126
+ return `name="${tool.name}", description="${tool.description}", inputSchema=${JSON.stringify(tool.inputSchema)}`;
1127
+ })
1128
+ .join('\n');
1129
+ response.push(toolDefinitionsMessage);
1130
+ }
1131
+ }
1132
+ }
1133
+ if (this.#listWebMcpTools && data.webmcpTools) {
1134
+ structuredContent.webmcpTools = data.webmcpTools.map(({ name, description, inputSchema, annotations }) => ({
1135
+ name,
1136
+ description,
1137
+ inputSchema,
1138
+ annotations,
1139
+ }));
1140
+ response.push('## WebMCP tools');
1141
+ if (data.webmcpTools.length === 0) {
1142
+ response.push('No WebMCP tools available.');
1143
+ }
1144
+ else {
1145
+ const webmcpToolsMessage = data.webmcpTools
1146
+ .map(tool => {
1147
+ return `name="${tool.name}", description="${tool.description}", inputSchema=${JSON.stringify(tool.inputSchema)}, annotations=${JSON.stringify(tool.annotations)}`;
1148
+ })
1149
+ .join('\n');
1150
+ response.push(webmcpToolsMessage);
1151
+ }
1152
+ }
1153
+ if (this.#networkRequestsOptions?.include && data.networkRequests) {
1154
+ const requests = data.networkRequests;
1155
+ response.push('## Network requests');
1156
+ if (requests.length) {
1157
+ const paginationData = this.#dataWithPagination(requests, this.#networkRequestsOptions.pagination);
1158
+ structuredContent.pagination = paginationData.pagination;
1159
+ response.push(...paginationData.info);
1160
+ if (data.networkRequests) {
1161
+ structuredContent.networkRequests = paginationData.items.map(i => i.toJSON());
1162
+ response.push(...(compactEncode
1163
+ ? [compactEncode(structuredContent.networkRequests)]
1164
+ : paginationData.items.map(i => i.toString())));
1165
+ }
1166
+ }
1167
+ else {
1168
+ response.push('No requests found.');
1169
+ }
1170
+ }
1171
+ if (this.#consoleDataOptions?.include) {
1172
+ const messages = data.consoleMessages ?? [];
1173
+ response.push('## Console messages');
1174
+ if (messages.length) {
1175
+ const grouped = ConsoleFormatter.groupConsecutive(messages);
1176
+ const paginationData = this.#dataWithPagination(grouped, this.#consoleDataOptions.pagination);
1177
+ structuredContent.pagination = paginationData.pagination;
1178
+ structuredContent.consoleMessages = paginationData.items.map(item => item.toJSON());
1179
+ response.push(...paginationData.info);
1180
+ if (compactEncode) {
1181
+ response.push(compactEncode(structuredContent.consoleMessages));
1182
+ }
1183
+ else {
1184
+ response.push(...paginationData.items.map(item => item.toString()));
1185
+ }
1186
+ if (structuredContent.consoleMessages.some(message => 'stackTrace' in message)) {
1187
+ response.push('Note: stack trace line and column numbers use 1-based indexing');
1188
+ }
1189
+ }
1190
+ else {
1191
+ response.push('<no console messages found>');
1192
+ }
1193
+ }
1194
+ if (data.consoleErrors?.length) {
1195
+ const grouped = ConsoleFormatter.groupConsecutive(data.consoleErrors);
1196
+ const shown = grouped.slice(0, MAX_CONSOLE_ERRORS);
1197
+ structuredContent.consoleErrors = shown.map(item => item.toJSON());
1198
+ response.push('## Console errors during this call');
1199
+ if (compactEncode) {
1200
+ response.push(compactEncode(structuredContent.consoleErrors));
1201
+ }
1202
+ else {
1203
+ response.push(...shown.map(item => item.toString()));
1204
+ }
1205
+ if (grouped.length > shown.length) {
1206
+ response.push(`${grouped.length - shown.length} more not shown. Call ${LIST_CONSOLE_MESSAGES_TOOL_NAME} to list them.`);
1207
+ }
1208
+ }
1209
+ if (data.comments) {
1210
+ const commentsJson = data.comments.toJSON();
1211
+ structuredContent.comments = commentsJson;
1212
+ response.push(compactEncode ? compactEncode(commentsJson) : data.comments.toString());
1213
+ if (data.commentsSnapshotRegenerated) {
1214
+ response.push(`Note: DevTools comments regenerated the ${data.commentsSnapshotRegenerated} text snapshot.`);
1215
+ structuredContent.commentsSnapshotRegenerated =
1216
+ data.commentsSnapshotRegenerated;
1217
+ }
1218
+ }
1219
+ if (this.#webAuthnFormatter) {
1220
+ structuredContent.webauthnAuthenticator =
1221
+ this.#webAuthnFormatter.toJSON();
1222
+ response.push(compactEncode
1223
+ ? compactEncode(structuredContent.webauthnAuthenticator)
1224
+ : this.#webAuthnFormatter.toString());
1225
+ }
1226
+ if (this.#cssStylesData) {
1227
+ const resolveUid = (backendNodeId) => this.#page?.textSnapshot?.resolveCdpElementId(backendNodeId);
1228
+ const containerDetails = await resolveContainerQueries(this.#cssStylesData.styles.matchedStyles, resolveUid);
1229
+ const options = {
1230
+ ...this.#cssStylesData.options,
1231
+ resolveUid,
1232
+ containerDetails,
1233
+ };
1234
+ const allRules = CssFormatter.collectRules(this.#cssStylesData.styles, options);
1235
+ let rules = allRules;
1236
+ const hasPagination = this.#cssStylesData.options.pageSize !== undefined ||
1237
+ this.#cssStylesData.options.pageIdx !== undefined;
1238
+ if (hasPagination) {
1239
+ const paginationData = this.#dataWithPagination(allRules, this.#cssStylesData.options);
1240
+ structuredContent.pagination = paginationData.pagination;
1241
+ response.push(...paginationData.info);
1242
+ rules = paginationData.items;
1243
+ }
1244
+ const formatter = new CssFormatter(this.#cssStylesData.styles, options, rules);
1245
+ structuredContent.matchedStyles = formatter.toJSON();
1246
+ if (compactEncode) {
1247
+ response.push(compactEncode(structuredContent.matchedStyles));
1248
+ }
1249
+ else {
1250
+ response.push(formatter.toString());
1251
+ }
1252
+ }
1253
+ if (data.errorMessage) {
1254
+ response.push(`Error: ${data.errorMessage}`);
1255
+ structuredContent.errorMessage = data.errorMessage;
1256
+ }
1257
+ const text = {
1258
+ type: 'text',
1259
+ text: response.join('\n'),
1260
+ };
1261
+ const images = this.#images.map(imageData => {
1262
+ return {
1263
+ type: 'image',
1264
+ ...imageData,
1265
+ };
1266
+ });
1267
+ return {
1268
+ content: [text, ...images],
1269
+ structuredContent,
1270
+ };
1271
+ }
1272
+ #dataWithPagination(data, pagination) {
1273
+ const response = [];
1274
+ const paginationResult = paginate(data, pagination);
1275
+ if (paginationResult.invalidPage) {
1276
+ response.push('Invalid page number provided. Showing first page.');
1277
+ }
1278
+ const { startIndex, endIndex, currentPage, totalPages } = paginationResult;
1279
+ const displayStartIndex = data.length === 0 ? 0 : startIndex + 1;
1280
+ response.push(`Showing ${displayStartIndex}-${endIndex} of ${data.length} (Page ${currentPage + 1} of ${totalPages}).`);
1281
+ if (pagination) {
1282
+ if (paginationResult.hasNextPage) {
1283
+ response.push(`Next page: ${currentPage + 1}`);
1284
+ }
1285
+ if (paginationResult.hasPreviousPage) {
1286
+ response.push(`Previous page: ${currentPage - 1}`);
1287
+ }
1288
+ }
1289
+ return {
1290
+ info: response,
1291
+ items: paginationResult.items,
1292
+ pagination: {
1293
+ currentPage: paginationResult.currentPage,
1294
+ totalPages: paginationResult.totalPages,
1295
+ hasNextPage: paginationResult.hasNextPage,
1296
+ hasPreviousPage: paginationResult.hasPreviousPage,
1297
+ startIndex: paginationResult.startIndex,
1298
+ endIndex: paginationResult.endIndex,
1299
+ invalidPage: paginationResult.invalidPage,
1300
+ },
1301
+ };
1302
+ }
1303
+ resetResponseLineForTesting() {
1304
+ this.#textResponseLines = [];
1305
+ }
1306
+ }
1307
+ function truncateTitle(title, maxLength = 50) {
1308
+ return truncateText(title, maxLength, { includeEllipsisInLength: true });
1309
+ }
1310
+ const collapseWhitespace = (value) => {
1311
+ return value.replace(/\s+/g, ' ').trim();
1312
+ };
1313
+ function formatPage(mcpPage, context, targetInfo) {
1314
+ const title = mcpPage.getTitle(targetInfo);
1315
+ const url = mcpPage.url();
1316
+ const pageLabel = title ? `${truncateTitle(title)} (${url})` : url;
1317
+ return {
1318
+ text: `${mcpPage.id}: ${pageLabel}`,
1319
+ structured: createStructuredPage(mcpPage, context, title),
1320
+ };
1321
+ }
1322
+ function getWebAuthnLabel(mcpPage) {
1323
+ const authenticator = mcpPage.getWebAuthnAuthenticator();
1324
+ return authenticator
1325
+ ? `${authenticator.protocol}/${authenticator.transport}`
1326
+ : undefined;
1327
+ }
1328
+ function formatWebAuthnLabel(mcpPage) {
1329
+ const label = getWebAuthnLabel(mcpPage);
1330
+ return label ? ` webauthn=${label}` : '';
1331
+ }
1332
+ function createStructuredPage(mcpPage, context, rawTitle) {
1333
+ const isolatedContextName = mcpPage.isolatedContextName;
1334
+ const title = truncateTitle(rawTitle);
1335
+ const entry = {
1336
+ id: mcpPage.id,
1337
+ url: mcpPage.url(),
1338
+ title,
1339
+ selected: context.isPageSelected(mcpPage),
1340
+ };
1341
+ if (isolatedContextName) {
1342
+ entry.isolatedContext = isolatedContextName;
1343
+ }
1344
+ const webAuthnLabel = getWebAuthnLabel(mcpPage);
1345
+ if (webAuthnLabel) {
1346
+ entry.webauthn = webAuthnLabel;
1347
+ }
1348
+ return entry;
1349
+ }
1350
+ //# sourceMappingURL=McpResponse.js.map