chrome-devtools-mcp 1.5.0 → 1.7.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 (295) hide show
  1. package/README.md +41 -9
  2. package/build/src/HeapSnapshotManager.js +77 -28
  3. package/build/src/McpContext.js +233 -383
  4. package/build/src/McpPage.js +466 -41
  5. package/build/src/McpResponse.js +285 -331
  6. package/build/src/PageCollector.js +53 -122
  7. package/build/src/SlimMcpResponse.js +1 -1
  8. package/build/src/TextSnapshot.js +100 -21
  9. package/build/src/ToolHandler.js +31 -10
  10. package/build/src/WaitForHelper.js +140 -56
  11. package/build/src/bin/chrome-devtools-cli-options.js +63 -3
  12. package/build/src/bin/chrome-devtools-mcp-cli-options.js +16 -7
  13. package/build/src/bin/chrome-devtools-mcp-main.js +3 -3
  14. package/build/src/bin/chrome-devtools.js +19 -3
  15. package/build/src/browser.js +1 -1
  16. package/build/src/daemon/client.js +55 -3
  17. package/build/src/daemon/daemon.js +17 -12
  18. package/build/src/daemon/utils.js +19 -4
  19. package/build/src/devtools/DevtoolsUtils.js +9 -65
  20. package/build/src/{issue-descriptions.js → devtools/issueDescriptions.js} +2 -2
  21. package/build/src/formatters/HeapSnapshotFormatter.js +48 -11
  22. package/build/src/formatters/IssueFormatter.js +2 -2
  23. package/build/src/index.js +13 -3
  24. package/build/src/telemetry/ClearcutLogger.js +4 -1
  25. package/build/src/telemetry/WatchdogClient.js +1 -1
  26. package/build/src/telemetry/metricsRegistry.js +2 -9
  27. package/build/src/telemetry/persistence.js +1 -1
  28. package/build/src/telemetry/transformation.js +50 -0
  29. package/build/src/telemetry/watchdog/ClearcutSender.js +1 -1
  30. package/build/src/telemetry/watchdog/main.js +1 -1
  31. package/build/src/third_party/THIRD_PARTY_NOTICES +230 -287
  32. package/build/src/third_party/bundled-packages.json +4 -6
  33. package/build/src/third_party/devtools-formatter-worker.js +60 -19
  34. package/build/src/third_party/devtools-heap-snapshot-worker.js +383 -182
  35. package/build/src/third_party/index.js +30171 -11328
  36. package/build/src/third_party/issue-descriptions/CoepCorpNotSameOrigin.md +2 -2
  37. package/build/src/third_party/issue-descriptions/CoepCorpNotSameOriginAfterDefaultedToSameOriginByCoep.md +3 -3
  38. package/build/src/third_party/issue-descriptions/CoepCorpNotSameSite.md +2 -2
  39. package/build/src/third_party/issue-descriptions/CoepFrameResourceNeedsCoepHeader.md +1 -1
  40. package/build/src/third_party/issue-descriptions/CompatibilityModeQuirks.md +1 -1
  41. package/build/src/third_party/issue-descriptions/CookieAttributeValueExceedsMaxSize.md +2 -2
  42. package/build/src/third_party/issue-descriptions/LowTextContrast.md +1 -1
  43. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureErrorRead.md +1 -1
  44. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureErrorSet.md +1 -1
  45. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureWarnRead.md +1 -1
  46. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureWarnSet.md +1 -1
  47. package/build/src/third_party/issue-descriptions/SameSiteUnspecifiedLaxAllowUnsafeRead.md +3 -3
  48. package/build/src/third_party/issue-descriptions/SameSiteUnspecifiedLaxAllowUnsafeSet.md +3 -3
  49. package/build/src/third_party/issue-descriptions/bounceTrackingMitigations.md +1 -1
  50. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowlistItemType.md +2 -2
  51. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidHeader.md +2 -2
  52. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidUrlPattern.md +3 -3
  53. package/build/src/third_party/issue-descriptions/connectionAllowlistItemNotInnerList.md +2 -2
  54. package/build/src/third_party/issue-descriptions/connectionAllowlistMoreThanOneList.md +2 -2
  55. package/build/src/third_party/issue-descriptions/connectionAllowlistReportingEndpointNotToken.md +1 -1
  56. package/build/src/third_party/issue-descriptions/cookieCrossSiteRedirectDowngrade.md +3 -3
  57. package/build/src/third_party/issue-descriptions/cookieExcludeBlockedWithinRelatedWebsiteSet.md +1 -1
  58. package/build/src/third_party/issue-descriptions/cookieExcludePortMismatch.md +1 -1
  59. package/build/src/third_party/issue-descriptions/cookieExcludeSchemeMismatch.md +1 -1
  60. package/build/src/third_party/issue-descriptions/cookieExcludeThirdPartyPhaseoutSet.md +1 -1
  61. package/build/src/third_party/issue-descriptions/cookieWarnThirdPartyPhaseoutRead.md +1 -1
  62. package/build/src/third_party/issue-descriptions/corsAllowCredentialsRequired.md +1 -1
  63. package/build/src/third_party/issue-descriptions/corsDisabledScheme.md +2 -2
  64. package/build/src/third_party/issue-descriptions/corsDisallowedByMode.md +2 -2
  65. package/build/src/third_party/issue-descriptions/corsHeaderDisallowedByPreflightResponse.md +1 -1
  66. package/build/src/third_party/issue-descriptions/corsInvalidHeaderValues.md +3 -3
  67. package/build/src/third_party/issue-descriptions/corsLocalNetworkAccessPermissionDenied.md +1 -1
  68. package/build/src/third_party/issue-descriptions/corsMethodDisallowedByPreflightResponse.md +1 -1
  69. package/build/src/third_party/issue-descriptions/corsNoCorsRedirectModeNotFollow.md +1 -1
  70. package/build/src/third_party/issue-descriptions/corsOriginMismatch.md +3 -3
  71. package/build/src/third_party/issue-descriptions/corsPreflightResponseInvalid.md +2 -2
  72. package/build/src/third_party/issue-descriptions/corsRedirectContainsCredentials.md +3 -3
  73. package/build/src/third_party/issue-descriptions/corsWildcardOriginNotAllowed.md +4 -3
  74. package/build/src/third_party/issue-descriptions/cspEvalViolation.md +4 -4
  75. package/build/src/third_party/issue-descriptions/cspInlineViolation.md +2 -2
  76. package/build/src/third_party/issue-descriptions/cspTrustedTypesPolicyViolation.md +2 -2
  77. package/build/src/third_party/issue-descriptions/cspTrustedTypesSinkViolation.md +4 -4
  78. package/build/src/third_party/issue-descriptions/cspURLViolation.md +4 -4
  79. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsEmptyList.md +1 -1
  80. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsHttpNotFound.md +1 -1
  81. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsInvalidContentType.md +1 -1
  82. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsInvalidResponse.md +1 -1
  83. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsNoResponse.md +1 -1
  84. package/build/src/third_party/issue-descriptions/emailVerificationRequestDnsFetchFailed.md +1 -1
  85. package/build/src/third_party/issue-descriptions/emailVerificationRequestDnsInvalidRecord.md +1 -1
  86. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownHttpNotFound.md +1 -1
  87. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownInvalidContentType.md +1 -1
  88. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownInvalidResponse.md +1 -1
  89. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownNoResponse.md +1 -1
  90. package/build/src/third_party/issue-descriptions/emailVerificationRequestInvalidEmail.md +1 -1
  91. package/build/src/third_party/issue-descriptions/emailVerificationRequestJwksHttpNotFound.md +1 -1
  92. package/build/src/third_party/issue-descriptions/emailVerificationRequestJwksInvalidResponse.md +1 -1
  93. package/build/src/third_party/issue-descriptions/emailVerificationRequestKeyBindingSigningFailed.md +1 -1
  94. package/build/src/third_party/issue-descriptions/emailVerificationRequestRpOriginIsOpaque.md +1 -1
  95. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenHttpNotFound.md +1 -1
  96. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidContentType.md +1 -1
  97. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidResponse.md +1 -1
  98. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidSdJwt.md +1 -1
  99. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenMalformedSdJwt.md +1 -1
  100. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenNoResponse.md +1 -1
  101. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidAudience.md +1 -1
  102. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidIssuedAt.md +1 -1
  103. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidNonce.md +1 -1
  104. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidSdHash.md +1 -1
  105. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidTyp.md +1 -1
  106. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingAud.md +1 -1
  107. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingCnf.md +1 -1
  108. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingIat.md +1 -1
  109. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingNonce.md +1 -1
  110. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingSdHash.md +1 -1
  111. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbSignatureFailed.md +1 -1
  112. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidEmail.md +1 -1
  113. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidEmailVerified.md +1 -1
  114. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidHolderKey.md +1 -1
  115. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidIssuedAt.md +1 -1
  116. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidIssuer.md +1 -1
  117. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtJwksMissingKeys.md +1 -1
  118. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingCnf.md +1 -1
  119. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingEmail.md +1 -1
  120. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingIat.md +1 -1
  121. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingIss.md +1 -1
  122. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtSignatureFailed.md +1 -1
  123. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtUnsupportedHeaderAlg.md +1 -1
  124. package/build/src/third_party/issue-descriptions/emailVerificationRequestUserLoggedOut.md +1 -1
  125. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownAccountsEndpointCrossOrigin.md +1 -1
  126. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownHttpNotFound.md +1 -1
  127. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownInvalidContentType.md +1 -1
  128. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownInvalidResponse.md +1 -1
  129. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownIssuanceEndpointCrossOrigin.md +1 -1
  130. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownListEmpty.md +1 -1
  131. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownMissingAccountsEndpoint.md +1 -1
  132. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownMissingIssuanceEndpoint.md +1 -1
  133. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownNoResponse.md +1 -1
  134. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownUnsupportedSigningAlgorithm.md +1 -1
  135. package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsHttpNotFound.md +1 -1
  136. package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsInvalidResponse.md +1 -1
  137. package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsNoResponse.md +1 -1
  138. package/build/src/third_party/issue-descriptions/federatedAuthRequestApprovalDeclined.md +1 -1
  139. package/build/src/third_party/issue-descriptions/federatedAuthRequestCanceled.md +1 -1
  140. package/build/src/third_party/issue-descriptions/federatedAuthRequestErrorFetchingSignin.md +1 -1
  141. package/build/src/third_party/issue-descriptions/federatedAuthRequestErrorIdToken.md +1 -1
  142. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenHttpNotFound.md +1 -1
  143. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenInvalidRequest.md +1 -1
  144. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenInvalidResponse.md +1 -1
  145. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenNoResponse.md +1 -1
  146. package/build/src/third_party/issue-descriptions/federatedAuthRequestInvalidSigninResponse.md +1 -1
  147. package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestHttpNotFound.md +1 -1
  148. package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestInvalidResponse.md +1 -1
  149. package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestNoResponse.md +1 -1
  150. package/build/src/third_party/issue-descriptions/federatedAuthRequestTooManyRequests.md +1 -1
  151. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestInvalidAccountsResponse.md +1 -1
  152. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestInvalidConfigOrWellKnown.md +1 -1
  153. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoAccountSharingPermission.md +1 -1
  154. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoApiPermission.md +1 -1
  155. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoReturningUserFromFetchedAccounts.md +1 -1
  156. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotIframe.md +1 -1
  157. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotPotentiallyTrustworthy.md +1 -1
  158. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotSameOrigin.md +1 -1
  159. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotSignedInWithIdp.md +1 -1
  160. package/build/src/third_party/issue-descriptions/fetchingPartitionedBlobURL.md +2 -2
  161. package/build/src/third_party/issue-descriptions/genericFormAriaLabelledByToNonExistingIdError.md +2 -2
  162. package/build/src/third_party/issue-descriptions/genericFormAutocompleteAttributeEmptyError.md +1 -1
  163. package/build/src/third_party/issue-descriptions/genericFormDuplicateIdForInputError.md +1 -1
  164. package/build/src/third_party/issue-descriptions/genericFormEmptyIdAndNameAttributesForInputError.md +2 -2
  165. package/build/src/third_party/issue-descriptions/genericFormInputAssignedAutocompleteValueToIdOrNameAttributeError.md +2 -2
  166. package/build/src/third_party/issue-descriptions/genericFormInputHasWrongButWellIntendedAutocompleteValueError.md +1 -1
  167. package/build/src/third_party/issue-descriptions/genericFormInputWithNoLabelError.md +1 -1
  168. package/build/src/third_party/issue-descriptions/genericFormLabelForMatchesNonExistingIdError.md +2 -2
  169. package/build/src/third_party/issue-descriptions/genericFormLabelForNameError.md +1 -1
  170. package/build/src/third_party/issue-descriptions/genericFormLabelHasNeitherForNorNestedInputError.md +1 -1
  171. package/build/src/third_party/issue-descriptions/genericFormModelContextMissingToolName.md +1 -1
  172. package/build/src/third_party/issue-descriptions/genericFormModelContextParameterMissingName.md +1 -1
  173. package/build/src/third_party/issue-descriptions/genericFormModelContextRequiredParameterMissingName.md +1 -1
  174. package/build/src/third_party/issue-descriptions/genericNavigationEntryMarkedSkippable.md +2 -2
  175. package/build/src/third_party/issue-descriptions/heavyAd.md +1 -1
  176. package/build/src/third_party/issue-descriptions/lazyLoadImageZeroSize.md +7 -0
  177. package/build/src/third_party/issue-descriptions/navigatingPartitionedBlobURL.md +3 -3
  178. package/build/src/third_party/issue-descriptions/permissionElementActivationDisabled.md +1 -1
  179. package/build/src/third_party/issue-descriptions/permissionElementActivationDisabledWithOccluder.md +1 -1
  180. package/build/src/third_party/issue-descriptions/permissionElementActivationDisabledWithOccluderParent.md +1 -1
  181. package/build/src/third_party/issue-descriptions/permissionElementFencedFrameDisallowed.md +2 -2
  182. package/build/src/third_party/issue-descriptions/permissionElementFontSizeTooLarge.md +2 -2
  183. package/build/src/third_party/issue-descriptions/permissionElementFontSizeTooSmall.md +2 -2
  184. package/build/src/third_party/issue-descriptions/permissionElementInsetBoxShadowUnsupported.md +1 -1
  185. package/build/src/third_party/issue-descriptions/permissionElementInvalidDisplayStyle.md +2 -2
  186. package/build/src/third_party/issue-descriptions/permissionElementInvalidSizeValue.md +2 -2
  187. package/build/src/third_party/issue-descriptions/permissionElementInvalidType.md +2 -2
  188. package/build/src/third_party/issue-descriptions/permissionElementInvalidTypeActivation.md +2 -2
  189. package/build/src/third_party/issue-descriptions/permissionElementNonOpaqueColor.md +1 -1
  190. package/build/src/third_party/issue-descriptions/permissionElementPaddingBottomUnsupported.md +2 -2
  191. package/build/src/third_party/issue-descriptions/permissionElementPaddingRightUnsupported.md +2 -2
  192. package/build/src/third_party/issue-descriptions/permissionElementRequestInProgress.md +2 -2
  193. package/build/src/third_party/issue-descriptions/permissionElementSecurityChecksFailed.md +1 -1
  194. package/build/src/third_party/issue-descriptions/permissionElementTypeNotSupported.md +2 -2
  195. package/build/src/third_party/issue-descriptions/permissionElementUntrustedEvent.md +1 -1
  196. package/build/src/third_party/issue-descriptions/placeholderDescriptionForInvisibleIssues.md +1 -1
  197. package/build/src/third_party/issue-descriptions/selectElementAccessibilityDisallowedOptGroupChild.md +1 -1
  198. package/build/src/third_party/issue-descriptions/selectElementAccessibilityDisallowedSelectChild.md +1 -1
  199. package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentAttributesSelectDescendant.md +1 -1
  200. package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentLegendChild.md +1 -1
  201. package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentOptionChild.md +1 -1
  202. package/build/src/third_party/issue-descriptions/selectElementAccessibilityNonPhrasingContentOptionChild.md +1 -1
  203. package/build/src/third_party/issue-descriptions/selectivePermissionsIntervention.md +3 -3
  204. package/build/src/third_party/issue-descriptions/sharedArrayBuffer.md +1 -1
  205. package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorCrossOriginNoCorsRequest.md +1 -1
  206. package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorMatchingDictionaryNotUsed.md +1 -1
  207. package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorUnexpectedContentDictionaryHeader.md +1 -1
  208. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorCossOriginNoCorsRequest.md +1 -1
  209. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorDisallowedBySettings.md +1 -1
  210. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorExpiredResponse.md +1 -1
  211. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorFeatureDisabled.md +2 -2
  212. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorInvalidStructuredHeader.md +1 -1
  213. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNavigationRequest.md +2 -2
  214. package/build/src/third_party/issue-descriptions/sriInvalidSignatureHeader.md +4 -4
  215. package/build/src/third_party/issue-descriptions/sriInvalidSignatureInputHeader.md +4 -4
  216. package/build/src/third_party/issue-descriptions/sriMissingSignatureHeader.md +1 -1
  217. package/build/src/third_party/issue-descriptions/sriMissingSignatureInputHeader.md +2 -2
  218. package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsIncorrectLength.md +2 -2
  219. package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsNotByteSequence.md +4 -4
  220. package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsParameterized.md +4 -4
  221. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidComponentName.md +1 -1
  222. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidComponentType.md +2 -2
  223. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidDerivedComponentParameter.md +1 -1
  224. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidHeaderComponentParameter.md +1 -1
  225. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidParameter.md +2 -2
  226. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderKeyIdLength.md +5 -5
  227. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderMissingLabel.md +3 -3
  228. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderMissingRequiredParameters.md +2 -2
  229. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderValueMissingComponents.md +2 -2
  230. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderValueNotInnerList.md +2 -2
  231. package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +4 -4
  232. package/build/src/third_party/issue-descriptions/sriValidationFailedInvalidLength.md +3 -3
  233. package/build/src/third_party/issue-descriptions/sriValidationFailedSignatureExpired.md +2 -2
  234. package/build/src/third_party/issue-descriptions/sriValidationFailedSignatureMismatch.md +2 -2
  235. package/build/src/third_party/issue-descriptions/stylesheetLateImport.md +1 -1
  236. package/build/src/third_party/issue-descriptions/summaryElementAccessibilityInteractiveContentSummaryDescendant.md +1 -1
  237. package/build/src/third_party/issue-descriptions/unencodedDigestIncorrectDigestLength.md +2 -2
  238. package/build/src/third_party/issue-descriptions/unencodedDigestIncorrectDigestType.md +3 -3
  239. package/build/src/third_party/issue-descriptions/unencodedDigestMalformedDictionary.md +2 -2
  240. package/build/src/third_party/issue-descriptions/unencodedDigestUnknownAlgorithm.md +1 -1
  241. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +3177 -6340
  242. package/build/src/tools/emulation.js +2 -2
  243. package/build/src/tools/extensions.js +1 -1
  244. package/build/src/tools/input.js +213 -112
  245. package/build/src/tools/lighthouse.js +1 -1
  246. package/build/src/tools/memory.js +49 -4
  247. package/build/src/tools/network.js +5 -5
  248. package/build/src/tools/pages.js +22 -89
  249. package/build/src/tools/performance.js +62 -41
  250. package/build/src/tools/screenshot.js +152 -77
  251. package/build/src/tools/script.js +95 -28
  252. package/build/src/tools/snapshot.js +2 -2
  253. package/build/src/tools/thirdPartyDeveloper.js +1 -1
  254. package/build/src/tools/webmcp.js +1 -1
  255. package/build/src/trace-processing/parse.js +1 -1
  256. package/build/src/{logger.js → utils/logger.js} +1 -1
  257. package/build/src/utils/polyfill.js +11 -0
  258. package/build/src/utils/url.js +43 -0
  259. package/build/src/version.js +1 -1
  260. package/package.json +23 -15
  261. package/skills/memory-leak-debugging/SKILL.md +23 -19
  262. package/skills/memory-leak-debugging/references/common-leaks.md +1 -1
  263. package/build/src/Mutex.js +0 -38
  264. package/build/src/devtools/DevToolsConnectionAdapter.js +0 -70
  265. package/build/src/polyfill.js +0 -8
  266. package/build/src/third_party/issue-descriptions/SameSiteExcludeContextDowngradeRead.md +0 -8
  267. package/build/src/third_party/issue-descriptions/SameSiteExcludeContextDowngradeSet.md +0 -8
  268. package/build/src/third_party/issue-descriptions/SameSiteExcludeNavigationContextDowngrade.md +0 -8
  269. package/build/src/third_party/issue-descriptions/SameSiteWarnCrossDowngradeRead.md +0 -8
  270. package/build/src/third_party/issue-descriptions/SameSiteWarnCrossDowngradeSet.md +0 -8
  271. package/build/src/third_party/issue-descriptions/SameSiteWarnStrictLaxDowngradeStrict.md +0 -8
  272. package/build/src/third_party/issue-descriptions/arInsecureContext.md +0 -7
  273. package/build/src/third_party/issue-descriptions/arInvalidInfoHeader.md +0 -5
  274. package/build/src/third_party/issue-descriptions/arInvalidRegisterOsSourceHeader.md +0 -5
  275. package/build/src/third_party/issue-descriptions/arInvalidRegisterOsTriggerHeader.md +0 -5
  276. package/build/src/third_party/issue-descriptions/arInvalidRegisterSourceHeader.md +0 -5
  277. package/build/src/third_party/issue-descriptions/arInvalidRegisterTriggerHeader.md +0 -5
  278. package/build/src/third_party/issue-descriptions/arNavigationRegistrationUniqueScopeAlreadySet.md +0 -5
  279. package/build/src/third_party/issue-descriptions/arNavigationRegistrationWithoutTransientUserActivation.md +0 -6
  280. package/build/src/third_party/issue-descriptions/arNoRegisterOsSourceHeader.md +0 -5
  281. package/build/src/third_party/issue-descriptions/arNoRegisterOsTriggerHeader.md +0 -5
  282. package/build/src/third_party/issue-descriptions/arNoRegisterSourceHeader.md +0 -5
  283. package/build/src/third_party/issue-descriptions/arNoRegisterTriggerHeader.md +0 -5
  284. package/build/src/third_party/issue-descriptions/arNoWebOrOsSupport.md +0 -4
  285. package/build/src/third_party/issue-descriptions/arOsSourceIgnored.md +0 -18
  286. package/build/src/third_party/issue-descriptions/arOsTriggerIgnored.md +0 -19
  287. package/build/src/third_party/issue-descriptions/arPermissionPolicyDisabled.md +0 -8
  288. package/build/src/third_party/issue-descriptions/arSourceAndTriggerHeaders.md +0 -9
  289. package/build/src/third_party/issue-descriptions/arSourceIgnored.md +0 -13
  290. package/build/src/third_party/issue-descriptions/arTriggerIgnored.md +0 -12
  291. package/build/src/third_party/issue-descriptions/arUntrustworthyReportingOrigin.md +0 -10
  292. package/build/src/third_party/issue-descriptions/arWebAndOsHeaders.md +0 -11
  293. package/build/src/utils/types.js +0 -7
  294. package/skills/memory-leak-debugging/references/compare_snapshots.js +0 -109
  295. package/skills/memory-leak-debugging/references/memlab.md +0 -29
@@ -3,55 +3,10 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { logger } from '../logger.js';
7
6
  import { zod } from '../third_party/index.js';
7
+ import { logger } from '../utils/logger.js';
8
8
  import { ToolCategory } from './categories.js';
9
9
  import { CLOSE_PAGE_ERROR, definePageTool, defineTool, timeoutSchema, } from './ToolDefinition.js';
10
- async function navigateWithInterception(page, action, allowListString, timeout) {
11
- const allowList = allowListString
12
- ? allowListString.split(',').map((p) => new URLPattern(p.trim()))
13
- : undefined;
14
- const requestHandler = (interceptedRequest) => {
15
- if (!interceptedRequest.isNavigationRequest()) {
16
- void interceptedRequest.continue();
17
- return;
18
- }
19
- const requestUrl = interceptedRequest.url();
20
- const isAllowed = allowList.some((pattern) => pattern.test(requestUrl));
21
- if (isAllowed) {
22
- void interceptedRequest.continue();
23
- }
24
- else {
25
- logger?.(`Blocking request to: ${requestUrl}`);
26
- void interceptedRequest.abort('blockedbyclient');
27
- }
28
- };
29
- const cleanupInterception = async () => {
30
- if (allowList) {
31
- page.pptrPage.off('request', requestHandler);
32
- await page.pptrPage.setRequestInterception(false).catch(error => {
33
- logger?.(`Failed to disable request interception`, error);
34
- });
35
- }
36
- };
37
- if (allowList) {
38
- await page.pptrPage.setRequestInterception(true);
39
- page.pptrPage.on('request', requestHandler);
40
- }
41
- try {
42
- await page.waitForEventsAfterAction(async () => {
43
- try {
44
- await action();
45
- }
46
- finally {
47
- await cleanupInterception();
48
- }
49
- }, { timeout });
50
- }
51
- finally {
52
- await cleanupInterception();
53
- }
54
- }
55
10
  export const listPages = defineTool(args => {
56
11
  return {
57
12
  name: 'list_pages',
@@ -129,7 +84,7 @@ export const closePage = defineTool({
129
84
  response.setListThirdPartyDeveloperTools();
130
85
  },
131
86
  });
132
- export const newPage = defineTool(args => {
87
+ export const newPage = defineTool(() => {
133
88
  return {
134
89
  name: 'new_page',
135
90
  description: `Open a new tab and load a URL. Use project URL if not specified otherwise.`,
@@ -149,29 +104,23 @@ export const newPage = defineTool(args => {
149
104
  .describe('If specified, the page is created in an isolated browser context with the given name. ' +
150
105
  'Pages in the same browser context share cookies and storage. ' +
151
106
  'Pages in different browser contexts are fully isolated.'),
152
- ...(args?.experimentalNavigationAllowlist
153
- ? {
154
- allowList: zod
155
- .string()
156
- .optional()
157
- .describe('Optional comma-separated list of URL patterns to allow. If provided, all other navigations will be blocked.'),
158
- }
159
- : {}),
160
107
  ...timeoutSchema,
161
108
  },
162
109
  blockedByDialog: false,
163
110
  verifyFilesSchema: [],
164
111
  handler: async (request, response, context) => {
165
112
  const page = await context.newPage(request.params.background, request.params.isolatedContext);
166
- await navigateWithInterception(page, () => page.pptrPage.goto(request.params.url, {
167
- timeout: request.params.timeout,
168
- }), request.params.allowList, request.params.timeout);
113
+ await page.waitForEventsAfterAction(async () => {
114
+ await page.pptrPage.goto(request.params.url, {
115
+ timeout: request.params.timeout,
116
+ });
117
+ }, { timeout: request.params.timeout });
169
118
  response.setIncludePages(true);
170
119
  response.setListThirdPartyDeveloperTools();
171
120
  },
172
121
  };
173
122
  });
174
- export const navigatePage = definePageTool(args => {
123
+ export const navigatePage = definePageTool(() => {
175
124
  return {
176
125
  name: 'navigate_page',
177
126
  description: `Go to a URL, or back, forward, or reload. Use project URL if not specified otherwise.`,
@@ -190,21 +139,13 @@ export const navigatePage = definePageTool(args => {
190
139
  .optional()
191
140
  .describe('Whether to ignore cache on reload.'),
192
141
  handleBeforeUnload: zod
193
- .enum(['accept', 'decline'])
142
+ .enum(['accept', 'dismiss'])
194
143
  .optional()
195
144
  .describe('Whether to auto accept or beforeunload dialogs triggered by this navigation. Default is accept.'),
196
145
  initScript: zod
197
146
  .string()
198
147
  .optional()
199
148
  .describe('A JavaScript script to be executed on each new document before any other scripts for the next navigation.'),
200
- ...(args?.experimentalNavigationAllowlist
201
- ? {
202
- allowList: zod
203
- .string()
204
- .optional()
205
- .describe('Optional comma-separated list of URL patterns to allow. If provided, all other navigations will be blocked.'),
206
- }
207
- : {}),
208
149
  ...timeoutSchema,
209
150
  },
210
151
  blockedByDialog: false,
@@ -220,29 +161,14 @@ export const navigatePage = definePageTool(args => {
220
161
  if (!request.params.type) {
221
162
  request.params.type = 'url';
222
163
  }
223
- const handleBeforeUnload = request.params.handleBeforeUnload ?? 'accept';
224
- const dialogHandler = (dialog) => {
225
- if (dialog.type() === 'beforeunload') {
226
- if (handleBeforeUnload === 'accept') {
227
- response.appendResponseLine(`Accepted a beforeunload dialog.`);
228
- void dialog.accept();
229
- }
230
- else {
231
- response.appendResponseLine(`Declined a beforeunload dialog.`);
232
- void dialog.dismiss();
233
- }
234
- // We are not going to report the dialog like regular dialogs.
235
- page.clearDialog();
236
- }
237
- };
238
164
  let initScriptId;
239
165
  if (request.params.initScript) {
240
166
  const { identifier } = await page.pptrPage.evaluateOnNewDocument(request.params.initScript);
241
167
  initScriptId = identifier;
242
168
  }
243
- page.pptrPage.on('dialog', dialogHandler);
244
169
  try {
245
- await navigateWithInterception(page, async () => {
170
+ const action = request.params.handleBeforeUnload ?? 'accept';
171
+ const result = await page.waitForEventsAfterAction(async () => {
246
172
  switch (request.params.type) {
247
173
  case 'url':
248
174
  if (!request.params.url) {
@@ -287,10 +213,16 @@ export const navigatePage = definePageTool(args => {
287
213
  }
288
214
  break;
289
215
  }
290
- }, request.params.allowList, request.params.timeout);
216
+ }, {
217
+ timeout: request.params.timeout,
218
+ handleDialog: { beforeunload: action },
219
+ });
220
+ if (result.dialogHandled) {
221
+ response.appendResponseLine(`${action === 'dismiss' ? 'Dismissed' : 'Accepted'} a beforeunload dialog.`);
222
+ page.clearDialog();
223
+ }
291
224
  }
292
225
  finally {
293
- page.pptrPage.off('dialog', dialogHandler);
294
226
  if (initScriptId) {
295
227
  await page.pptrPage
296
228
  .removeScriptToEvaluateOnNewDocument(initScriptId)
@@ -318,7 +250,7 @@ export const resizePage = definePageTool({
318
250
  },
319
251
  blockedByDialog: false,
320
252
  verifyFilesSchema: [],
321
- handler: async (request, response, _context) => {
253
+ handler: async (request, response) => {
322
254
  const page = request.page;
323
255
  try {
324
256
  const browser = page.pptrPage.browser();
@@ -361,7 +293,7 @@ export const handleDialog = definePageTool({
361
293
  },
362
294
  blockedByDialog: false,
363
295
  verifyFilesSchema: [],
364
- handler: async (request, response, _context) => {
296
+ handler: async (request, response) => {
365
297
  const page = request.page;
366
298
  const dialog = page.getDialog();
367
299
  if (!dialog) {
@@ -414,6 +346,7 @@ export const getTabId = definePageTool({
414
346
  const page = context.getPageById(request.params.pageId);
415
347
  const tabId = page.pptrPage._tabId;
416
348
  response.setTabId(tabId);
349
+ response.appendResponseLine(`Tab ID: ${tabId}`);
417
350
  },
418
351
  });
419
352
  //# sourceMappingURL=pages.js.map
@@ -4,9 +4,9 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import zlib from 'node:zlib';
7
- import { logger } from '../logger.js';
8
7
  import { zod, DevTools } from '../third_party/index.js';
9
8
  import { parseRawTraceBuffer, traceResultIsSuccess, } from '../trace-processing/parse.js';
9
+ import { logger } from '../utils/logger.js';
10
10
  import { ToolCategory } from './categories.js';
11
11
  import { definePageTool } from './ToolDefinition.js';
12
12
  const filePathSchema = zod
@@ -41,47 +41,68 @@ export const startTrace = definePageTool({
41
41
  context.setIsRunningPerformanceTrace(true);
42
42
  const page = request.page;
43
43
  const pageUrlForTracing = page.pptrPage.url();
44
- if (request.params.reload) {
45
- // Before starting the recording, navigate to about:blank to clear out any state.
46
- await page.pptrPage.goto('about:blank', {
47
- waitUntil: ['networkidle0'],
48
- });
49
- }
50
- // Keep in sync with the categories arrays in:
51
- // https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/panels/timeline/TimelineController.ts
52
- // https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/gather/gatherers/trace.js
53
- const categories = [
54
- '-*',
55
- 'blink.console',
56
- 'blink.user_timing',
57
- 'devtools.timeline',
58
- 'disabled-by-default-devtools.screenshot',
59
- 'disabled-by-default-devtools.timeline',
60
- 'disabled-by-default-devtools.timeline.invalidationTracking',
61
- 'disabled-by-default-devtools.timeline.frame',
62
- 'disabled-by-default-devtools.timeline.stack',
63
- 'disabled-by-default-v8.cpu_profiler',
64
- 'disabled-by-default-v8.cpu_profiler.hires',
65
- 'latencyInfo',
66
- 'loading',
67
- 'disabled-by-default-lighthouse',
68
- 'v8.execute',
69
- 'v8',
70
- ];
71
- await page.pptrPage.tracing.start({
72
- categories,
73
- });
74
- if (request.params.reload) {
75
- await page.pptrPage.goto(pageUrlForTracing, {
76
- waitUntil: ['load'],
44
+ try {
45
+ if (request.params.reload) {
46
+ // Before starting the recording, navigate to about:blank to clear out any state.
47
+ // We use `load` because `networkidle0` is known to be flaky for about:blank in Puppeteer.
48
+ await page.pptrPage.goto('about:blank', {
49
+ waitUntil: 'load',
50
+ });
51
+ }
52
+ // Keep in sync with the categories arrays in:
53
+ // https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/panels/timeline/TimelineController.ts
54
+ // https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/gather/gatherers/trace.js
55
+ const categories = [
56
+ '-*',
57
+ 'blink.console',
58
+ 'blink.user_timing',
59
+ 'devtools.timeline',
60
+ 'disabled-by-default-devtools.screenshot',
61
+ 'disabled-by-default-devtools.timeline',
62
+ 'disabled-by-default-devtools.timeline.invalidationTracking',
63
+ 'disabled-by-default-devtools.timeline.frame',
64
+ 'disabled-by-default-devtools.timeline.stack',
65
+ 'disabled-by-default-v8.cpu_profiler',
66
+ 'disabled-by-default-v8.cpu_profiler.hires',
67
+ 'latencyInfo',
68
+ 'loading',
69
+ 'disabled-by-default-lighthouse',
70
+ 'v8.execute',
71
+ 'v8',
72
+ ];
73
+ await page.pptrPage.tracing.start({
74
+ categories,
77
75
  });
76
+ if (request.params.reload) {
77
+ await page.pptrPage.goto(pageUrlForTracing, {
78
+ waitUntil: ['load'],
79
+ });
80
+ }
81
+ if (request.params.autoStop) {
82
+ await new Promise(resolve => setTimeout(resolve, 5_000));
83
+ await stopTracingAndAppendOutput(page, response, context, request.params.filePath);
84
+ }
85
+ else {
86
+ response.appendResponseLine(`The performance trace is being recorded. Use performance_stop_trace to stop it.`);
87
+ }
78
88
  }
79
- if (request.params.autoStop) {
80
- await new Promise(resolve => setTimeout(resolve, 5_000));
81
- await stopTracingAndAppendOutput(page, response, context, request.params.filePath);
82
- }
83
- else {
84
- response.appendResponseLine(`The performance trace is being recorded. Use performance_stop_trace to stop it.`);
89
+ catch (error) {
90
+ // If a setup step (navigation, tracing.start) throws before
91
+ // stopTracingAndAppendOutput runs, the running flag would otherwise stay
92
+ // stuck `true` for the rest of the session, blocking all future traces.
93
+ // Unwind here: stop tracing if it was started and clear the flag. When
94
+ // autoStop already ran stopTracingAndAppendOutput the flag is already
95
+ // false and this is a no-op.
96
+ if (context.isRunningPerformanceTrace()) {
97
+ try {
98
+ await page.pptrPage.tracing.stop();
99
+ }
100
+ catch {
101
+ // Tracing may not have started yet; ignore.
102
+ }
103
+ context.setIsRunningPerformanceTrace(false);
104
+ }
105
+ throw error;
85
106
  }
86
107
  },
87
108
  });
@@ -148,7 +169,7 @@ async function stopTracingAndAppendOutput(page, response, context, filePath) {
148
169
  });
149
170
  });
150
171
  }
151
- const file = await context.saveFile(dataToWrite, filePath, filePath.endsWith('.gz') ? '.json.gz' : '.json');
172
+ const file = await context.saveFile(dataToWrite, filePath, filePath.endsWith('.gz') ? '.gz' : '.json');
152
173
  response.appendResponseLine(`The raw trace data was saved to ${file.filename}.`);
153
174
  }
154
175
  const result = await parseRawTraceBuffer(traceEventsBuffer, {
@@ -3,6 +3,58 @@
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 { definePageTool } from './ToolDefinition.js';
@@ -22,10 +74,20 @@ async function getSourceBox(page, element, fullPage) {
22
74
  return { x: 0, y: 0, width: dims.width, height: dims.height };
23
75
  }
24
76
  const viewport = page.viewport();
25
- if (!viewport) {
77
+ if (viewport) {
78
+ return { x: 0, y: 0, width: viewport.width, height: viewport.height };
79
+ }
80
+ // The browser is launched and connected with `defaultViewport: null`, so
81
+ // `page.viewport()` stays null until something emulates one. Fall back to the
82
+ // window's own dimensions, which is the area a viewport screenshot captures.
83
+ const dims = await page.evaluate(() => ({
84
+ width: window.innerWidth,
85
+ height: window.innerHeight,
86
+ }));
87
+ if (dims.width <= 0 || dims.height <= 0) {
26
88
  return undefined;
27
89
  }
28
- return { x: 0, y: 0, width: viewport.width, height: viewport.height };
90
+ return { x: 0, y: 0, width: dims.width, height: dims.height };
29
91
  }
30
92
  function computeDownscaleClip(box, maxWidth, maxHeight) {
31
93
  const widthScale = maxWidth !== undefined ? Math.min(1, maxWidth / box.width) : 1;
@@ -84,84 +146,97 @@ export const screenshot = definePageTool(args => {
84
146
  blockedByDialog: true,
85
147
  verifyFilesSchema: ['filePath'],
86
148
  handler: async (request, response, context) => {
87
- if (request.params.uid && request.params.fullPage) {
88
- throw new Error('Providing both "uid" and "fullPage" is not allowed.');
89
- }
90
- const page = request.page.pptrPage;
91
- const element = request.params.uid
92
- ? await request.page.getElementByUid(request.params.uid)
93
- : undefined;
94
- const format = request.params.format;
95
- const quality = format === 'png'
96
- ? undefined
97
- : (request.params.quality ?? screenshotQuality);
98
- const fullPage = request.params.fullPage ?? false;
99
- // Compute a downscale clip when --screenshot-max-width or
100
- // --screenshot-max-height is set and the source exceeds either bound.
101
- // The smaller scale factor wins so both bounds are respected while
102
- // preserving aspect ratio.
103
- let clip;
104
- if (screenshotMaxWidth !== undefined ||
105
- screenshotMaxHeight !== undefined) {
106
- const box = await getSourceBox(page, element, fullPage);
107
- if (box) {
108
- clip = computeDownscaleClip(box, screenshotMaxWidth, screenshotMaxHeight);
149
+ const env_1 = { stack: [], error: void 0, hasError: false };
150
+ try {
151
+ if (request.params.uid && request.params.fullPage) {
152
+ throw new Error('Providing both "uid" and "fullPage" is not allowed.');
153
+ }
154
+ const page = request.page.pptrPage;
155
+ const element = __addDisposableResource(env_1, request.params.uid
156
+ ? await request.page.getElementByUid(request.params.uid)
157
+ : undefined, false);
158
+ const format = request.params.format;
159
+ const quality = format === 'png'
160
+ ? undefined
161
+ : (request.params.quality ?? screenshotQuality);
162
+ const fullPage = request.params.fullPage ?? false;
163
+ // `getElementByUid` mints a fresh ElementHandle per call, so dispose it
164
+ // once the capture is done to avoid leaking a remote object for the life
165
+ // of the page's execution context.
166
+ let screenshot;
167
+ // Compute a downscale clip when --screenshot-max-width or
168
+ // --screenshot-max-height is set and the source exceeds either bound.
169
+ // The smaller scale factor wins so both bounds are respected while
170
+ // preserving aspect ratio.
171
+ let clip;
172
+ if (screenshotMaxWidth !== undefined ||
173
+ screenshotMaxHeight !== undefined) {
174
+ const box = await getSourceBox(page, element, fullPage);
175
+ if (box) {
176
+ clip = computeDownscaleClip(box, screenshotMaxWidth, screenshotMaxHeight);
177
+ }
178
+ }
179
+ if (clip) {
180
+ // page.screenshot with clip lets the CDP scale param downscale the
181
+ // capture for viewport, full-page and element shots alike. We rely on
182
+ // Puppeteer's default of captureBeyondViewport=true when a clip is
183
+ // present so element/full-page captures below the fold still work.
184
+ screenshot = await page.screenshot({
185
+ type: format,
186
+ quality,
187
+ optimizeForSpeed: true,
188
+ clip,
189
+ });
190
+ }
191
+ else if (element) {
192
+ screenshot = await element.screenshot({
193
+ type: format,
194
+ quality,
195
+ optimizeForSpeed: true,
196
+ });
197
+ }
198
+ else {
199
+ screenshot = await page.screenshot({
200
+ type: format,
201
+ fullPage,
202
+ quality,
203
+ optimizeForSpeed: true,
204
+ });
205
+ }
206
+ if (request.params.uid) {
207
+ response.appendResponseLine(`Took a screenshot of node with uid "${request.params.uid}".`);
208
+ }
209
+ else if (fullPage) {
210
+ response.appendResponseLine('Took a screenshot of the full current page.');
211
+ }
212
+ else {
213
+ response.appendResponseLine("Took a screenshot of the current page's viewport.");
214
+ }
215
+ // Narrow `format` at the point of use: in the factory form of
216
+ // definePageTool TS widens the Schema generic, which loses the literal
217
+ // union from zod.enum on request.params.format.
218
+ const extension = format === 'jpeg' ? '.jpeg' : format === 'webp' ? '.webp' : '.png';
219
+ if (request.params.filePath) {
220
+ const result = await context.saveFile(screenshot, request.params.filePath, extension);
221
+ response.appendResponseLine(`Saved screenshot to ${result.filename}.`);
222
+ }
223
+ else if (screenshot.length >= 2_000_000) {
224
+ const { filepath } = await context.saveTemporaryFile(screenshot, `screenshot${extension}`);
225
+ response.appendResponseLine(`Saved screenshot to ${filepath}.`);
226
+ }
227
+ else {
228
+ response.attachImage({
229
+ mimeType: `image/${format}`,
230
+ data: Buffer.from(screenshot).toString('base64'),
231
+ });
109
232
  }
110
233
  }
111
- let screenshot;
112
- if (clip) {
113
- // page.screenshot with clip lets the CDP scale param downscale the
114
- // capture for viewport, full-page and element shots alike. We rely on
115
- // Puppeteer's default of captureBeyondViewport=true when a clip is
116
- // present so element/full-page captures below the fold still work.
117
- screenshot = await page.screenshot({
118
- type: format,
119
- quality,
120
- optimizeForSpeed: true,
121
- clip,
122
- });
123
- }
124
- else if (element) {
125
- screenshot = await element.screenshot({
126
- type: format,
127
- quality,
128
- optimizeForSpeed: true,
129
- });
130
- }
131
- else {
132
- screenshot = await page.screenshot({
133
- type: format,
134
- fullPage,
135
- quality,
136
- optimizeForSpeed: true,
137
- });
138
- }
139
- if (request.params.uid) {
140
- response.appendResponseLine(`Took a screenshot of node with uid "${request.params.uid}".`);
141
- }
142
- else if (fullPage) {
143
- response.appendResponseLine('Took a screenshot of the full current page.');
144
- }
145
- else {
146
- response.appendResponseLine("Took a screenshot of the current page's viewport.");
147
- }
148
- // Narrow `format` at the point of use: in the factory form of
149
- // definePageTool TS widens the Schema generic, which loses the literal
150
- // union from zod.enum on request.params.format.
151
- const extension = format === 'jpeg' ? '.jpeg' : format === 'webp' ? '.webp' : '.png';
152
- if (request.params.filePath) {
153
- const result = await context.saveFile(screenshot, request.params.filePath, extension);
154
- response.appendResponseLine(`Saved screenshot to ${result.filename}.`);
155
- }
156
- else if (screenshot.length >= 2_000_000) {
157
- const { filepath } = await context.saveTemporaryFile(screenshot, `screenshot${extension}`);
158
- response.appendResponseLine(`Saved screenshot to ${filepath}.`);
234
+ catch (e_1) {
235
+ env_1.error = e_1;
236
+ env_1.hasError = true;
159
237
  }
160
- else {
161
- response.attachImage({
162
- mimeType: `image/${format}`,
163
- data: Buffer.from(screenshot).toString('base64'),
164
- });
238
+ finally {
239
+ __disposeResources(env_1);
165
240
  }
166
241
  },
167
242
  };