chrome-devtools-mcp 1.6.0 → 1.8.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 (313) hide show
  1. package/README.md +73 -22
  2. package/build/src/McpContext.js +121 -44
  3. package/build/src/McpPage.js +230 -14
  4. package/build/src/McpResponse.js +209 -283
  5. package/build/src/SlimMcpResponse.js +1 -1
  6. package/build/src/TextSnapshot.js +80 -19
  7. package/build/src/ToolHandler.js +80 -15
  8. package/build/src/bin/chrome-devtools-mcp-main.js +3 -3
  9. package/build/src/bin/chrome-devtools.js +47 -32
  10. package/build/src/browser.js +3 -1
  11. package/build/src/{PageCollector.js → collectors/PageCollector.js} +15 -10
  12. package/build/src/{ServiceWorkerCollector.js → collectors/ServiceWorkerCollector.js} +1 -1
  13. package/build/src/{bin/chrome-devtools-cli-options.js → config/cli-options.js} +414 -23
  14. package/build/src/{bin/chrome-devtools-mcp-cli-options.js → config/mcp-options.js} +74 -9
  15. package/build/src/daemon/client.js +33 -2
  16. package/build/src/daemon/daemon.js +17 -13
  17. package/build/src/daemon/utils.js +18 -3
  18. package/build/src/devtools/DevtoolsUtils.js +9 -16
  19. package/build/src/formatters/ConsoleFormatter.js +43 -10
  20. package/build/src/formatters/HeapSnapshotFormatter.js +58 -13
  21. package/build/src/formatters/IssueFormatter.js +1 -1
  22. package/build/src/formatters/NetworkFormatter.js +7 -7
  23. package/build/src/index.js +34 -5
  24. package/build/src/{HeapSnapshotManager.js → processors/HeapSnapshotManager.js} +82 -27
  25. package/build/src/{trace-processing/parse.js → processors/PerformanceTrace.js} +1 -1
  26. package/build/src/telemetry/ClearcutLogger.js +16 -1
  27. package/build/src/telemetry/flagUtils.js +4 -3
  28. package/build/src/telemetry/transformation.js +30 -0
  29. package/build/src/telemetry/types.js +4 -0
  30. package/build/src/third_party/THIRD_PARTY_NOTICES +235 -113
  31. package/build/src/third_party/bundled-packages.json +6 -7
  32. package/build/src/third_party/devtools-formatter-worker.js +60 -19
  33. package/build/src/third_party/devtools-heap-snapshot-worker.js +657 -224
  34. package/build/src/third_party/index.js +62484 -43814
  35. package/build/src/third_party/issue-descriptions/CoepCorpNotSameOrigin.md +2 -2
  36. package/build/src/third_party/issue-descriptions/CoepCorpNotSameOriginAfterDefaultedToSameOriginByCoep.md +3 -3
  37. package/build/src/third_party/issue-descriptions/CoepCorpNotSameSite.md +2 -2
  38. package/build/src/third_party/issue-descriptions/CoepFrameResourceNeedsCoepHeader.md +1 -1
  39. package/build/src/third_party/issue-descriptions/CompatibilityModeQuirks.md +1 -1
  40. package/build/src/third_party/issue-descriptions/CookieAttributeValueExceedsMaxSize.md +2 -2
  41. package/build/src/third_party/issue-descriptions/LowTextContrast.md +1 -1
  42. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureErrorRead.md +1 -1
  43. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureErrorSet.md +1 -1
  44. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureWarnRead.md +1 -1
  45. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureWarnSet.md +1 -1
  46. package/build/src/third_party/issue-descriptions/SameSiteUnspecifiedLaxAllowUnsafeRead.md +3 -3
  47. package/build/src/third_party/issue-descriptions/SameSiteUnspecifiedLaxAllowUnsafeSet.md +3 -3
  48. package/build/src/third_party/issue-descriptions/bounceTrackingMitigations.md +1 -1
  49. package/build/src/third_party/issue-descriptions/connectionAllowlistEmbeddingRequirementNotSatisfied.md +26 -0
  50. package/build/src/third_party/issue-descriptions/connectionAllowlistIFrameAttributeLoosensEmbeddingRequirement.md +19 -0
  51. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowConnectionAllowlistFrom.md +21 -0
  52. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowlistItemType.md +2 -2
  53. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidHeader.md +2 -2
  54. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidUrlPattern.md +3 -3
  55. package/build/src/third_party/issue-descriptions/connectionAllowlistItemNotInnerList.md +2 -2
  56. package/build/src/third_party/issue-descriptions/connectionAllowlistMoreThanOneList.md +2 -2
  57. package/build/src/third_party/issue-descriptions/connectionAllowlistReportingEndpointNotToken.md +1 -1
  58. package/build/src/third_party/issue-descriptions/cookieCrossSiteRedirectDowngrade.md +3 -3
  59. package/build/src/third_party/issue-descriptions/cookieExcludeBlockedWithinRelatedWebsiteSet.md +1 -1
  60. package/build/src/third_party/issue-descriptions/cookieExcludePortMismatch.md +1 -1
  61. package/build/src/third_party/issue-descriptions/cookieExcludeSchemeMismatch.md +1 -1
  62. package/build/src/third_party/issue-descriptions/cookieExcludeThirdPartyPhaseoutSet.md +1 -1
  63. package/build/src/third_party/issue-descriptions/cookieWarnThirdPartyPhaseoutRead.md +1 -1
  64. package/build/src/third_party/issue-descriptions/corsAllowCredentialsRequired.md +1 -1
  65. package/build/src/third_party/issue-descriptions/corsDisabledScheme.md +2 -2
  66. package/build/src/third_party/issue-descriptions/corsDisallowedByMode.md +2 -2
  67. package/build/src/third_party/issue-descriptions/corsHeaderDisallowedByPreflightResponse.md +1 -1
  68. package/build/src/third_party/issue-descriptions/corsInvalidHeaderValues.md +3 -3
  69. package/build/src/third_party/issue-descriptions/corsLocalNetworkAccessPermissionDenied.md +1 -1
  70. package/build/src/third_party/issue-descriptions/corsMethodDisallowedByPreflightResponse.md +1 -1
  71. package/build/src/third_party/issue-descriptions/corsNoCorsRedirectModeNotFollow.md +1 -1
  72. package/build/src/third_party/issue-descriptions/corsOriginMismatch.md +3 -3
  73. package/build/src/third_party/issue-descriptions/corsPreflightResponseInvalid.md +2 -2
  74. package/build/src/third_party/issue-descriptions/corsRedirectContainsCredentials.md +3 -3
  75. package/build/src/third_party/issue-descriptions/corsWildcardOriginNotAllowed.md +4 -3
  76. package/build/src/third_party/issue-descriptions/cspEvalViolation.md +4 -4
  77. package/build/src/third_party/issue-descriptions/cspInlineViolation.md +2 -2
  78. package/build/src/third_party/issue-descriptions/cspTrustedTypesPolicyViolation.md +2 -2
  79. package/build/src/third_party/issue-descriptions/cspTrustedTypesSinkViolation.md +4 -4
  80. package/build/src/third_party/issue-descriptions/cspURLViolation.md +4 -4
  81. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsEmptyList.md +1 -1
  82. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsHttpNotFound.md +1 -1
  83. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsInvalidContentType.md +1 -1
  84. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsInvalidResponse.md +1 -1
  85. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsNoResponse.md +1 -1
  86. package/build/src/third_party/issue-descriptions/emailVerificationRequestDnsFetchFailed.md +1 -1
  87. package/build/src/third_party/issue-descriptions/emailVerificationRequestDnsInvalidRecord.md +1 -1
  88. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownHttpNotFound.md +1 -1
  89. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownInvalidContentType.md +1 -1
  90. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownInvalidResponse.md +1 -1
  91. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownNoResponse.md +1 -1
  92. package/build/src/third_party/issue-descriptions/emailVerificationRequestInvalidEmail.md +1 -1
  93. package/build/src/third_party/issue-descriptions/emailVerificationRequestJwksHttpNotFound.md +1 -1
  94. package/build/src/third_party/issue-descriptions/emailVerificationRequestJwksInvalidResponse.md +1 -1
  95. package/build/src/third_party/issue-descriptions/emailVerificationRequestKeyBindingSigningFailed.md +1 -1
  96. package/build/src/third_party/issue-descriptions/emailVerificationRequestRpOriginIsOpaque.md +1 -1
  97. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenHttpNotFound.md +1 -1
  98. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidContentType.md +1 -1
  99. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidResponse.md +1 -1
  100. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidSdJwt.md +1 -1
  101. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenMalformedSdJwt.md +1 -1
  102. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenNoResponse.md +1 -1
  103. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidAudience.md +1 -1
  104. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidIssuedAt.md +1 -1
  105. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidNonce.md +1 -1
  106. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidSdHash.md +1 -1
  107. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidTyp.md +1 -1
  108. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingAud.md +1 -1
  109. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingCnf.md +1 -1
  110. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingIat.md +1 -1
  111. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingNonce.md +1 -1
  112. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingSdHash.md +1 -1
  113. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbSignatureFailed.md +1 -1
  114. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidEmail.md +1 -1
  115. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidEmailVerified.md +1 -1
  116. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidHolderKey.md +1 -1
  117. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidIssuedAt.md +1 -1
  118. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidIssuer.md +1 -1
  119. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtJwksMissingKeys.md +1 -1
  120. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingCnf.md +1 -1
  121. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingEmail.md +1 -1
  122. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingIat.md +1 -1
  123. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingIss.md +1 -1
  124. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtSignatureFailed.md +1 -1
  125. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtUnsupportedHeaderAlg.md +1 -1
  126. package/build/src/third_party/issue-descriptions/emailVerificationRequestUserLoggedOut.md +1 -1
  127. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownAccountsEndpointCrossOrigin.md +1 -1
  128. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownHttpNotFound.md +1 -1
  129. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownInvalidContentType.md +1 -1
  130. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownInvalidResponse.md +1 -1
  131. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownIssuanceEndpointCrossOrigin.md +1 -1
  132. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownListEmpty.md +1 -1
  133. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownMissingAccountsEndpoint.md +1 -1
  134. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownMissingIssuanceEndpoint.md +1 -1
  135. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownNoResponse.md +1 -1
  136. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownUnsupportedSigningAlgorithm.md +1 -1
  137. package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsBlockedByConnectionAllowlist.md +1 -0
  138. package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsHttpNotFound.md +1 -1
  139. package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsInvalidResponse.md +1 -1
  140. package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsNoResponse.md +1 -1
  141. package/build/src/third_party/issue-descriptions/federatedAuthRequestApprovalDeclined.md +1 -1
  142. package/build/src/third_party/issue-descriptions/federatedAuthRequestCanceled.md +1 -1
  143. package/build/src/third_party/issue-descriptions/federatedAuthRequestConfigBlockedByConnectionAllowlist.md +1 -0
  144. package/build/src/third_party/issue-descriptions/federatedAuthRequestErrorFetchingSignin.md +1 -1
  145. package/build/src/third_party/issue-descriptions/federatedAuthRequestErrorIdToken.md +1 -1
  146. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenBlockedByConnectionAllowlist.md +1 -0
  147. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenHttpNotFound.md +1 -1
  148. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenInvalidRequest.md +1 -1
  149. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenInvalidResponse.md +1 -1
  150. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenNoResponse.md +1 -1
  151. package/build/src/third_party/issue-descriptions/federatedAuthRequestInvalidSigninResponse.md +1 -1
  152. package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestHttpNotFound.md +1 -1
  153. package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestInvalidResponse.md +1 -1
  154. package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestNoResponse.md +1 -1
  155. package/build/src/third_party/issue-descriptions/federatedAuthRequestTooManyRequests.md +1 -1
  156. package/build/src/third_party/issue-descriptions/federatedAuthRequestWellKnownBlockedByConnectionAllowlist.md +1 -0
  157. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestInvalidAccountsResponse.md +1 -1
  158. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestInvalidConfigOrWellKnown.md +1 -1
  159. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoAccountSharingPermission.md +1 -1
  160. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoApiPermission.md +1 -1
  161. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoReturningUserFromFetchedAccounts.md +1 -1
  162. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotIframe.md +1 -1
  163. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotPotentiallyTrustworthy.md +1 -1
  164. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotSameOrigin.md +1 -1
  165. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotSignedInWithIdp.md +1 -1
  166. package/build/src/third_party/issue-descriptions/fetchingPartitionedBlobURL.md +2 -2
  167. package/build/src/third_party/issue-descriptions/genericFormAriaLabelledByToNonExistingIdError.md +2 -2
  168. package/build/src/third_party/issue-descriptions/genericFormAutocompleteAttributeEmptyError.md +1 -1
  169. package/build/src/third_party/issue-descriptions/genericFormDuplicateIdForInputError.md +1 -1
  170. package/build/src/third_party/issue-descriptions/genericFormEmptyIdAndNameAttributesForInputError.md +2 -2
  171. package/build/src/third_party/issue-descriptions/genericFormInputAssignedAutocompleteValueToIdOrNameAttributeError.md +2 -2
  172. package/build/src/third_party/issue-descriptions/genericFormInputHasWrongButWellIntendedAutocompleteValueError.md +1 -1
  173. package/build/src/third_party/issue-descriptions/genericFormInputWithNoLabelError.md +1 -1
  174. package/build/src/third_party/issue-descriptions/genericFormLabelForMatchesNonExistingIdError.md +2 -2
  175. package/build/src/third_party/issue-descriptions/genericFormLabelForNameError.md +1 -1
  176. package/build/src/third_party/issue-descriptions/genericFormLabelHasNeitherForNorNestedInputError.md +1 -1
  177. package/build/src/third_party/issue-descriptions/genericFormModelContextMissingToolName.md +1 -1
  178. package/build/src/third_party/issue-descriptions/genericFormModelContextParameterMissingName.md +1 -1
  179. package/build/src/third_party/issue-descriptions/genericFormModelContextRequiredParameterMissingName.md +1 -1
  180. package/build/src/third_party/issue-descriptions/genericNavigationEntryMarkedSkippable.md +2 -2
  181. package/build/src/third_party/issue-descriptions/heavyAd.md +1 -1
  182. package/build/src/third_party/issue-descriptions/lazyLoadImageZeroSize.md +7 -0
  183. package/build/src/third_party/issue-descriptions/navigatingPartitionedBlobURL.md +3 -3
  184. package/build/src/third_party/issue-descriptions/permissionElementActivationDisabled.md +1 -1
  185. package/build/src/third_party/issue-descriptions/permissionElementActivationDisabledWithOccluder.md +1 -1
  186. package/build/src/third_party/issue-descriptions/permissionElementActivationDisabledWithOccluderParent.md +1 -1
  187. package/build/src/third_party/issue-descriptions/permissionElementFencedFrameDisallowed.md +2 -2
  188. package/build/src/third_party/issue-descriptions/permissionElementFontSizeTooLarge.md +2 -2
  189. package/build/src/third_party/issue-descriptions/permissionElementFontSizeTooSmall.md +2 -2
  190. package/build/src/third_party/issue-descriptions/permissionElementInsetBoxShadowUnsupported.md +1 -1
  191. package/build/src/third_party/issue-descriptions/permissionElementInvalidDisplayStyle.md +2 -2
  192. package/build/src/third_party/issue-descriptions/permissionElementInvalidSizeValue.md +2 -2
  193. package/build/src/third_party/issue-descriptions/permissionElementInvalidType.md +2 -2
  194. package/build/src/third_party/issue-descriptions/permissionElementInvalidTypeActivation.md +2 -2
  195. package/build/src/third_party/issue-descriptions/permissionElementNonOpaqueColor.md +1 -1
  196. package/build/src/third_party/issue-descriptions/permissionElementPaddingBottomUnsupported.md +2 -2
  197. package/build/src/third_party/issue-descriptions/permissionElementPaddingRightUnsupported.md +2 -2
  198. package/build/src/third_party/issue-descriptions/permissionElementRequestInProgress.md +2 -2
  199. package/build/src/third_party/issue-descriptions/permissionElementSecurityChecksFailed.md +1 -1
  200. package/build/src/third_party/issue-descriptions/permissionElementTypeNotSupported.md +2 -2
  201. package/build/src/third_party/issue-descriptions/permissionElementUntrustedEvent.md +1 -1
  202. package/build/src/third_party/issue-descriptions/placeholderDescriptionForInvisibleIssues.md +1 -1
  203. package/build/src/third_party/issue-descriptions/selectElementAccessibilityDisallowedOptGroupChild.md +1 -1
  204. package/build/src/third_party/issue-descriptions/selectElementAccessibilityDisallowedSelectChild.md +1 -1
  205. package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentAttributesSelectDescendant.md +1 -1
  206. package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentLegendChild.md +1 -1
  207. package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentOptionChild.md +1 -1
  208. package/build/src/third_party/issue-descriptions/selectElementAccessibilityNonPhrasingContentOptionChild.md +1 -1
  209. package/build/src/third_party/issue-descriptions/selectivePermissionsIntervention.md +3 -3
  210. package/build/src/third_party/issue-descriptions/sharedArrayBuffer.md +1 -1
  211. package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorCrossOriginNoCorsRequest.md +1 -1
  212. package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorMatchingDictionaryNotUsed.md +1 -1
  213. package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorUnexpectedContentDictionaryHeader.md +1 -1
  214. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorCossOriginNoCorsRequest.md +1 -1
  215. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorDisallowedBySettings.md +1 -1
  216. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorExpiredResponse.md +1 -1
  217. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorFeatureDisabled.md +2 -2
  218. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorInvalidStructuredHeader.md +1 -1
  219. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNavigationRequest.md +2 -2
  220. package/build/src/third_party/issue-descriptions/sriInvalidSignatureHeader.md +4 -4
  221. package/build/src/third_party/issue-descriptions/sriInvalidSignatureInputHeader.md +4 -4
  222. package/build/src/third_party/issue-descriptions/sriMissingSignatureHeader.md +1 -1
  223. package/build/src/third_party/issue-descriptions/sriMissingSignatureInputHeader.md +2 -2
  224. package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsIncorrectLength.md +2 -2
  225. package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsNotByteSequence.md +4 -4
  226. package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsParameterized.md +4 -4
  227. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidComponentName.md +1 -1
  228. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidComponentType.md +2 -2
  229. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidDerivedComponentParameter.md +1 -1
  230. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidHeaderComponentParameter.md +1 -1
  231. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidParameter.md +2 -2
  232. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderKeyIdLength.md +5 -5
  233. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderMissingLabel.md +3 -3
  234. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderMissingRequiredParameters.md +2 -2
  235. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderValueMissingComponents.md +2 -2
  236. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderValueNotInnerList.md +2 -2
  237. package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +4 -4
  238. package/build/src/third_party/issue-descriptions/sriValidationFailedInvalidLength.md +3 -3
  239. package/build/src/third_party/issue-descriptions/sriValidationFailedSignatureExpired.md +2 -2
  240. package/build/src/third_party/issue-descriptions/sriValidationFailedSignatureMismatch.md +2 -2
  241. package/build/src/third_party/issue-descriptions/stylesheetLateImport.md +1 -1
  242. package/build/src/third_party/issue-descriptions/summaryElementAccessibilityInteractiveContentSummaryDescendant.md +1 -1
  243. package/build/src/third_party/issue-descriptions/unencodedDigestIncorrectDigestLength.md +2 -2
  244. package/build/src/third_party/issue-descriptions/unencodedDigestIncorrectDigestType.md +3 -3
  245. package/build/src/third_party/issue-descriptions/unencodedDigestMalformedDictionary.md +2 -2
  246. package/build/src/third_party/issue-descriptions/unencodedDigestUnknownAlgorithm.md +1 -1
  247. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +1125 -1027
  248. package/build/src/tools/categories.js +3 -0
  249. package/build/src/tools/console.js +9 -3
  250. package/build/src/tools/emulation.js +2 -2
  251. package/build/src/tools/extensions.js +7 -5
  252. package/build/src/tools/input.js +222 -120
  253. package/build/src/tools/lighthouse.js +3 -1
  254. package/build/src/tools/memory.js +144 -17
  255. package/build/src/tools/network.js +6 -3
  256. package/build/src/tools/pages.js +13 -16
  257. package/build/src/tools/performance.js +57 -46
  258. package/build/src/tools/pwa.js +128 -0
  259. package/build/src/tools/screencast.js +6 -4
  260. package/build/src/tools/screenshot.js +192 -84
  261. package/build/src/tools/script.js +118 -34
  262. package/build/src/tools/slim/tools.js +3 -3
  263. package/build/src/tools/snapshot.js +5 -3
  264. package/build/src/tools/thirdPartyDeveloper.js +2 -2
  265. package/build/src/tools/tools.js +2 -0
  266. package/build/src/tools/webmcp.js +2 -2
  267. package/build/src/utils/WaitForHelper.js +299 -0
  268. package/build/src/utils/bytes.js +105 -0
  269. package/build/src/utils/logger.js +25 -11
  270. package/build/src/utils/polyfill.js +6 -3
  271. package/build/src/utils/url.js +43 -0
  272. package/build/src/version.js +1 -1
  273. package/package.json +37 -25
  274. package/skills/a11y-debugging/SKILL.md +2 -0
  275. package/skills/chrome-devtools/SKILL.md +5 -4
  276. package/skills/chrome-devtools-cli/SKILL.md +109 -64
  277. package/skills/debug-optimize-lcp/SKILL.md +9 -9
  278. package/skills/memory-leak-debugging/SKILL.md +14 -18
  279. package/skills/memory-leak-debugging/references/common-leaks.md +1 -1
  280. package/skills/troubleshooting/SKILL.md +1 -0
  281. package/build/src/WaitForHelper.js +0 -200
  282. package/build/src/devtools/DevToolsConnectionAdapter.js +0 -70
  283. package/build/src/third_party/issue-descriptions/SameSiteExcludeContextDowngradeRead.md +0 -8
  284. package/build/src/third_party/issue-descriptions/SameSiteExcludeContextDowngradeSet.md +0 -8
  285. package/build/src/third_party/issue-descriptions/SameSiteExcludeNavigationContextDowngrade.md +0 -8
  286. package/build/src/third_party/issue-descriptions/SameSiteWarnCrossDowngradeRead.md +0 -8
  287. package/build/src/third_party/issue-descriptions/SameSiteWarnCrossDowngradeSet.md +0 -8
  288. package/build/src/third_party/issue-descriptions/SameSiteWarnStrictLaxDowngradeStrict.md +0 -8
  289. package/build/src/third_party/issue-descriptions/arInsecureContext.md +0 -7
  290. package/build/src/third_party/issue-descriptions/arInvalidInfoHeader.md +0 -5
  291. package/build/src/third_party/issue-descriptions/arInvalidRegisterOsSourceHeader.md +0 -5
  292. package/build/src/third_party/issue-descriptions/arInvalidRegisterOsTriggerHeader.md +0 -5
  293. package/build/src/third_party/issue-descriptions/arInvalidRegisterSourceHeader.md +0 -5
  294. package/build/src/third_party/issue-descriptions/arInvalidRegisterTriggerHeader.md +0 -5
  295. package/build/src/third_party/issue-descriptions/arNavigationRegistrationUniqueScopeAlreadySet.md +0 -5
  296. package/build/src/third_party/issue-descriptions/arNavigationRegistrationWithoutTransientUserActivation.md +0 -6
  297. package/build/src/third_party/issue-descriptions/arNoRegisterOsSourceHeader.md +0 -5
  298. package/build/src/third_party/issue-descriptions/arNoRegisterOsTriggerHeader.md +0 -5
  299. package/build/src/third_party/issue-descriptions/arNoRegisterSourceHeader.md +0 -5
  300. package/build/src/third_party/issue-descriptions/arNoRegisterTriggerHeader.md +0 -5
  301. package/build/src/third_party/issue-descriptions/arNoWebOrOsSupport.md +0 -4
  302. package/build/src/third_party/issue-descriptions/arOsSourceIgnored.md +0 -18
  303. package/build/src/third_party/issue-descriptions/arOsTriggerIgnored.md +0 -19
  304. package/build/src/third_party/issue-descriptions/arPermissionPolicyDisabled.md +0 -8
  305. package/build/src/third_party/issue-descriptions/arSourceAndTriggerHeaders.md +0 -9
  306. package/build/src/third_party/issue-descriptions/arSourceIgnored.md +0 -13
  307. package/build/src/third_party/issue-descriptions/arTriggerIgnored.md +0 -12
  308. package/build/src/third_party/issue-descriptions/arUntrustworthyReportingOrigin.md +0 -10
  309. package/build/src/third_party/issue-descriptions/arWebAndOsHeaders.md +0 -11
  310. package/build/src/utils/Mutex.js +0 -38
  311. package/build/src/utils/string.js +0 -37
  312. package/skills/memory-leak-debugging/references/compare_snapshots.js +0 -109
  313. package/skills/memory-leak-debugging/references/memlab.md +0 -29
@@ -3,20 +3,81 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
7
+ if (value !== null && value !== void 0) {
8
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
9
+ var dispose, inner;
10
+ if (async) {
11
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
12
+ dispose = value[Symbol.asyncDispose];
13
+ }
14
+ if (dispose === void 0) {
15
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
16
+ dispose = value[Symbol.dispose];
17
+ if (async) inner = dispose;
18
+ }
19
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
20
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
21
+ env.stack.push({ value: value, dispose: dispose, async: async });
22
+ }
23
+ else if (async) {
24
+ env.stack.push({ async: true });
25
+ }
26
+ return value;
27
+ };
28
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
29
+ return function (env) {
30
+ function fail(e) {
31
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
32
+ env.hasError = true;
33
+ }
34
+ var r, s = 0;
35
+ function next() {
36
+ while (r = env.stack.pop()) {
37
+ try {
38
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
39
+ if (r.dispose) {
40
+ var result = r.dispose.call(r.value);
41
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
42
+ }
43
+ else s |= 1;
44
+ }
45
+ catch (e) {
46
+ fail(e);
47
+ }
48
+ }
49
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
50
+ if (env.hasError) throw env.error;
51
+ }
52
+ return next();
53
+ };
54
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
55
+ var e = new Error(message);
56
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
+ });
6
58
  import { zod } from '../third_party/index.js';
7
59
  import { ToolCategory } from './categories.js';
8
60
  import { defineTool, pageIdSchema } from './ToolDefinition.js';
9
61
  export const evaluateScript = defineTool(cliArgs => {
10
62
  return {
11
63
  name: 'evaluate_script',
12
- description: `Evaluate a JavaScript function inside the currently selected page${cliArgs?.categoryExtensions ? ' or service worker' : ''}. Returns the response as JSON, so returned values have to be JSON-serializable.`,
64
+ description: `Evaluate a JavaScript function inside the target page${cliArgs?.categoryExtensions ? ' or service worker' : ''}. Returns the response as JSON, so returned values have to be JSON-serializable.`,
13
65
  annotations: {
14
66
  category: ToolCategory.DEBUGGING,
15
67
  readOnlyHint: false,
16
68
  },
17
69
  schema: {
18
- ...(cliArgs?.experimentalPageIdRouting ? pageIdSchema : {}),
19
- function: zod.string().describe(`A JavaScript function declaration to be executed by the tool in the currently selected page.
70
+ ...(cliArgs?.pageIdRouting
71
+ ? cliArgs.categoryExtensions
72
+ ? {
73
+ pageId: zod
74
+ .number()
75
+ .optional()
76
+ .describe('Targets a specific page by ID. Required when not evaluating in a service worker.'),
77
+ }
78
+ : pageIdSchema
79
+ : {}),
80
+ function: zod.string().describe(`A JavaScript function declaration to be executed by the tool in the target page.
20
81
  Example without arguments: \`() => document.title\` or \`async () => await fetch("example.com")\`.
21
82
  Example with arguments: \`(el) => el.innerText\`
22
83
  `),
@@ -34,6 +95,10 @@ Example with arguments: \`(el) => el.innerText\`
34
95
  .string()
35
96
  .optional()
36
97
  .describe('Handle dialogs while execution. "accept", "dismiss", or string for response of window.prompt. Defaults to accept.'),
98
+ waitForStableDom: zod
99
+ .boolean()
100
+ .optional()
101
+ .describe('Whether to wait for the DOM to settle. Pass false if the script only reads data. Defaults to true.'),
37
102
  ...(cliArgs?.categoryExtensions
38
103
  ? {
39
104
  serviceWorkerId: zod
@@ -44,41 +109,51 @@ Example with arguments: \`(el) => el.innerText\`
44
109
  : {}),
45
110
  },
46
111
  blockedByDialog: true,
47
- verifyFilesSchema: ['filePath'],
112
+ verifyFilesSchema: {
113
+ filePath: true,
114
+ },
48
115
  handler: async (request, response, context) => {
49
- const { serviceWorkerId, args: uidArgs, function: fnString, pageId, dialogAction, filePath, } = request.params;
50
- if (cliArgs?.categoryExtensions && serviceWorkerId) {
51
- if (uidArgs && uidArgs.length > 0) {
52
- throw new Error('args (element uids) cannot be used when evaluating in a service worker.');
116
+ const env_1 = { stack: [], error: void 0, hasError: false };
117
+ try {
118
+ const { serviceWorkerId, args: uidArgs, function: fnString, pageId, dialogAction, filePath, waitForStableDom, } = request.params;
119
+ if (cliArgs?.categoryExtensions && serviceWorkerId) {
120
+ if (uidArgs && uidArgs.length > 0) {
121
+ throw new Error('args (element uids) cannot be used when evaluating in a service worker.');
122
+ }
123
+ if (pageId) {
124
+ throw new Error('specify either a pageId or a serviceWorkerId.');
125
+ }
126
+ const worker = await getWebWorker(context, serviceWorkerId);
127
+ const result = await context
128
+ .getSelectedMcpPage()
129
+ .waitForEventsAfterAction(async () => {
130
+ await performEvaluation(worker, fnString, [], response, {
131
+ filePath,
132
+ context,
133
+ });
134
+ },
135
+ // Service workers cannot interact with the DOM, so never wait for it.
136
+ { handleDialog: dialogAction ?? 'accept', waitForStableDom: false });
137
+ if (result.dialogHandled) {
138
+ context.getSelectedMcpPage().clearDialog();
139
+ }
140
+ response.attachWaitForResult(result);
141
+ return;
53
142
  }
54
- if (pageId) {
143
+ if (cliArgs?.categoryExtensions && cliArgs?.pageIdRouting && !pageId) {
55
144
  throw new Error('specify either a pageId or a serviceWorkerId.');
56
145
  }
57
- const worker = await getWebWorker(context, serviceWorkerId);
58
- const result = await context
59
- .getSelectedMcpPage()
60
- .waitForEventsAfterAction(async () => {
61
- await performEvaluation(worker, fnString, [], response, {
62
- filePath,
63
- context,
64
- });
65
- }, { handleDialog: dialogAction ?? 'accept' });
66
- if (result.dialogHandled) {
67
- context.getSelectedMcpPage().clearDialog();
68
- }
69
- response.attachWaitForResult(result);
70
- return;
71
- }
72
- const mcpPage = cliArgs?.experimentalPageIdRouting
73
- ? context.getPageById(request.params.pageId)
74
- : context.getSelectedMcpPage();
75
- const page = mcpPage.pptrPage;
76
- const args = [];
77
- try {
146
+ const mcpPage = cliArgs?.pageIdRouting && request.params.pageId
147
+ ? context.getPageById(request.params.pageId)
148
+ : context.getSelectedMcpPage();
149
+ const page = mcpPage.pptrPage;
150
+ const args = [];
151
+ const stack = __addDisposableResource(env_1, new DisposableStack(), false);
78
152
  const frames = new Set();
79
153
  for (const uid of uidArgs ?? []) {
80
154
  const handle = await mcpPage.getElementByUid(uid);
81
155
  frames.add(handle.frame);
156
+ stack.use(handle);
82
157
  args.push(handle);
83
158
  }
84
159
  const evaluatable = await getPageOrFrame(page, frames);
@@ -87,18 +162,23 @@ Example with arguments: \`(el) => el.innerText\`
87
162
  filePath,
88
163
  context,
89
164
  });
90
- }, { handleDialog: dialogAction ?? 'accept' });
165
+ }, { handleDialog: dialogAction ?? 'accept', waitForStableDom });
91
166
  response.attachWaitForResult(result);
92
167
  }
168
+ catch (e_1) {
169
+ env_1.error = e_1;
170
+ env_1.hasError = true;
171
+ }
93
172
  finally {
94
- void Promise.allSettled(args.map(arg => arg.dispose()));
173
+ __disposeResources(env_1);
95
174
  }
96
175
  },
97
176
  };
98
177
  });
99
178
  const performEvaluation = async (evaluatable, fnString, args, response, options) => {
100
- const fn = await evaluatable.evaluateHandle(`(${fnString})`);
179
+ const env_2 = { stack: [], error: void 0, hasError: false };
101
180
  try {
181
+ const fn = __addDisposableResource(env_2, await evaluatable.evaluateHandle(`(${fnString})`), false);
102
182
  const result = await evaluatable.evaluate(async (fn, ...args) => {
103
183
  // @ts-expect-error no types for function fn
104
184
  return JSON.stringify(await fn(...args));
@@ -115,8 +195,12 @@ const performEvaluation = async (evaluatable, fnString, args, response, options)
115
195
  response.appendResponseLine('```');
116
196
  }
117
197
  }
198
+ catch (e_2) {
199
+ env_2.error = e_2;
200
+ env_2.hasError = true;
201
+ }
118
202
  finally {
119
- void fn.dispose();
203
+ __disposeResources(env_2);
120
204
  }
121
205
  };
122
206
  const getPageOrFrame = async (page, frames) => {
@@ -16,7 +16,7 @@ export const screenshot = definePageTool({
16
16
  },
17
17
  schema: {},
18
18
  blockedByDialog: true,
19
- verifyFilesSchema: [],
19
+ verifyFilesSchema: {},
20
20
  handler: async (request, response, context) => {
21
21
  const page = request.page;
22
22
  const screenshot = await page.pptrPage.screenshot({
@@ -38,7 +38,7 @@ export const navigate = definePageTool({
38
38
  url: zod.string().describe('URL to navigate to'),
39
39
  },
40
40
  blockedByDialog: false,
41
- verifyFilesSchema: [],
41
+ verifyFilesSchema: {},
42
42
  handler: async (request, response) => {
43
43
  const page = request.page;
44
44
  const options = {
@@ -73,7 +73,7 @@ export const evaluate = definePageTool({
73
73
  script: zod.string().describe(`JS script to run on the page`),
74
74
  },
75
75
  blockedByDialog: true,
76
- verifyFilesSchema: [],
76
+ verifyFilesSchema: {},
77
77
  handler: async (request, response) => {
78
78
  const page = request.page;
79
79
  try {
@@ -8,7 +8,7 @@ import { ToolCategory } from './categories.js';
8
8
  import { definePageTool, timeoutSchema } from './ToolDefinition.js';
9
9
  export const takeSnapshot = definePageTool({
10
10
  name: 'take_snapshot',
11
- description: `Take a text snapshot of the currently selected page based on the a11y tree. The snapshot lists page elements along with a unique
11
+ description: `Take a text snapshot of the target page based on the a11y tree. The snapshot lists page elements along with a unique
12
12
  identifier (uid). Always use the latest snapshot. Prefer taking a snapshot over taking a screenshot. The snapshot indicates the element selected
13
13
  in the DevTools Elements panel (if any).`,
14
14
  annotations: {
@@ -27,7 +27,9 @@ in the DevTools Elements panel (if any).`,
27
27
  .describe('The absolute path, or a path relative to the current working directory, to save the snapshot to instead of attaching it to the response.'),
28
28
  },
29
29
  blockedByDialog: true,
30
- verifyFilesSchema: ['filePath'],
30
+ verifyFilesSchema: {
31
+ filePath: true,
32
+ },
31
33
  handler: async (request, response) => {
32
34
  response.includeSnapshot({
33
35
  verbose: request.params.verbose ?? false,
@@ -50,7 +52,7 @@ export const waitFor = definePageTool({
50
52
  ...timeoutSchema,
51
53
  },
52
54
  blockedByDialog: true,
53
- verifyFilesSchema: [],
55
+ verifyFilesSchema: {},
54
56
  handler: async (request, response) => {
55
57
  const page = request.page;
56
58
  await page.waitForTextOnPage(request.params.text, request.params.timeout);
@@ -21,7 +21,7 @@ third-party developer tools with additional functionality.`,
21
21
  },
22
22
  schema: {},
23
23
  blockedByDialog: false,
24
- verifyFilesSchema: [],
24
+ verifyFilesSchema: {},
25
25
  handler: async (_request, response) => {
26
26
  response.setListThirdPartyDeveloperTools();
27
27
  },
@@ -41,7 +41,7 @@ export const executeThirdPartyDeveloperTool = definePageTool({
41
41
  .describe('The JSON-stringified parameters to pass to the tool'),
42
42
  },
43
43
  blockedByDialog: false,
44
- verifyFilesSchema: [],
44
+ verifyFilesSchema: {},
45
45
  handler: async (request, response) => {
46
46
  const toolName = request.params.toolName;
47
47
  let params = {};
@@ -12,6 +12,7 @@ import * as memoryTools from './memory.js';
12
12
  import * as networkTools from './network.js';
13
13
  import * as pagesTools from './pages.js';
14
14
  import * as performanceTools from './performance.js';
15
+ import * as pwaTools from './pwa.js';
15
16
  import * as screencastTools from './screencast.js';
16
17
  import * as screenshotTools from './screenshot.js';
17
18
  import * as scriptTools from './script.js';
@@ -32,6 +33,7 @@ export const createTools = (args) => {
32
33
  ...Object.values(networkTools),
33
34
  ...Object.values(pagesTools),
34
35
  ...Object.values(performanceTools),
36
+ ...Object.values(pwaTools),
35
37
  ...Object.values(screencastTools),
36
38
  ...Object.values(screenshotTools),
37
39
  ...Object.values(scriptTools),
@@ -15,7 +15,7 @@ export const listWebMcpTools = definePageTool({
15
15
  },
16
16
  schema: {},
17
17
  blockedByDialog: false,
18
- verifyFilesSchema: [],
18
+ verifyFilesSchema: {},
19
19
  handler: async (_request, response) => {
20
20
  response.setListWebMcpTools();
21
21
  },
@@ -35,7 +35,7 @@ export const executeWebMcpTool = definePageTool({
35
35
  .describe('The JSON-stringified parameters to pass to the WebMCP tool'),
36
36
  },
37
37
  blockedByDialog: false,
38
- verifyFilesSchema: [],
38
+ verifyFilesSchema: {},
39
39
  handler: async (request, response) => {
40
40
  const toolName = request.params.toolName;
41
41
  let input = {};
@@ -0,0 +1,299 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
7
+ if (value !== null && value !== void 0) {
8
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
9
+ var dispose, inner;
10
+ if (async) {
11
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
12
+ dispose = value[Symbol.asyncDispose];
13
+ }
14
+ if (dispose === void 0) {
15
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
16
+ dispose = value[Symbol.dispose];
17
+ if (async) inner = dispose;
18
+ }
19
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
20
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
21
+ env.stack.push({ value: value, dispose: dispose, async: async });
22
+ }
23
+ else if (async) {
24
+ env.stack.push({ async: true });
25
+ }
26
+ return value;
27
+ };
28
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
29
+ return function (env) {
30
+ function fail(e) {
31
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
32
+ env.hasError = true;
33
+ }
34
+ var r, s = 0;
35
+ function next() {
36
+ while (r = env.stack.pop()) {
37
+ try {
38
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
39
+ if (r.dispose) {
40
+ var result = r.dispose.call(r.value);
41
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
42
+ }
43
+ else s |= 1;
44
+ }
45
+ catch (e) {
46
+ fail(e);
47
+ }
48
+ }
49
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
50
+ if (env.hasError) throw env.error;
51
+ }
52
+ return next();
53
+ };
54
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
55
+ var e = new Error(message);
56
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
+ });
58
+ import { logger } from './logger.js';
59
+ export class WaitForHelper {
60
+ #abortController = new AbortController();
61
+ #page;
62
+ #stableDomTimeout;
63
+ #stableDomFor;
64
+ #expectNavigationIn;
65
+ #navigationTimeout;
66
+ #dialogHandled = false;
67
+ /** Track all dialogs as they pause the renderer. */
68
+ #dialogDetected = false;
69
+ #initialUrl;
70
+ constructor(page, cpuTimeoutMultiplier, networkTimeoutMultiplier) {
71
+ this.#stableDomTimeout = 3000 * cpuTimeoutMultiplier;
72
+ this.#stableDomFor = 100 * cpuTimeoutMultiplier;
73
+ this.#expectNavigationIn = 100 * cpuTimeoutMultiplier;
74
+ this.#navigationTimeout = 3000 * networkTimeoutMultiplier;
75
+ this.#page = page;
76
+ this.#initialUrl = page.url();
77
+ }
78
+ /**
79
+ * A wrapper that executes a action and waits for
80
+ * a potential navigation, after which it waits
81
+ * for the DOM to be stable before returning.
82
+ */
83
+ async waitForStableDom() {
84
+ const env_1 = { stack: [], error: void 0, hasError: false };
85
+ try {
86
+ // Bound the setup evaluation against the stable-DOM timeout. Without this
87
+ // cap a paused renderer (e.g. an open dialog) would make evaluateHandle
88
+ // hang until protocolTimeout (default 180s) while the tool mutex is held.
89
+ const stableDomObserver = __addDisposableResource(env_1, await Promise.race([
90
+ this.#page.evaluateHandle(timeout => {
91
+ let timeoutId;
92
+ function callback() {
93
+ clearTimeout(timeoutId);
94
+ timeoutId = setTimeout(() => {
95
+ domObserver.resolver.resolve();
96
+ domObserver.observer.disconnect();
97
+ }, timeout);
98
+ }
99
+ const domObserver = {
100
+ resolver: Promise.withResolvers(),
101
+ observer: new MutationObserver(callback),
102
+ };
103
+ // It's possible that the DOM is not gonna change so we
104
+ // need to start the timeout initially.
105
+ callback();
106
+ domObserver.observer.observe(document.body, {
107
+ childList: true,
108
+ subtree: true,
109
+ attributes: true,
110
+ });
111
+ return domObserver;
112
+ }, this.#stableDomFor),
113
+ this.timeout(this.#stableDomTimeout),
114
+ ]).catch(() => undefined), false);
115
+ if (!stableDomObserver) {
116
+ return;
117
+ }
118
+ this.#abortController.signal.addEventListener('abort', async () => {
119
+ try {
120
+ await stableDomObserver.evaluate(observer => {
121
+ observer.observer.disconnect();
122
+ observer.resolver.resolve();
123
+ });
124
+ }
125
+ catch {
126
+ // Ignored cleanup errors
127
+ }
128
+ });
129
+ return Promise.race([
130
+ stableDomObserver.evaluate(async (observer) => {
131
+ return await observer.resolver.promise;
132
+ }),
133
+ this.timeout(this.#stableDomTimeout).then(() => {
134
+ throw new Error('Timeout');
135
+ }),
136
+ ]);
137
+ }
138
+ catch (e_1) {
139
+ env_1.error = e_1;
140
+ env_1.hasError = true;
141
+ }
142
+ finally {
143
+ __disposeResources(env_1);
144
+ }
145
+ }
146
+ timeout(time) {
147
+ return new Promise(res => {
148
+ const id = setTimeout(res, time);
149
+ this.#abortController.signal.addEventListener('abort', () => {
150
+ res();
151
+ clearTimeout(id);
152
+ });
153
+ });
154
+ }
155
+ async waitForEventsAfterAction(action, options) {
156
+ if (this.#abortController.signal.aborted) {
157
+ throw new Error("Can't re-use a WaitForHelper");
158
+ }
159
+ const dialogHandler = (dialog) => {
160
+ this.#dialogDetected = true;
161
+ if (!options?.handleDialog) {
162
+ return;
163
+ }
164
+ let actionToTake;
165
+ if (typeof options.handleDialog === 'object') {
166
+ actionToTake = options.handleDialog[dialog.type()];
167
+ }
168
+ else {
169
+ actionToTake = options.handleDialog;
170
+ }
171
+ if (actionToTake) {
172
+ this.#dialogHandled = true;
173
+ if (actionToTake === 'dismiss') {
174
+ void dialog.dismiss();
175
+ }
176
+ else if (actionToTake === 'accept') {
177
+ void dialog.accept();
178
+ }
179
+ else {
180
+ void dialog.accept(actionToTake);
181
+ }
182
+ }
183
+ };
184
+ this.#page.on('dialog', dialogHandler);
185
+ this.#abortController.signal.addEventListener('abort', () => {
186
+ this.#page.off('dialog', dialogHandler);
187
+ });
188
+ // A scoped AbortController used to clean up navigation probe listeners.
189
+ // When aborted (either after navigation detection finishes or if this.#abortController
190
+ // aborts), it removes the CDP Page.frameStartedNavigating listener and automatically
191
+ // detaches the abort listener from this.#abortController.signal.
192
+ const navigationAbortController = new AbortController();
193
+ const navigationStartedResolvers = Promise.withResolvers();
194
+ const navigationListener = (event) => {
195
+ if (event.frameId !== this.#page.mainFrame()._id) {
196
+ return;
197
+ }
198
+ if (event.navigationType === 'sameDocument' ||
199
+ event.navigationType === 'historySameDocument') {
200
+ return;
201
+ }
202
+ navigationStartedResolvers.resolve(true);
203
+ };
204
+ this.#page._client().on('Page.frameStartedNavigating', navigationListener);
205
+ navigationAbortController.signal.addEventListener('abort', () => {
206
+ this.#page
207
+ ._client()
208
+ .off('Page.frameStartedNavigating', navigationListener);
209
+ });
210
+ this.#abortController.signal.addEventListener('abort', () => {
211
+ navigationStartedResolvers.resolve(false);
212
+ navigationAbortController.abort();
213
+ }, { signal: navigationAbortController.signal });
214
+ // Puppeteer's waitForNavigation must be started before the action runs so that
215
+ // it captures the pre-action loader ID. If started after the action triggers navigation,
216
+ // it risks recording the new loader ID and hanging until timeout.
217
+ // If no navigation occurs, this.#abortController will cancel it in the finally block.
218
+ const navigationFinished = this.#page
219
+ .waitForNavigation({
220
+ timeout: options?.timeout ?? this.#navigationTimeout,
221
+ signal: this.#abortController.signal,
222
+ ignoreSameDocumentNavigation: true,
223
+ })
224
+ .then(result => {
225
+ navigationStartedResolvers.resolve(true);
226
+ return result;
227
+ })
228
+ .catch(error => {
229
+ if (this.#abortController.signal.aborted ||
230
+ (error instanceof Error && error.name === 'AbortError')) {
231
+ return;
232
+ }
233
+ logger?.(error);
234
+ });
235
+ try {
236
+ await action();
237
+ }
238
+ catch (error) {
239
+ // Clear up pending promises
240
+ this.#abortController.abort();
241
+ throw error;
242
+ }
243
+ const expectNavigationIn = options?.expectNavigationIn ?? this.#expectNavigationIn;
244
+ const navigationStarted = await Promise.race([
245
+ navigationStartedResolvers.promise,
246
+ this.timeout(expectNavigationIn).then(() => {
247
+ navigationStartedResolvers.resolve(false);
248
+ return false;
249
+ }),
250
+ ]);
251
+ navigationAbortController.abort();
252
+ try {
253
+ // Only await navigation if one was actually initiated; otherwise, the
254
+ // pending waitForNavigation promise will be cancelled when this.#abortController aborts.
255
+ if (navigationStarted) {
256
+ await navigationFinished;
257
+ }
258
+ if (this.#dialogDetected) {
259
+ return this.#getResult();
260
+ }
261
+ // Wait for stable dom after navigation so we execute in
262
+ // the correct context
263
+ if (options?.waitForStableDom !== false) {
264
+ await this.waitForStableDom();
265
+ }
266
+ }
267
+ catch (error) {
268
+ logger?.(error);
269
+ }
270
+ finally {
271
+ this.#abortController.abort();
272
+ }
273
+ return this.#getResult();
274
+ }
275
+ #getResult() {
276
+ const urlAfterAction = this.#page.url();
277
+ return {
278
+ ...(urlAfterAction !== this.#initialUrl
279
+ ? { navigatedToUrl: urlAfterAction }
280
+ : {}),
281
+ dialogHandled: this.#dialogHandled,
282
+ };
283
+ }
284
+ }
285
+ export function getNetworkMultiplierFromString(condition) {
286
+ const puppeteerCondition = condition;
287
+ switch (puppeteerCondition) {
288
+ case 'Fast 4G':
289
+ return 1;
290
+ case 'Slow 4G':
291
+ return 2.5;
292
+ case 'Fast 3G':
293
+ return 5;
294
+ case 'Slow 3G':
295
+ return 10;
296
+ }
297
+ return 1;
298
+ }
299
+ //# sourceMappingURL=WaitForHelper.js.map