opera-devtools-mcp 0.2.4 → 0.4.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 (330) hide show
  1. package/README.md +108 -8
  2. package/build/src/McpContext.js +365 -365
  3. package/build/src/McpPage.js +475 -48
  4. package/build/src/McpResponse.js +462 -288
  5. package/build/src/SlimMcpResponse.js +1 -1
  6. package/build/src/TextSnapshot.js +101 -22
  7. package/build/src/ToolHandler.js +142 -20
  8. package/build/src/bin/check-latest-version.js +27 -1
  9. package/build/src/bin/chrome-devtools-cli-options.js +614 -10
  10. package/build/src/bin/chrome-devtools-mcp-cli-options.js +119 -32
  11. package/build/src/bin/chrome-devtools-mcp-main.js +50 -7
  12. package/build/src/bin/chrome-devtools-mcp.js +7 -4
  13. package/build/src/bin/chrome-devtools.js +57 -14
  14. package/build/src/bin/opera-devtools-cli-options.js +3 -829
  15. package/build/src/bin/opera-devtools-mcp-cli-options.js +3 -348
  16. package/build/src/bin/opera-devtools-mcp-main.js +3 -37
  17. package/build/src/bin/opera-devtools-mcp.js +4 -19
  18. package/build/src/bin/opera-devtools.js +4 -185
  19. package/build/src/browser.js +45 -5
  20. package/build/src/{PageCollector.js → collectors/PageCollector.js} +64 -133
  21. package/build/src/collectors/ServiceWorkerCollector.js +171 -0
  22. package/build/src/daemon/client.js +75 -17
  23. package/build/src/daemon/daemon.js +92 -30
  24. package/build/src/daemon/utils.js +24 -8
  25. package/build/src/{DevtoolsUtils.js → devtools/DevtoolsUtils.js} +94 -88
  26. package/build/src/devtools/McpHostBindingAdapter.js +165 -0
  27. package/build/src/{issue-descriptions.js → devtools/issueDescriptions.js} +8 -6
  28. package/build/src/formatters/ConsoleFormatter.js +44 -11
  29. package/build/src/formatters/HeapSnapshotFormatter.js +140 -9
  30. package/build/src/formatters/IssueFormatter.js +7 -7
  31. package/build/src/formatters/NetworkFormatter.js +10 -8
  32. package/build/src/index.js +101 -232
  33. package/build/src/opera/branding.js +34 -0
  34. package/build/src/opera/browserFlags.js +85 -0
  35. package/build/src/opera/browserLaunch.js +52 -0
  36. package/build/src/opera/policy.js +50 -0
  37. package/build/src/opera/serviceWorkerRetry.js +37 -0
  38. package/build/src/opera/toolHandlerHooks.js +39 -0
  39. package/build/src/{tools → opera/tools}/opera.js +116 -21
  40. package/build/src/processors/HeapSnapshotManager.js +258 -0
  41. package/build/src/{trace-processing/parse.js → processors/PerformanceTrace.js} +9 -9
  42. package/build/src/telemetry/ClearcutLogger.js +12 -119
  43. package/build/src/telemetry/WatchdogClient.js +5 -5
  44. package/build/src/telemetry/errors.js +1 -1
  45. package/build/src/telemetry/flagUtils.js +6 -6
  46. package/build/src/telemetry/{toolMetricsUtils.js → metricsRegistry.js} +4 -11
  47. package/build/src/telemetry/persistence.js +3 -3
  48. package/build/src/telemetry/transformation.js +193 -0
  49. package/build/src/telemetry/watchdog/ClearcutSender.js +11 -11
  50. package/build/src/telemetry/watchdog/main.js +6 -6
  51. package/build/src/third_party/THIRD_PARTY_NOTICES +232 -1061
  52. package/build/src/third_party/bundled-packages.json +7 -8
  53. package/build/src/third_party/devtools-formatter-worker.js +63 -22
  54. package/build/src/third_party/devtools-heap-snapshot-worker.js +809 -182
  55. package/build/src/third_party/index.js +69558 -74691
  56. package/build/src/third_party/issue-descriptions/CoepCorpNotSameOrigin.md +2 -2
  57. package/build/src/third_party/issue-descriptions/CoepCorpNotSameOriginAfterDefaultedToSameOriginByCoep.md +3 -3
  58. package/build/src/third_party/issue-descriptions/CoepCorpNotSameSite.md +2 -2
  59. package/build/src/third_party/issue-descriptions/CoepFrameResourceNeedsCoepHeader.md +1 -1
  60. package/build/src/third_party/issue-descriptions/CompatibilityModeQuirks.md +1 -1
  61. package/build/src/third_party/issue-descriptions/CookieAttributeValueExceedsMaxSize.md +2 -2
  62. package/build/src/third_party/issue-descriptions/LowTextContrast.md +1 -1
  63. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureErrorRead.md +1 -1
  64. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureErrorSet.md +1 -1
  65. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureWarnRead.md +1 -1
  66. package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureWarnSet.md +1 -1
  67. package/build/src/third_party/issue-descriptions/SameSiteUnspecifiedLaxAllowUnsafeRead.md +3 -3
  68. package/build/src/third_party/issue-descriptions/SameSiteUnspecifiedLaxAllowUnsafeSet.md +3 -3
  69. package/build/src/third_party/issue-descriptions/bounceTrackingMitigations.md +1 -1
  70. package/build/src/third_party/issue-descriptions/connectionAllowlistEmbeddingRequirementNotSatisfied.md +26 -0
  71. package/build/src/third_party/issue-descriptions/connectionAllowlistIFrameAttributeLoosensEmbeddingRequirement.md +19 -0
  72. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowConnectionAllowlistFrom.md +21 -0
  73. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowlistItemType.md +2 -2
  74. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidHeader.md +2 -2
  75. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidUrlPattern.md +3 -3
  76. package/build/src/third_party/issue-descriptions/connectionAllowlistItemNotInnerList.md +2 -2
  77. package/build/src/third_party/issue-descriptions/connectionAllowlistMoreThanOneList.md +2 -2
  78. package/build/src/third_party/issue-descriptions/connectionAllowlistReportingEndpointNotToken.md +1 -1
  79. package/build/src/third_party/issue-descriptions/cookieCrossSiteRedirectDowngrade.md +3 -3
  80. package/build/src/third_party/issue-descriptions/cookieExcludeBlockedWithinRelatedWebsiteSet.md +1 -1
  81. package/build/src/third_party/issue-descriptions/cookieExcludePortMismatch.md +1 -1
  82. package/build/src/third_party/issue-descriptions/cookieExcludeSchemeMismatch.md +1 -1
  83. package/build/src/third_party/issue-descriptions/cookieExcludeThirdPartyPhaseoutSet.md +1 -1
  84. package/build/src/third_party/issue-descriptions/cookieWarnThirdPartyPhaseoutRead.md +1 -1
  85. package/build/src/third_party/issue-descriptions/corsAllowCredentialsRequired.md +1 -1
  86. package/build/src/third_party/issue-descriptions/corsDisabledScheme.md +2 -2
  87. package/build/src/third_party/issue-descriptions/corsDisallowedByMode.md +2 -2
  88. package/build/src/third_party/issue-descriptions/corsHeaderDisallowedByPreflightResponse.md +1 -1
  89. package/build/src/third_party/issue-descriptions/corsInvalidHeaderValues.md +3 -3
  90. package/build/src/third_party/issue-descriptions/corsLocalNetworkAccessPermissionDenied.md +1 -1
  91. package/build/src/third_party/issue-descriptions/corsMethodDisallowedByPreflightResponse.md +1 -1
  92. package/build/src/third_party/issue-descriptions/corsNoCorsRedirectModeNotFollow.md +1 -1
  93. package/build/src/third_party/issue-descriptions/corsOriginMismatch.md +3 -3
  94. package/build/src/third_party/issue-descriptions/corsPreflightResponseInvalid.md +2 -2
  95. package/build/src/third_party/issue-descriptions/corsRedirectContainsCredentials.md +3 -3
  96. package/build/src/third_party/issue-descriptions/corsWildcardOriginNotAllowed.md +4 -3
  97. package/build/src/third_party/issue-descriptions/cspEvalViolation.md +4 -4
  98. package/build/src/third_party/issue-descriptions/cspInlineViolation.md +2 -2
  99. package/build/src/third_party/issue-descriptions/cspTrustedTypesPolicyViolation.md +2 -2
  100. package/build/src/third_party/issue-descriptions/cspTrustedTypesSinkViolation.md +4 -4
  101. package/build/src/third_party/issue-descriptions/cspURLViolation.md +4 -4
  102. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsEmptyList.md +1 -0
  103. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsHttpNotFound.md +1 -0
  104. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsInvalidContentType.md +1 -0
  105. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsInvalidResponse.md +1 -0
  106. package/build/src/third_party/issue-descriptions/emailVerificationRequestAccountsNoResponse.md +1 -0
  107. package/build/src/third_party/issue-descriptions/emailVerificationRequestDnsFetchFailed.md +1 -0
  108. package/build/src/third_party/issue-descriptions/emailVerificationRequestDnsInvalidRecord.md +1 -0
  109. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownHttpNotFound.md +1 -0
  110. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownInvalidContentType.md +1 -0
  111. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownInvalidResponse.md +1 -0
  112. package/build/src/third_party/issue-descriptions/emailVerificationRequestEmailVerificationWellKnownNoResponse.md +1 -0
  113. package/build/src/third_party/issue-descriptions/emailVerificationRequestInvalidEmail.md +1 -0
  114. package/build/src/third_party/issue-descriptions/emailVerificationRequestJwksHttpNotFound.md +1 -0
  115. package/build/src/third_party/issue-descriptions/emailVerificationRequestJwksInvalidResponse.md +1 -0
  116. package/build/src/third_party/issue-descriptions/emailVerificationRequestKeyBindingSigningFailed.md +1 -0
  117. package/build/src/third_party/issue-descriptions/emailVerificationRequestRpOriginIsOpaque.md +1 -0
  118. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenHttpNotFound.md +1 -0
  119. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidContentType.md +1 -0
  120. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidResponse.md +1 -0
  121. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenInvalidSdJwt.md +1 -0
  122. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenMalformedSdJwt.md +1 -0
  123. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenNoResponse.md +1 -0
  124. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidAudience.md +1 -0
  125. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidIssuedAt.md +1 -0
  126. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidNonce.md +1 -0
  127. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidSdHash.md +1 -0
  128. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbInvalidTyp.md +1 -0
  129. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingAud.md +1 -0
  130. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingCnf.md +1 -0
  131. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingIat.md +1 -0
  132. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingNonce.md +1 -0
  133. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbMissingSdHash.md +1 -0
  134. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationKbSignatureFailed.md +1 -0
  135. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidEmail.md +1 -0
  136. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidEmailVerified.md +1 -0
  137. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidHolderKey.md +1 -0
  138. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidIssuedAt.md +1 -0
  139. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtInvalidIssuer.md +1 -0
  140. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtJwksMissingKeys.md +1 -0
  141. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingCnf.md +1 -0
  142. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingEmail.md +1 -0
  143. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingIat.md +1 -0
  144. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtMissingIss.md +1 -0
  145. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtSignatureFailed.md +1 -0
  146. package/build/src/third_party/issue-descriptions/emailVerificationRequestTokenVerificationSdJwtUnsupportedHeaderAlg.md +1 -0
  147. package/build/src/third_party/issue-descriptions/emailVerificationRequestUserLoggedOut.md +1 -0
  148. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownAccountsEndpointCrossOrigin.md +1 -0
  149. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownHttpNotFound.md +1 -0
  150. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownInvalidContentType.md +1 -0
  151. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownInvalidResponse.md +1 -0
  152. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownIssuanceEndpointCrossOrigin.md +1 -0
  153. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownListEmpty.md +1 -0
  154. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownMissingAccountsEndpoint.md +1 -0
  155. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownMissingIssuanceEndpoint.md +1 -0
  156. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownNoResponse.md +1 -0
  157. package/build/src/third_party/issue-descriptions/emailVerificationRequestWellKnownUnsupportedSigningAlgorithm.md +1 -0
  158. package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsHttpNotFound.md +1 -1
  159. package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsInvalidResponse.md +1 -1
  160. package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsNoResponse.md +1 -1
  161. package/build/src/third_party/issue-descriptions/federatedAuthRequestApprovalDeclined.md +1 -1
  162. package/build/src/third_party/issue-descriptions/federatedAuthRequestCanceled.md +1 -1
  163. package/build/src/third_party/issue-descriptions/federatedAuthRequestErrorFetchingSignin.md +1 -1
  164. package/build/src/third_party/issue-descriptions/federatedAuthRequestErrorIdToken.md +1 -1
  165. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenHttpNotFound.md +1 -1
  166. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenInvalidRequest.md +1 -1
  167. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenInvalidResponse.md +1 -1
  168. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenNoResponse.md +1 -1
  169. package/build/src/third_party/issue-descriptions/federatedAuthRequestInvalidSigninResponse.md +1 -1
  170. package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestHttpNotFound.md +1 -1
  171. package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestInvalidResponse.md +1 -1
  172. package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestNoResponse.md +1 -1
  173. package/build/src/third_party/issue-descriptions/federatedAuthRequestTooManyRequests.md +1 -1
  174. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestInvalidAccountsResponse.md +1 -1
  175. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestInvalidConfigOrWellKnown.md +1 -1
  176. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoAccountSharingPermission.md +1 -1
  177. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoApiPermission.md +1 -1
  178. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoReturningUserFromFetchedAccounts.md +1 -1
  179. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotIframe.md +1 -1
  180. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotPotentiallyTrustworthy.md +1 -1
  181. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotSameOrigin.md +1 -1
  182. package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotSignedInWithIdp.md +1 -1
  183. package/build/src/third_party/issue-descriptions/fetchingPartitionedBlobURL.md +2 -2
  184. package/build/src/third_party/issue-descriptions/genericBackUINavigationWouldSkipAd.md +4 -0
  185. package/build/src/third_party/issue-descriptions/genericFormAriaLabelledByToNonExistingIdError.md +2 -2
  186. package/build/src/third_party/issue-descriptions/genericFormAutocompleteAttributeEmptyError.md +1 -1
  187. package/build/src/third_party/issue-descriptions/genericFormDuplicateIdForInputError.md +1 -1
  188. package/build/src/third_party/issue-descriptions/genericFormEmptyIdAndNameAttributesForInputError.md +2 -2
  189. package/build/src/third_party/issue-descriptions/genericFormInputAssignedAutocompleteValueToIdOrNameAttributeError.md +2 -2
  190. package/build/src/third_party/issue-descriptions/genericFormInputHasWrongButWellIntendedAutocompleteValueError.md +1 -1
  191. package/build/src/third_party/issue-descriptions/genericFormInputWithNoLabelError.md +1 -1
  192. package/build/src/third_party/issue-descriptions/genericFormLabelForMatchesNonExistingIdError.md +2 -2
  193. package/build/src/third_party/issue-descriptions/genericFormLabelForNameError.md +1 -1
  194. package/build/src/third_party/issue-descriptions/genericFormLabelHasNeitherForNorNestedInputError.md +1 -1
  195. package/build/src/third_party/issue-descriptions/genericFormModelContextMissingToolName.md +1 -1
  196. package/build/src/third_party/issue-descriptions/genericFormModelContextParameterMissingName.md +1 -1
  197. package/build/src/third_party/issue-descriptions/genericFormModelContextRequiredParameterMissingName.md +1 -1
  198. package/build/src/third_party/issue-descriptions/genericNavigationEntryMarkedSkippable.md +2 -2
  199. package/build/src/third_party/issue-descriptions/heavyAd.md +1 -1
  200. package/build/src/third_party/issue-descriptions/lazyLoadImageZeroSize.md +7 -0
  201. package/build/src/third_party/issue-descriptions/navigatingPartitionedBlobURL.md +3 -3
  202. package/build/src/third_party/issue-descriptions/permissionElementActivationDisabled.md +1 -1
  203. package/build/src/third_party/issue-descriptions/permissionElementActivationDisabledWithOccluder.md +1 -1
  204. package/build/src/third_party/issue-descriptions/permissionElementActivationDisabledWithOccluderParent.md +1 -1
  205. package/build/src/third_party/issue-descriptions/permissionElementFencedFrameDisallowed.md +2 -2
  206. package/build/src/third_party/issue-descriptions/permissionElementFontSizeTooLarge.md +2 -2
  207. package/build/src/third_party/issue-descriptions/permissionElementFontSizeTooSmall.md +2 -2
  208. package/build/src/third_party/issue-descriptions/permissionElementInsetBoxShadowUnsupported.md +1 -1
  209. package/build/src/third_party/issue-descriptions/permissionElementInvalidDisplayStyle.md +2 -2
  210. package/build/src/third_party/issue-descriptions/permissionElementInvalidSizeValue.md +2 -2
  211. package/build/src/third_party/issue-descriptions/permissionElementInvalidType.md +2 -2
  212. package/build/src/third_party/issue-descriptions/permissionElementInvalidTypeActivation.md +2 -2
  213. package/build/src/third_party/issue-descriptions/permissionElementNonOpaqueColor.md +1 -1
  214. package/build/src/third_party/issue-descriptions/permissionElementPaddingBottomUnsupported.md +2 -2
  215. package/build/src/third_party/issue-descriptions/permissionElementPaddingRightUnsupported.md +2 -2
  216. package/build/src/third_party/issue-descriptions/permissionElementRequestInProgress.md +2 -2
  217. package/build/src/third_party/issue-descriptions/permissionElementSecurityChecksFailed.md +1 -1
  218. package/build/src/third_party/issue-descriptions/permissionElementTypeNotSupported.md +2 -2
  219. package/build/src/third_party/issue-descriptions/permissionElementUntrustedEvent.md +1 -1
  220. package/build/src/third_party/issue-descriptions/placeholderDescriptionForInvisibleIssues.md +1 -1
  221. package/build/src/third_party/issue-descriptions/selectElementAccessibilityDisallowedOptGroupChild.md +1 -1
  222. package/build/src/third_party/issue-descriptions/selectElementAccessibilityDisallowedSelectChild.md +1 -1
  223. package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentAttributesSelectDescendant.md +1 -1
  224. package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentLegendChild.md +1 -1
  225. package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentOptionChild.md +1 -1
  226. package/build/src/third_party/issue-descriptions/selectElementAccessibilityNonPhrasingContentOptionChild.md +1 -1
  227. package/build/src/third_party/issue-descriptions/selectivePermissionsIntervention.md +3 -3
  228. package/build/src/third_party/issue-descriptions/sharedArrayBuffer.md +1 -1
  229. package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorCrossOriginNoCorsRequest.md +1 -1
  230. package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorMatchingDictionaryNotUsed.md +1 -1
  231. package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorUnexpectedContentDictionaryHeader.md +1 -1
  232. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorCossOriginNoCorsRequest.md +1 -1
  233. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorDisallowedBySettings.md +1 -1
  234. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorExpiredResponse.md +1 -1
  235. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorFeatureDisabled.md +2 -2
  236. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorInvalidStructuredHeader.md +1 -1
  237. package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNavigationRequest.md +2 -2
  238. package/build/src/third_party/issue-descriptions/sriInvalidSignatureHeader.md +4 -4
  239. package/build/src/third_party/issue-descriptions/sriInvalidSignatureInputHeader.md +4 -4
  240. package/build/src/third_party/issue-descriptions/sriMissingSignatureHeader.md +1 -1
  241. package/build/src/third_party/issue-descriptions/sriMissingSignatureInputHeader.md +2 -2
  242. package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsIncorrectLength.md +2 -2
  243. package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsNotByteSequence.md +4 -4
  244. package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsParameterized.md +4 -4
  245. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidComponentName.md +1 -1
  246. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidComponentType.md +2 -2
  247. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidDerivedComponentParameter.md +1 -1
  248. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidHeaderComponentParameter.md +1 -1
  249. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidParameter.md +2 -2
  250. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderKeyIdLength.md +5 -5
  251. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderMissingLabel.md +3 -3
  252. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderMissingRequiredParameters.md +2 -2
  253. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderValueMissingComponents.md +2 -2
  254. package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderValueNotInnerList.md +2 -2
  255. package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +4 -4
  256. package/build/src/third_party/issue-descriptions/sriValidationFailedInvalidLength.md +3 -3
  257. package/build/src/third_party/issue-descriptions/sriValidationFailedSignatureExpired.md +2 -2
  258. package/build/src/third_party/issue-descriptions/sriValidationFailedSignatureMismatch.md +2 -2
  259. package/build/src/third_party/issue-descriptions/stylesheetLateImport.md +1 -1
  260. package/build/src/third_party/issue-descriptions/summaryElementAccessibilityInteractiveContentSummaryDescendant.md +1 -1
  261. package/build/src/third_party/issue-descriptions/unencodedDigestIncorrectDigestLength.md +2 -2
  262. package/build/src/third_party/issue-descriptions/unencodedDigestIncorrectDigestType.md +3 -3
  263. package/build/src/third_party/issue-descriptions/unencodedDigestMalformedDictionary.md +2 -2
  264. package/build/src/third_party/issue-descriptions/unencodedDigestUnknownAlgorithm.md +1 -1
  265. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +3177 -6340
  266. package/build/src/tools/ToolDefinition.js +2 -2
  267. package/build/src/tools/categories.js +3 -0
  268. package/build/src/tools/console.js +13 -0
  269. package/build/src/tools/emulation.js +30 -3
  270. package/build/src/tools/extensions.js +8 -1
  271. package/build/src/tools/input.js +246 -128
  272. package/build/src/tools/lighthouse.js +14 -7
  273. package/build/src/tools/memory.js +289 -25
  274. package/build/src/tools/network.js +10 -7
  275. package/build/src/tools/pages.js +33 -92
  276. package/build/src/tools/performance.js +67 -52
  277. package/build/src/tools/pwa.js +128 -0
  278. package/build/src/tools/screencast.js +35 -12
  279. package/build/src/tools/screenshot.js +234 -75
  280. package/build/src/tools/script.js +130 -45
  281. package/build/src/tools/slim/tools.js +3 -0
  282. package/build/src/tools/snapshot.js +7 -4
  283. package/build/src/tools/thirdPartyDeveloper.js +19 -9
  284. package/build/src/tools/tools.js +3 -1
  285. package/build/src/tools/webmcp.js +3 -1
  286. package/build/src/utils/WaitForHelper.js +299 -0
  287. package/build/src/utils/check-for-updates.js +8 -2
  288. package/build/src/utils/files.js +42 -3
  289. package/build/src/utils/logger.js +51 -0
  290. package/build/src/utils/polyfill.js +11 -0
  291. package/build/src/utils/url.js +43 -0
  292. package/build/src/version.js +1 -4
  293. package/package.json +43 -33
  294. package/build/src/DevToolsConnectionAdapter.js +0 -70
  295. package/build/src/HeapSnapshotManager.js +0 -110
  296. package/build/src/Mutex.js +0 -38
  297. package/build/src/WaitForHelper.js +0 -195
  298. package/build/src/bin/cliDefinitions.js +0 -616
  299. package/build/src/logger.js +0 -37
  300. package/build/src/polyfill.js +0 -8
  301. package/build/src/telemetry/metricUtils.js +0 -15
  302. package/build/src/third_party/issue-descriptions/SameSiteExcludeContextDowngradeRead.md +0 -8
  303. package/build/src/third_party/issue-descriptions/SameSiteExcludeContextDowngradeSet.md +0 -8
  304. package/build/src/third_party/issue-descriptions/SameSiteExcludeNavigationContextDowngrade.md +0 -8
  305. package/build/src/third_party/issue-descriptions/SameSiteWarnCrossDowngradeRead.md +0 -8
  306. package/build/src/third_party/issue-descriptions/SameSiteWarnCrossDowngradeSet.md +0 -8
  307. package/build/src/third_party/issue-descriptions/SameSiteWarnStrictLaxDowngradeStrict.md +0 -8
  308. package/build/src/third_party/issue-descriptions/arInsecureContext.md +0 -7
  309. package/build/src/third_party/issue-descriptions/arInvalidInfoHeader.md +0 -5
  310. package/build/src/third_party/issue-descriptions/arInvalidRegisterOsSourceHeader.md +0 -5
  311. package/build/src/third_party/issue-descriptions/arInvalidRegisterOsTriggerHeader.md +0 -5
  312. package/build/src/third_party/issue-descriptions/arInvalidRegisterSourceHeader.md +0 -5
  313. package/build/src/third_party/issue-descriptions/arInvalidRegisterTriggerHeader.md +0 -5
  314. package/build/src/third_party/issue-descriptions/arNavigationRegistrationUniqueScopeAlreadySet.md +0 -5
  315. package/build/src/third_party/issue-descriptions/arNavigationRegistrationWithoutTransientUserActivation.md +0 -6
  316. package/build/src/third_party/issue-descriptions/arNoRegisterOsSourceHeader.md +0 -5
  317. package/build/src/third_party/issue-descriptions/arNoRegisterOsTriggerHeader.md +0 -5
  318. package/build/src/third_party/issue-descriptions/arNoRegisterSourceHeader.md +0 -5
  319. package/build/src/third_party/issue-descriptions/arNoRegisterTriggerHeader.md +0 -5
  320. package/build/src/third_party/issue-descriptions/arNoWebOrOsSupport.md +0 -4
  321. package/build/src/third_party/issue-descriptions/arOsSourceIgnored.md +0 -18
  322. package/build/src/third_party/issue-descriptions/arOsTriggerIgnored.md +0 -19
  323. package/build/src/third_party/issue-descriptions/arPermissionPolicyDisabled.md +0 -8
  324. package/build/src/third_party/issue-descriptions/arSourceAndTriggerHeaders.md +0 -9
  325. package/build/src/third_party/issue-descriptions/arSourceIgnored.md +0 -13
  326. package/build/src/third_party/issue-descriptions/arTriggerIgnored.md +0 -12
  327. package/build/src/third_party/issue-descriptions/arUntrustworthyReportingOrigin.md +0 -10
  328. package/build/src/third_party/issue-descriptions/arWebAndOsHeaders.md +0 -11
  329. package/build/src/utils/string.js +0 -37
  330. package/build/src/utils/types.js +0 -7
@@ -3,85 +3,244 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { zod } from '../third_party/index.js';
7
- import { ToolCategory } from './categories.js';
8
- import { definePageTool } from './ToolDefinition.js';
9
- export const screenshot = definePageTool({
10
- name: 'take_screenshot',
11
- description: `Take a screenshot of the page or element.`,
12
- annotations: {
13
- category: ToolCategory.DEBUGGING,
14
- // Not read-only due to filePath param.
15
- readOnlyHint: false,
16
- },
17
- schema: {
18
- format: zod
19
- .enum(['png', 'jpeg', 'webp'])
20
- .default('png')
21
- .describe('Type of format to save the screenshot as. Default is "png"'),
22
- quality: zod
23
- .number()
24
- .min(0)
25
- .max(100)
26
- .optional()
27
- .describe('Compression quality for JPEG and WebP formats (0-100). Higher values mean better quality but larger file sizes. Ignored for PNG format.'),
28
- uid: zod
29
- .string()
30
- .optional()
31
- .describe('The uid of an element on the page from the page content snapshot. If omitted, takes a page screenshot.'),
32
- fullPage: zod
33
- .boolean()
34
- .optional()
35
- .describe('If set to true takes a screenshot of the full page instead of the currently visible viewport. Incompatible with uid.'),
36
- filePath: zod
37
- .string()
38
- .optional()
39
- .describe('The absolute path, or a path relative to the current working directory, to save the screenshot to instead of attaching it to the response.'),
40
- },
41
- blockedByDialog: true,
42
- handler: async (request, response, context) => {
43
- context.validatePath(request.params.filePath);
44
- if (request.params.uid && request.params.fullPage) {
45
- throw new Error('Providing both "uid" and "fullPage" is not allowed.');
46
- }
47
- let pageOrHandle;
48
- if (request.params.uid) {
49
- pageOrHandle = await request.page.getElementByUid(request.params.uid);
50
- }
51
- else {
52
- pageOrHandle = request.page.pptrPage;
53
- }
54
- const format = request.params.format;
55
- const quality = format === 'png' ? undefined : request.params.quality;
56
- const screenshot = await pageOrHandle.screenshot({
57
- type: format,
58
- fullPage: request.params.fullPage,
59
- quality,
60
- optimizeForSpeed: true, // Bonus: optimize encoding for speed
61
- });
62
- if (request.params.uid) {
63
- response.appendResponseLine(`Took a screenshot of node with uid "${request.params.uid}".`);
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];
64
13
  }
65
- else if (request.params.fullPage) {
66
- response.appendResponseLine('Took a screenshot of the full current page.');
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;
67
18
  }
68
- else {
69
- response.appendResponseLine("Took a screenshot of the current page's viewport.");
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;
70
33
  }
71
- if (request.params.filePath) {
72
- const result = await context.saveFile(screenshot, request.params.filePath, `.${format}`);
73
- response.appendResponseLine(`Saved screenshot to ${result.filename}.`);
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;
74
51
  }
75
- else if (screenshot.length >= 2_000_000) {
76
- const { filepath } = await context.saveTemporaryFile(screenshot, `screenshot.${request.params.format}`);
77
- response.appendResponseLine(`Saved screenshot to ${filepath}.`);
78
- }
79
- else {
80
- response.attachImage({
81
- mimeType: `image/${request.params.format}`,
82
- data: Buffer.from(screenshot).toString('base64'),
83
- });
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 { zod } from '../third_party/index.js';
59
+ import { ToolCategory } from './categories.js';
60
+ import { definePageTool } from './ToolDefinition.js';
61
+ async function getSourceBox(page, element, fullPage) {
62
+ if (element) {
63
+ const box = await element.boundingBox();
64
+ return box ?? undefined;
65
+ }
66
+ if (fullPage) {
67
+ const dims = await page.evaluate(() => ({
68
+ width: Math.max(document.documentElement.scrollWidth, document.body?.scrollWidth ?? 0),
69
+ height: Math.max(document.documentElement.scrollHeight, document.body?.scrollHeight ?? 0),
70
+ }));
71
+ if (dims.width <= 0 || dims.height <= 0) {
72
+ return undefined;
84
73
  }
85
- },
74
+ return { x: 0, y: 0, width: dims.width, height: dims.height };
75
+ }
76
+ const viewport = page.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) {
88
+ return undefined;
89
+ }
90
+ return { x: 0, y: 0, width: dims.width, height: dims.height };
91
+ }
92
+ function computeDownscaleClip(box, maxWidth, maxHeight) {
93
+ const widthScale = maxWidth !== undefined ? Math.min(1, maxWidth / box.width) : 1;
94
+ const heightScale = maxHeight !== undefined ? Math.min(1, maxHeight / box.height) : 1;
95
+ const scale = Math.min(widthScale, heightScale);
96
+ if (scale >= 1) {
97
+ return undefined;
98
+ }
99
+ // Skip degenerate sub-pixel results.
100
+ if (Math.round(box.width * scale) < 1 || Math.round(box.height * scale) < 1) {
101
+ return undefined;
102
+ }
103
+ return {
104
+ x: box.x,
105
+ y: box.y,
106
+ width: box.width,
107
+ height: box.height,
108
+ scale,
109
+ };
110
+ }
111
+ export const screenshot = definePageTool(args => {
112
+ const { screenshotFormat, screenshotQuality, screenshotMaxWidth, screenshotMaxHeight, } = args ?? {};
113
+ const defaultFormat = screenshotFormat ?? 'png';
114
+ return {
115
+ name: 'take_screenshot',
116
+ description: `Take a screenshot of the page or element.`,
117
+ annotations: {
118
+ category: ToolCategory.DEBUGGING,
119
+ // Not read-only due to filePath param.
120
+ readOnlyHint: false,
121
+ },
122
+ schema: {
123
+ format: zod
124
+ .enum(['png', 'jpeg', 'webp'])
125
+ .default(defaultFormat)
126
+ .describe(`Type of format to save the screenshot as. Default is "${defaultFormat}"`),
127
+ quality: zod
128
+ .number()
129
+ .min(0)
130
+ .max(100)
131
+ .optional()
132
+ .describe('Compression quality for JPEG and WebP formats (0-100). Higher values mean better quality but larger file sizes. Ignored for PNG format.'),
133
+ uid: zod
134
+ .string()
135
+ .optional()
136
+ .describe('The uid of an element on the page from the page content snapshot. If omitted, takes a page screenshot.'),
137
+ fullPage: zod
138
+ .boolean()
139
+ .optional()
140
+ .describe('If set to true takes a screenshot of the full page instead of the currently visible viewport. Incompatible with uid.'),
141
+ filePath: zod
142
+ .string()
143
+ .optional()
144
+ .describe('The absolute path, or a path relative to the current working directory, to save the screenshot to instead of attaching it to the response.'),
145
+ },
146
+ blockedByDialog: true,
147
+ verifyFilesSchema: {
148
+ filePath: true,
149
+ },
150
+ handler: async (request, response, context) => {
151
+ const env_1 = { stack: [], error: void 0, hasError: false };
152
+ try {
153
+ if (request.params.uid && request.params.fullPage) {
154
+ throw new Error('Providing both "uid" and "fullPage" is not allowed.');
155
+ }
156
+ const page = request.page.pptrPage;
157
+ const element = __addDisposableResource(env_1, request.params.uid
158
+ ? await request.page.getElementByUid(request.params.uid)
159
+ : undefined, false);
160
+ const format = request.params.format;
161
+ const quality = format === 'png'
162
+ ? undefined
163
+ : (request.params.quality ?? screenshotQuality);
164
+ const fullPage = request.params.fullPage ?? false;
165
+ // `getElementByUid` mints a fresh ElementHandle per call, so dispose it
166
+ // once the capture is done to avoid leaking a remote object for the life
167
+ // of the page's execution context.
168
+ let screenshot;
169
+ // Compute a downscale clip when --screenshot-max-width or
170
+ // --screenshot-max-height is set and the source exceeds either bound.
171
+ // The smaller scale factor wins so both bounds are respected while
172
+ // preserving aspect ratio.
173
+ let clip;
174
+ if (screenshotMaxWidth !== undefined ||
175
+ screenshotMaxHeight !== undefined) {
176
+ const box = await getSourceBox(page, element, fullPage);
177
+ if (box) {
178
+ clip = computeDownscaleClip(box, screenshotMaxWidth, screenshotMaxHeight);
179
+ }
180
+ }
181
+ if (clip) {
182
+ // page.screenshot with clip lets the CDP scale param downscale the
183
+ // capture for viewport, full-page and element shots alike. We rely on
184
+ // Puppeteer's default of captureBeyondViewport=true when a clip is
185
+ // present so element/full-page captures below the fold still work.
186
+ screenshot = await page.screenshot({
187
+ type: format,
188
+ quality,
189
+ optimizeForSpeed: true,
190
+ clip,
191
+ });
192
+ }
193
+ else if (element) {
194
+ screenshot = await element.screenshot({
195
+ type: format,
196
+ quality,
197
+ optimizeForSpeed: true,
198
+ });
199
+ }
200
+ else {
201
+ screenshot = await page.screenshot({
202
+ type: format,
203
+ fullPage,
204
+ quality,
205
+ optimizeForSpeed: true,
206
+ });
207
+ }
208
+ if (request.params.uid) {
209
+ response.appendResponseLine(`Took a screenshot of node with uid "${request.params.uid}".`);
210
+ }
211
+ else if (fullPage) {
212
+ response.appendResponseLine('Took a screenshot of the full current page.');
213
+ }
214
+ else {
215
+ response.appendResponseLine("Took a screenshot of the current page's viewport.");
216
+ }
217
+ // Narrow `format` at the point of use: in the factory form of
218
+ // definePageTool TS widens the Schema generic, which loses the literal
219
+ // union from zod.enum on request.params.format.
220
+ const extension = format === 'jpeg' ? '.jpeg' : format === 'webp' ? '.webp' : '.png';
221
+ if (request.params.filePath) {
222
+ const result = await context.saveFile(screenshot, request.params.filePath, extension);
223
+ response.appendResponseLine(`Saved screenshot to ${result.filename}.`);
224
+ }
225
+ else if (screenshot.length >= 2_000_000) {
226
+ const { filepath } = await context.saveTemporaryFile(screenshot, `screenshot${extension}`);
227
+ response.appendResponseLine(`Saved screenshot to ${filepath}.`);
228
+ }
229
+ else {
230
+ response.attachImage({
231
+ mimeType: `image/${format}`,
232
+ data: Buffer.from(screenshot).toString('base64'),
233
+ });
234
+ }
235
+ }
236
+ catch (e_1) {
237
+ env_1.error = e_1;
238
+ env_1.hasError = true;
239
+ }
240
+ finally {
241
+ __disposeResources(env_1);
242
+ }
243
+ },
244
+ };
86
245
  });
87
246
  //# sourceMappingURL=screenshot.js.map
@@ -3,29 +3,74 @@
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
- import { appendWaitForResult } from '../WaitForHelper.js';
8
59
  import { ToolCategory } from './categories.js';
9
60
  import { defineTool, pageIdSchema } from './ToolDefinition.js';
10
61
  export const evaluateScript = defineTool(cliArgs => {
11
62
  return {
12
63
  name: 'evaluate_script',
13
- description: `Evaluate a JavaScript function inside the currently selected page${cliArgs?.categoryExtensions ? ' or service worker' : ''}. Returns the response as JSON,
14
- so returned values have to be JSON-serializable.`,
64
+ 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.`,
15
65
  annotations: {
16
66
  category: ToolCategory.DEBUGGING,
17
67
  readOnlyHint: false,
18
68
  },
19
69
  schema: {
70
+ ...(cliArgs?.experimentalPageIdRouting ? pageIdSchema : {}),
20
71
  function: zod.string().describe(`A JavaScript function declaration to be executed by the tool in the currently selected page.
21
- Example without arguments: \`() => {
22
- return document.title
23
- }\` or \`async () => {
24
- return await fetch("example.com")
25
- }\`.
26
- Example with arguments: \`(el) => {
27
- return el.innerText;
28
- }\`
72
+ Example without arguments: \`() => document.title\` or \`async () => await fetch("example.com")\`.
73
+ Example with arguments: \`(el) => el.innerText\`
29
74
  `),
30
75
  args: zod
31
76
  .array(zod
@@ -33,11 +78,18 @@ Example with arguments: \`(el) => {
33
78
  .describe('The uid of an element on the page from the page content snapshot'))
34
79
  .optional()
35
80
  .describe(`An optional list of arguments to pass to the function.`),
81
+ filePath: zod
82
+ .string()
83
+ .optional()
84
+ .describe('The absolute or relative path to a file to save the script output to. If omitted, the output is returned inline.'),
36
85
  dialogAction: zod
37
86
  .string()
38
87
  .optional()
39
88
  .describe('Handle dialogs while execution. "accept", "dismiss", or string for response of window.prompt. Defaults to accept.'),
40
- ...(cliArgs?.experimentalPageIdRouting ? pageIdSchema : {}),
89
+ waitForStableDom: zod
90
+ .boolean()
91
+ .optional()
92
+ .describe('Whether to wait for the DOM to settle. Pass false if the script only reads data. Defaults to true.'),
41
93
  ...(cliArgs?.categoryExtensions
42
94
  ? {
43
95
  serviceWorkerId: zod
@@ -48,62 +100,95 @@ Example with arguments: \`(el) => {
48
100
  : {}),
49
101
  },
50
102
  blockedByDialog: true,
103
+ verifyFilesSchema: {
104
+ filePath: true,
105
+ },
51
106
  handler: async (request, response, context) => {
52
- const { serviceWorkerId, args: uidArgs, function: fnString, pageId, dialogAction, } = request.params;
53
- if (cliArgs?.categoryExtensions && serviceWorkerId) {
54
- if (uidArgs && uidArgs.length > 0) {
55
- throw new Error('args (element uids) cannot be used when evaluating in a service worker.');
56
- }
57
- if (pageId) {
58
- throw new Error('specify either a pageId or a serviceWorkerId.');
59
- }
60
- const worker = await getWebWorker(context, serviceWorkerId);
61
- const result = await context
62
- .getSelectedMcpPage()
63
- .waitForEventsAfterAction(async () => {
64
- await performEvaluation(worker, fnString, [], response);
65
- }, { handleDialog: dialogAction ?? 'accept' });
66
- appendWaitForResult(response, result);
67
- return;
68
- }
69
- const mcpPage = cliArgs?.experimentalPageIdRouting
70
- ? context.getPageById(request.params.pageId)
71
- : context.getSelectedMcpPage();
72
- const page = mcpPage.pptrPage;
73
- const args = [];
107
+ const env_1 = { stack: [], error: void 0, hasError: false };
74
108
  try {
109
+ const { serviceWorkerId, args: uidArgs, function: fnString, pageId, dialogAction, filePath, waitForStableDom, } = request.params;
110
+ if (cliArgs?.categoryExtensions && serviceWorkerId) {
111
+ if (uidArgs && uidArgs.length > 0) {
112
+ throw new Error('args (element uids) cannot be used when evaluating in a service worker.');
113
+ }
114
+ if (pageId) {
115
+ throw new Error('specify either a pageId or a serviceWorkerId.');
116
+ }
117
+ const worker = await getWebWorker(context, serviceWorkerId);
118
+ const result = await context
119
+ .getSelectedMcpPage()
120
+ .waitForEventsAfterAction(async () => {
121
+ await performEvaluation(worker, fnString, [], response, {
122
+ filePath,
123
+ context,
124
+ });
125
+ },
126
+ // Service workers cannot interact with the DOM, so never wait for it.
127
+ { handleDialog: dialogAction ?? 'accept', waitForStableDom: false });
128
+ if (result.dialogHandled) {
129
+ context.getSelectedMcpPage().clearDialog();
130
+ }
131
+ response.attachWaitForResult(result);
132
+ return;
133
+ }
134
+ const mcpPage = cliArgs?.experimentalPageIdRouting
135
+ ? context.getPageById(request.params.pageId)
136
+ : context.getSelectedMcpPage();
137
+ const page = mcpPage.pptrPage;
138
+ const args = [];
139
+ const stack = __addDisposableResource(env_1, new DisposableStack(), false);
75
140
  const frames = new Set();
76
141
  for (const uid of uidArgs ?? []) {
77
142
  const handle = await mcpPage.getElementByUid(uid);
78
143
  frames.add(handle.frame);
144
+ stack.use(handle);
79
145
  args.push(handle);
80
146
  }
81
147
  const evaluatable = await getPageOrFrame(page, frames);
82
148
  const result = await mcpPage.waitForEventsAfterAction(async () => {
83
- await performEvaluation(evaluatable, fnString, args, response);
84
- }, { handleDialog: dialogAction ?? 'accept' });
85
- appendWaitForResult(response, result);
149
+ await performEvaluation(evaluatable, fnString, args, response, {
150
+ filePath,
151
+ context,
152
+ });
153
+ }, { handleDialog: dialogAction ?? 'accept', waitForStableDom });
154
+ response.attachWaitForResult(result);
155
+ }
156
+ catch (e_1) {
157
+ env_1.error = e_1;
158
+ env_1.hasError = true;
86
159
  }
87
160
  finally {
88
- void Promise.allSettled(args.map(arg => arg.dispose()));
161
+ __disposeResources(env_1);
89
162
  }
90
163
  },
91
164
  };
92
165
  });
93
- const performEvaluation = async (evaluatable, fnString, args, response) => {
94
- const fn = await evaluatable.evaluateHandle(`(${fnString})`);
166
+ const performEvaluation = async (evaluatable, fnString, args, response, options) => {
167
+ const env_2 = { stack: [], error: void 0, hasError: false };
95
168
  try {
169
+ const fn = __addDisposableResource(env_2, await evaluatable.evaluateHandle(`(${fnString})`), false);
96
170
  const result = await evaluatable.evaluate(async (fn, ...args) => {
97
171
  // @ts-expect-error no types for function fn
98
172
  return JSON.stringify(await fn(...args));
99
173
  }, fn, ...args);
100
- response.appendResponseLine('Script ran on page and returned:');
101
- response.appendResponseLine('```json');
102
- response.appendResponseLine(`${result}`);
103
- response.appendResponseLine('```');
174
+ if (options?.filePath) {
175
+ const data = new TextEncoder().encode(result ?? 'undefined');
176
+ const { filename } = await options.context.saveFile(data, options.filePath, '.json');
177
+ response.appendResponseLine(`Script ran on page. Output saved to ${filename}.`);
178
+ }
179
+ else {
180
+ response.appendResponseLine('Script ran on page and returned:');
181
+ response.appendResponseLine('```json');
182
+ response.appendResponseLine(`${result}`);
183
+ response.appendResponseLine('```');
184
+ }
185
+ }
186
+ catch (e_2) {
187
+ env_2.error = e_2;
188
+ env_2.hasError = true;
104
189
  }
105
190
  finally {
106
- void fn.dispose();
191
+ __disposeResources(env_2);
107
192
  }
108
193
  };
109
194
  const getPageOrFrame = async (page, frames) => {
@@ -16,6 +16,7 @@ export const screenshot = definePageTool({
16
16
  },
17
17
  schema: {},
18
18
  blockedByDialog: true,
19
+ verifyFilesSchema: {},
19
20
  handler: async (request, response, context) => {
20
21
  const page = request.page;
21
22
  const screenshot = await page.pptrPage.screenshot({
@@ -37,6 +38,7 @@ export const navigate = definePageTool({
37
38
  url: zod.string().describe('URL to navigate to'),
38
39
  },
39
40
  blockedByDialog: false,
41
+ verifyFilesSchema: {},
40
42
  handler: async (request, response) => {
41
43
  const page = request.page;
42
44
  const options = {
@@ -71,6 +73,7 @@ export const evaluate = definePageTool({
71
73
  script: zod.string().describe(`JS script to run on the page`),
72
74
  },
73
75
  blockedByDialog: true,
76
+ verifyFilesSchema: {},
74
77
  handler: async (request, response) => {
75
78
  const page = request.page;
76
79
  try {
@@ -27,8 +27,10 @@ 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
- handler: async (request, response, context) => {
31
- context.validatePath(request.params.filePath);
30
+ verifyFilesSchema: {
31
+ filePath: true,
32
+ },
33
+ handler: async (request, response) => {
32
34
  response.includeSnapshot({
33
35
  verbose: request.params.verbose ?? false,
34
36
  filePath: request.params.filePath,
@@ -50,9 +52,10 @@ export const waitFor = definePageTool({
50
52
  ...timeoutSchema,
51
53
  },
52
54
  blockedByDialog: true,
53
- handler: async (request, response, context) => {
55
+ verifyFilesSchema: {},
56
+ handler: async (request, response) => {
54
57
  const page = request.page;
55
- await context.waitForTextOnPage(request.params.text, request.params.timeout, page.pptrPage);
58
+ await page.waitForTextOnPage(request.params.text, request.params.timeout);
56
59
  response.appendResponseLine(`Element matching one of ${JSON.stringify(request.params.text)} found.`);
57
60
  response.includeSnapshot();
58
61
  },
@@ -9,19 +9,20 @@ import { definePageTool } from './ToolDefinition.js';
9
9
  export const listThirdPartyDeveloperTools = definePageTool({
10
10
  name: 'list_3p_developer_tools',
11
11
  description: `Lists all third-party developer tools the page exposes for providing runtime information.
12
- Third-party developer tools can be called via the 'execute_3p_developer_tool()' MCP tool.
13
- Alternatively, third-party developer tools can be executed by calling 'evaluate_script' and adding the
14
- following command to the script:
15
- 'window.__dtmcp.executeTool(toolName, params)'
16
- This might be helpful when the third-party developer tools return non-serializable values or when composing
17
- third-party developer tools with additional functionality.`,
12
+ Third-party developer tools can be called via the 'execute_3p_developer_tool()' MCP tool.
13
+ Alternatively, third-party developer tools can be executed by calling 'evaluate_script' and adding the
14
+ following command to the script:
15
+ \`window.__dtmcp.executeTool(toolName, params)\`
16
+ This might be helpful when the third-party developer tools return non-serializable values or when composing
17
+ third-party developer tools with additional functionality.`,
18
18
  annotations: {
19
19
  category: ToolCategory.THIRD_PARTY,
20
20
  readOnlyHint: true,
21
21
  },
22
22
  schema: {},
23
23
  blockedByDialog: false,
24
- handler: async (_request, response, _context) => {
24
+ verifyFilesSchema: {},
25
+ handler: async (_request, response) => {
25
26
  response.setListThirdPartyDeveloperTools();
26
27
  },
27
28
  });
@@ -40,6 +41,7 @@ export const executeThirdPartyDeveloperTool = definePageTool({
40
41
  .describe('The JSON-stringified parameters to pass to the tool'),
41
42
  },
42
43
  blockedByDialog: false,
44
+ verifyFilesSchema: {},
43
45
  handler: async (request, response) => {
44
46
  const toolName = request.params.toolName;
45
47
  let params = {};
@@ -58,8 +60,16 @@ export const executeThirdPartyDeveloperTool = definePageTool({
58
60
  throw new Error(`Failed to parse params as JSON: ${errorMessage}`);
59
61
  }
60
62
  }
61
- const toolGroup = request.page.getThirdPartyDeveloperTools();
62
- const tool = toolGroup?.tools.find(t => t.name === toolName);
63
+ const toolGroups = request.page.getThirdPartyDeveloperTools();
64
+ let tool;
65
+ if (toolGroups) {
66
+ for (const group of toolGroups) {
67
+ tool = group.tools?.find(t => t.name === toolName);
68
+ if (tool) {
69
+ break;
70
+ }
71
+ }
72
+ }
63
73
  if (!tool) {
64
74
  throw new Error(`Tool ${toolName} not found`);
65
75
  }