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
@@ -4,22 +4,22 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import fs from 'node:fs/promises';
7
- import fsPromises from 'node:fs/promises';
8
7
  import os from 'node:os';
9
8
  import path from 'node:path';
10
9
  import { fileURLToPath, pathToFileURL } from 'node:url';
11
- import { overrideDevToolsGlobals, UniverseManager, } from './devtools/DevtoolsUtils.js';
10
+ import { overrideDevToolsGlobals } from './devtools/DevtoolsUtils.js';
12
11
  import { HeapSnapshotManager } from './HeapSnapshotManager.js';
13
12
  import { McpPage } from './McpPage.js';
14
- import { NetworkCollector, ConsoleCollector, } from './PageCollector.js';
15
13
  import { ServiceWorkerConsoleCollector } from './ServiceWorkerCollector.js';
16
- import { Locator, PredefinedNetworkConditions, } from './third_party/index.js';
14
+ import { Locator, } from './third_party/index.js';
17
15
  import { listPages } from './tools/pages.js';
18
16
  import { CLOSE_PAGE_ERROR } from './tools/ToolDefinition.js';
19
17
  import { getTempFilePath, resolveCanonicalPath } from './utils/files.js';
20
- import { getNetworkMultiplierFromString } from './WaitForHelper.js';
21
- const DEFAULT_TIMEOUT = 5_000;
22
- const NAVIGATION_TIMEOUT = 10_000;
18
+ // Page ids are handed out from a process-wide counter so they stay unique
19
+ // across all contexts, in particular across browser reconnects. An id issued
20
+ // before a reconnect then fails to resolve instead of hitting an unrelated
21
+ // page of the reconnected browser.
22
+ let nextPageId = 1;
23
23
  export class McpContext {
24
24
  browser;
25
25
  logger;
@@ -27,17 +27,14 @@ export class McpContext {
27
27
  #isolatedContexts = new Map();
28
28
  // Auto-generated name counter for when no name is provided.
29
29
  #nextIsolatedContextId = 1;
30
- #pages = [];
31
30
  #extensionServiceWorkers = [];
32
31
  #mcpPages = new Map();
33
32
  #selectedPage;
34
- #networkCollector;
35
- #consoleCollector;
36
- #devtoolsUniverseManager;
33
+ #selectedPageFallback;
37
34
  #serviceWorkerConsoleCollector;
38
35
  #isRunningTrace = false;
39
36
  #screenRecorderData = null;
40
- #nextPageId = 1;
37
+ #reconnectNotice = false;
41
38
  #extensionPages = new WeakMap();
42
39
  #extensionServiceWorkerMap = new WeakMap();
43
40
  #nextExtensionServiceWorkerId = 1;
@@ -46,6 +43,7 @@ export class McpContext {
46
43
  #options;
47
44
  #heapSnapshotManager = new HeapSnapshotManager();
48
45
  #roots = undefined;
46
+ #allowUnrestrictedPaths;
49
47
  constructor(browser, logger, options, locatorClass) {
50
48
  overrideDevToolsGlobals({
51
49
  loadResource: (url) => {
@@ -56,36 +54,22 @@ export class McpContext {
56
54
  this.logger = logger;
57
55
  this.#locatorClass = locatorClass;
58
56
  this.#options = options;
59
- this.#networkCollector = new NetworkCollector(this.browser);
60
- this.#consoleCollector = new ConsoleCollector(this.browser, collect => {
61
- return {
62
- console: event => {
63
- collect(event);
64
- },
65
- uncaughtError: event => {
66
- collect(event);
67
- },
68
- devtoolsAggregatedIssue: event => {
69
- collect(event);
70
- },
71
- };
72
- });
57
+ this.#allowUnrestrictedPaths = options.allowUnrestrictedPaths ?? false;
58
+ this.#reconnectNotice = options.reconnected ?? false;
73
59
  this.#serviceWorkerConsoleCollector = new ServiceWorkerConsoleCollector(this.browser);
74
- this.#devtoolsUniverseManager = new UniverseManager(this.browser);
75
60
  }
76
61
  async #init() {
77
- const pages = await this.createPagesSnapshot();
62
+ await this.createPagesSnapshot();
78
63
  const workers = await this.createExtensionServiceWorkersSnapshot();
79
- await this.#networkCollector.init(pages);
80
- await this.#consoleCollector.init(pages);
81
- await this.#devtoolsUniverseManager.init(pages);
82
64
  await this.#serviceWorkerConsoleCollector.init(workers);
65
+ this.browser.on('targetcreated', this.#onTargetCreated);
66
+ this.browser.on('targetdestroyed', this.#onTargetDestroyed);
83
67
  }
84
68
  dispose() {
85
- this.#networkCollector.dispose();
86
- this.#consoleCollector.dispose();
87
- this.#devtoolsUniverseManager.dispose();
69
+ this.browser.off('targetcreated', this.#onTargetCreated);
70
+ this.browser.off('targetdestroyed', this.#onTargetDestroyed);
88
71
  this.#serviceWorkerConsoleCollector.dispose();
72
+ this.#heapSnapshotManager.dispose();
89
73
  for (const mcpPage of this.#mcpPages.values()) {
90
74
  mcpPage.dispose();
91
75
  }
@@ -95,6 +79,40 @@ export class McpContext {
95
79
  // without destroying browser state.
96
80
  this.#isolatedContexts.clear();
97
81
  }
82
+ #onTargetCreated = async (target) => {
83
+ try {
84
+ const page = await target.page();
85
+ if (!page) {
86
+ return;
87
+ }
88
+ void this.#createMcpPage(page);
89
+ }
90
+ catch (err) {
91
+ this.logger?.('Error handling targetcreated', err);
92
+ }
93
+ };
94
+ #onTargetDestroyed = (target) => {
95
+ try {
96
+ let foundPage;
97
+ for (const page of this.#mcpPages.keys()) {
98
+ if (page.target() === target) {
99
+ foundPage = page;
100
+ break;
101
+ }
102
+ }
103
+ if (!foundPage) {
104
+ return;
105
+ }
106
+ const mcpPage = this.#mcpPages.get(foundPage);
107
+ if (mcpPage) {
108
+ mcpPage.dispose();
109
+ this.#mcpPages.delete(foundPage);
110
+ }
111
+ }
112
+ catch (err) {
113
+ this.logger?.('Error handling targetdestroyed', err);
114
+ }
115
+ };
98
116
  static async from(browser, logger, opts,
99
117
  /* Let tests use unbundled Locator class to avoid overly strict checks within puppeteer that fail when mixing bundled and unbundled class instances */
100
118
  locatorClass = Locator) {
@@ -102,12 +120,12 @@ export class McpContext {
102
120
  await context.#init();
103
121
  return context;
104
122
  }
123
+ static resetPageIdsForTesting() {
124
+ nextPageId = 1;
125
+ }
105
126
  roots() {
106
- if (this.#roots === undefined) {
107
- return undefined;
108
- }
109
127
  return [
110
- ...this.#roots,
128
+ ...(this.#roots ?? []),
111
129
  {
112
130
  uri: pathToFileURL(os.tmpdir()).href,
113
131
  name: 'temp',
@@ -121,10 +139,17 @@ export class McpContext {
121
139
  if (filePath === undefined) {
122
140
  return;
123
141
  }
124
- const roots = this.roots();
125
- if (roots === undefined) {
142
+ // If the client never negotiated roots and the operator has explicitly
143
+ // opted into unrestricted access via --allow-unrestricted-paths, restore
144
+ // the previous permissive behavior and skip validation.
145
+ if (this.#roots === undefined && this.#allowUnrestrictedPaths) {
126
146
  return;
127
147
  }
148
+ // roots() always returns at least the temp directory, even if the
149
+ // connecting client never negotiated the optional `roots` capability.
150
+ // Path validation must not be skipped just because no workspace roots
151
+ // were configured.
152
+ const roots = this.roots();
128
153
  let canonicalPath;
129
154
  try {
130
155
  canonicalPath = await resolveCanonicalPath(filePath);
@@ -135,18 +160,24 @@ export class McpContext {
135
160
  throw new Error(`Access denied: Cannot resolve base path for ${filePath}.`);
136
161
  }
137
162
  let allowed = false;
138
- for (const root of roots) {
139
- try {
140
- const rootPathUri = root.uri;
141
- const rootPath = path.resolve(fileURLToPath(rootPathUri));
142
- const canonicalRoot = await fsPromises.realpath(rootPath);
163
+ const resolvedRoots = await Promise.allSettled(roots.map(async (root) => {
164
+ const rootPathUri = root.uri;
165
+ const rootPath = path.resolve(fileURLToPath(rootPathUri));
166
+ return await fs.realpath(rootPath);
167
+ }));
168
+ for (let i = 0; i < roots.length; i++) {
169
+ const root = roots[i];
170
+ const result = resolvedRoots[i];
171
+ if (result.status === 'fulfilled') {
172
+ const canonicalRoot = result.value;
143
173
  if (canonicalPath === canonicalRoot ||
144
174
  canonicalPath.startsWith(canonicalRoot + path.sep)) {
145
175
  allowed = true;
146
176
  break;
147
177
  }
148
178
  }
149
- catch (rootErr) {
179
+ else {
180
+ const rootErr = result.reason;
150
181
  const errMsg = rootErr instanceof Error ? rootErr.message : String(rootErr);
151
182
  console.warn(`[MCP Context] Could not resolve configured root ${root.uri}: ${errMsg}`);
152
183
  // Skip this root if it cannot be resolved.
@@ -163,36 +194,6 @@ export class McpContext {
163
194
  await this.validatePath(outputPath);
164
195
  return outputPath;
165
196
  }
166
- resolveCdpRequestId(page, cdpRequestId) {
167
- if (!cdpRequestId) {
168
- this.logger?.('no network request');
169
- return;
170
- }
171
- const request = this.#networkCollector.find(page.pptrPage, request => {
172
- // @ts-expect-error id is internal.
173
- return request.id === cdpRequestId;
174
- });
175
- if (!request) {
176
- this.logger?.('no network request for ' + cdpRequestId);
177
- return;
178
- }
179
- return this.#networkCollector.getIdForResource(request);
180
- }
181
- getNetworkRequests(page, includePreservedRequests) {
182
- return this.#networkCollector.getData(page.pptrPage, includePreservedRequests);
183
- }
184
- getConsoleData(page, includePreservedMessages) {
185
- return this.#consoleCollector.getData(page.pptrPage, includePreservedMessages);
186
- }
187
- getDevToolsUniverse(page) {
188
- return this.#devtoolsUniverseManager.get(page.pptrPage);
189
- }
190
- getConsoleMessageStableId(message) {
191
- return this.#consoleCollector.getIdForResource(message);
192
- }
193
- getConsoleMessageById(page, id) {
194
- return this.#consoleCollector.getById(page.pptrPage, id);
195
- }
196
197
  async newPage(background, isolatedContextName) {
197
198
  let page;
198
199
  if (isolatedContextName !== undefined) {
@@ -206,14 +207,13 @@ export class McpContext {
206
207
  else {
207
208
  page = await this.browser.newPage({ background });
208
209
  }
210
+ const mcpPage = await this.#createMcpPage(page);
209
211
  await this.createPagesSnapshot();
210
- this.selectPage(this.#getMcpPage(page));
211
- this.#networkCollector.addPage(page);
212
- this.#consoleCollector.addPage(page);
213
- return this.#getMcpPage(page);
212
+ this.selectPage(mcpPage);
213
+ return mcpPage;
214
214
  }
215
215
  async closePage(pageId) {
216
- if (this.#pages.length === 1) {
216
+ if (this.#mcpPages.size === 1) {
217
217
  throw new Error(CLOSE_PAGE_ERROR);
218
218
  }
219
219
  const page = this.getPageById(pageId);
@@ -223,118 +223,9 @@ export class McpContext {
223
223
  }
224
224
  await page.pptrPage.close({ runBeforeUnload: false });
225
225
  }
226
- getNetworkRequestById(page, reqid) {
227
- return this.#networkCollector.getById(page.pptrPage, reqid);
228
- }
229
- async restoreEmulation(page) {
230
- const currentSetting = page.emulationSettings;
231
- await this.emulate(currentSetting, page.pptrPage);
232
- }
233
226
  get #hasNetworkBlockOrAllowlist() {
234
227
  return !!(this.#options.allowList || this.#options.blocklist);
235
228
  }
236
- async emulate(options, targetPage) {
237
- const page = targetPage ?? this.getSelectedPptrPage();
238
- const mcpPage = this.#getMcpPage(page);
239
- const newSettings = { ...mcpPage.emulationSettings };
240
- // Skip network emulation if blocklist/allowlist is configured, as it conflicts with blocking rules in Puppeteer.
241
- if (this.#hasNetworkBlockOrAllowlist) {
242
- if (options.networkConditions !== undefined) {
243
- throw new Error('Network throttling is not supported when network blocking (allowlist/blocklist) is configured.');
244
- }
245
- }
246
- else if (!options.networkConditions) {
247
- await page.emulateNetworkConditions(null);
248
- delete newSettings.networkConditions;
249
- }
250
- else if (options.networkConditions === 'Offline') {
251
- await page.emulateNetworkConditions({
252
- offline: true,
253
- download: 0,
254
- upload: 0,
255
- latency: 0,
256
- });
257
- newSettings.networkConditions = 'Offline';
258
- }
259
- else if (options.networkConditions in PredefinedNetworkConditions) {
260
- const networkCondition = PredefinedNetworkConditions[options.networkConditions];
261
- await page.emulateNetworkConditions(networkCondition);
262
- newSettings.networkConditions = options.networkConditions;
263
- }
264
- const secondarySession = this.getDevToolsUniverse(mcpPage)?.session;
265
- if (!options.cpuThrottlingRate) {
266
- await page.emulateCPUThrottling(1);
267
- if (secondarySession) {
268
- await secondarySession.send('Emulation.setCPUThrottlingRate', {
269
- rate: 1,
270
- });
271
- }
272
- delete newSettings.cpuThrottlingRate;
273
- }
274
- else {
275
- await page.emulateCPUThrottling(options.cpuThrottlingRate);
276
- if (secondarySession) {
277
- await secondarySession.send('Emulation.setCPUThrottlingRate', {
278
- rate: options.cpuThrottlingRate,
279
- });
280
- }
281
- newSettings.cpuThrottlingRate = options.cpuThrottlingRate;
282
- }
283
- if (!options.geolocation) {
284
- await page.setGeolocation({ latitude: 0, longitude: 0 });
285
- delete newSettings.geolocation;
286
- }
287
- else {
288
- await page.setGeolocation(options.geolocation);
289
- newSettings.geolocation = options.geolocation;
290
- }
291
- if (!options.userAgent) {
292
- await page.setUserAgent({ userAgent: undefined });
293
- delete newSettings.userAgent;
294
- }
295
- else {
296
- await page.setUserAgent({ userAgent: options.userAgent });
297
- newSettings.userAgent = options.userAgent;
298
- }
299
- if (!options.colorScheme || options.colorScheme === 'auto') {
300
- await page.emulateMediaFeatures([
301
- { name: 'prefers-color-scheme', value: '' },
302
- ]);
303
- delete newSettings.colorScheme;
304
- }
305
- else {
306
- await page.emulateMediaFeatures([
307
- { name: 'prefers-color-scheme', value: options.colorScheme },
308
- ]);
309
- newSettings.colorScheme = options.colorScheme;
310
- }
311
- if (!options.viewport) {
312
- delete newSettings.viewport;
313
- }
314
- else {
315
- const defaults = {
316
- deviceScaleFactor: 1,
317
- isMobile: false,
318
- hasTouch: false,
319
- isLandscape: false,
320
- };
321
- newSettings.viewport = { ...defaults, ...options.viewport };
322
- }
323
- if (options.extraHttpHeaders !== undefined) {
324
- await page.setExtraHTTPHeaders(options.extraHttpHeaders);
325
- newSettings.extraHttpHeaders = options.extraHttpHeaders;
326
- if (Object.keys(options.extraHttpHeaders).length === 0) {
327
- delete newSettings.extraHttpHeaders;
328
- }
329
- }
330
- mcpPage.emulationSettings = Object.keys(newSettings).length
331
- ? newSettings
332
- : {};
333
- this.#updateSelectedPageTimeouts();
334
- // This should happen after updating the page timeouts.
335
- // Setting the viewport can trigger a reload which we don't want to timeout.
336
- await page.setViewport(newSettings.viewport ?? null);
337
- }
338
229
  setIsRunningPerformanceTrace(x) {
339
230
  this.#isRunningTrace = x;
340
231
  }
@@ -350,7 +241,10 @@ export class McpContext {
350
241
  isCruxEnabled() {
351
242
  return this.#options.performanceCrux;
352
243
  }
353
- getSelectedPptrPage() {
244
+ getPages() {
245
+ return Array.from(this.#mcpPages.values());
246
+ }
247
+ getSelectedMcpPage() {
354
248
  const page = this.#selectedPage;
355
249
  if (!page) {
356
250
  throw new Error('No page selected');
@@ -358,11 +252,37 @@ export class McpContext {
358
252
  if (page.pptrPage.isClosed()) {
359
253
  throw new Error(`The selected page has been closed. Call ${listPages().name} to see open pages.`);
360
254
  }
361
- return page.pptrPage;
255
+ return page;
362
256
  }
363
- getSelectedMcpPage() {
364
- const page = this.getSelectedPptrPage();
365
- return this.#getMcpPage(page);
257
+ async getDevToolsData(page) {
258
+ const targetPage = page ?? this.#selectedPage;
259
+ if (!targetPage) {
260
+ return undefined;
261
+ }
262
+ let timeoutId;
263
+ const timeoutPromise = new Promise(resolve => {
264
+ timeoutId = setTimeout(() => resolve(undefined), 500);
265
+ });
266
+ const dataPromise = targetPage.getDevToolsData();
267
+ try {
268
+ return await Promise.race([dataPromise, timeoutPromise]);
269
+ }
270
+ catch {
271
+ return undefined;
272
+ }
273
+ finally {
274
+ clearTimeout(timeoutId);
275
+ }
276
+ }
277
+ /**
278
+ * Returns true once if this context was created by reconnecting after the
279
+ * previous browser connection was lost, so the next response can surface a
280
+ * note. Cleared on first call.
281
+ */
282
+ consumeReconnectNotice() {
283
+ const notice = this.#reconnectNotice;
284
+ this.#reconnectNotice = false;
285
+ return notice;
366
286
  }
367
287
  getPageById(pageId) {
368
288
  const page = this.#mcpPages.values().find(mcpPage => mcpPage.id === pageId);
@@ -371,55 +291,27 @@ export class McpContext {
371
291
  }
372
292
  return page;
373
293
  }
374
- getPageId(page) {
375
- return this.#mcpPages.get(page)?.id;
376
- }
377
- #getMcpPage(page) {
378
- const mcpPage = this.#mcpPages.get(page);
379
- if (!mcpPage) {
380
- throw new Error('No McpPage found for the given page.');
381
- }
382
- return mcpPage;
383
- }
384
- #getSelectedMcpPage() {
385
- return this.#getMcpPage(this.getSelectedPptrPage());
386
- }
387
294
  isPageSelected(page) {
388
- return this.#selectedPage?.pptrPage === page;
295
+ return this.#selectedPage === page;
389
296
  }
390
297
  selectPage(newPage) {
391
298
  this.#selectedPage = newPage;
392
- this.#updateSelectedPageTimeouts();
393
- }
394
- #updateSelectedPageTimeouts() {
395
- const page = this.#getSelectedMcpPage();
396
- // For waiters 5sec timeout should be sufficient.
397
- // Increased in case we throttle the CPU
398
- const cpuMultiplier = page.cpuThrottlingRate;
399
- page.pptrPage.setDefaultTimeout(DEFAULT_TIMEOUT * cpuMultiplier);
400
- // 10sec should be enough for the load event to be emitted during
401
- // navigations.
402
- // Increased in case we throttle the network requests or the CPU
403
- const networkMultiplier = getNetworkMultiplierFromString(page.networkConditions);
404
- page.pptrPage.setDefaultNavigationTimeout(NAVIGATION_TIMEOUT * networkMultiplier * cpuMultiplier);
405
- }
406
- // Linear scan over per-page snapshots. The page count is small (typically
407
- // 2-10) so a reverse index isn't worthwhile given the uid-reuse lifecycle
408
- // complexity it would introduce.
409
- getAXNodeByUid(uid) {
410
- for (const mcpPage of this.#mcpPages.values()) {
411
- const node = mcpPage.textSnapshot?.idToNode.get(uid);
412
- if (node) {
413
- return node;
414
- }
415
- }
416
- return undefined;
299
+ newPage.updateTimeouts();
300
+ }
301
+ /**
302
+ * Returns details about the last page snapshot automatically replacing the
303
+ * selection because the selected page disappeared from the page list, or
304
+ * `undefined` if the snapshot left the selection intact. Recomputed on every
305
+ * createPagesSnapshot() call.
306
+ */
307
+ getSelectedPageFallback() {
308
+ return this.#selectedPageFallback;
417
309
  }
418
310
  /**
419
311
  * Creates a snapshot of the extension service workers.
420
312
  */
421
313
  async createExtensionServiceWorkersSnapshot() {
422
- const allTargets = await this.browser.targets();
314
+ const allTargets = this.browser.targets();
423
315
  const serviceWorkers = allTargets.filter(target => {
424
316
  return (target.type() === 'service_worker' &&
425
317
  target.url().includes('chrome-extension://'));
@@ -441,74 +333,13 @@ export class McpContext {
441
333
  getServiceWorkerConsoleData(extensionId) {
442
334
  return this.#serviceWorkerConsoleCollector.getData(extensionId);
443
335
  }
444
- async createPagesSnapshot() {
445
- const { pages: allPages, isolatedContextNames } = await this.#getAllPages();
446
- for (const page of allPages) {
447
- let mcpPage = this.#mcpPages.get(page);
448
- if (!mcpPage) {
449
- mcpPage = new McpPage(page, this.#nextPageId++);
450
- this.#mcpPages.set(page, mcpPage);
451
- // We emulate a focused page for all pages to support multi-agent workflows.
452
- void page.emulateFocusedPage(true).catch(error => {
453
- this.logger?.('Error turning on focused page emulation', error);
454
- });
455
- }
456
- mcpPage.isolatedContextName = isolatedContextNames.get(page);
457
- }
458
- // Prune orphaned #mcpPages entries (pages that no longer exist).
459
- const currentPages = new Set(allPages);
460
- for (const [page, mcpPage] of this.#mcpPages) {
461
- if (!currentPages.has(page)) {
462
- mcpPage.dispose();
463
- this.#mcpPages.delete(page);
464
- }
465
- }
466
- this.#pages = allPages.filter(page => {
467
- return (this.#options.experimentalDevToolsDebugging ||
468
- !page.url().startsWith('devtools://'));
469
- });
470
- if ((!this.#selectedPage ||
471
- this.#pages.indexOf(this.#selectedPage.pptrPage) === -1) &&
472
- this.#pages[0]) {
473
- this.selectPage(this.#getMcpPage(this.#pages[0]));
474
- }
475
- await this.detectOpenDevToolsWindows();
476
- return this.#pages;
477
- }
478
- async #getAllPages() {
479
- const defaultCtx = this.browser.defaultBrowserContext();
480
- const allPages = await this.browser.pages(this.#options.experimentalIncludeAllPages);
481
- const allTargets = this.browser.targets();
482
- const extensionTargets = allTargets.filter(target => {
483
- return (target.url().startsWith('chrome-extension://') &&
484
- target.type() === 'page');
485
- });
486
- for (const target of extensionTargets) {
487
- // Right now target.page() returns null for popup and side panel pages.
488
- let page = await target.page();
489
- if (!page) {
490
- // We need to cache pages instances for targets because target.asPage()
491
- // returns a new page instance every time.
492
- page = this.#extensionPages.get(target) ?? null;
493
- if (!page) {
494
- try {
495
- page = await target.asPage();
496
- this.#extensionPages.set(target, page);
497
- }
498
- catch (e) {
499
- this.logger?.('Failed to get page for extension target', e);
500
- }
501
- }
502
- }
503
- if (page && !allPages.includes(page)) {
504
- allPages.push(page);
505
- }
506
- }
336
+ #getBrowserContextToNameMap() {
507
337
  // Build a reverse lookup from BrowserContext instance → name.
508
338
  const contextToName = new Map();
509
339
  for (const [name, ctx] of this.#isolatedContexts) {
510
340
  contextToName.set(ctx, name);
511
341
  }
342
+ const defaultCtx = this.browser.defaultBrowserContext();
512
343
  // Auto-discover BrowserContexts not in our mapping (e.g., externally
513
344
  // created incognito contexts) and assign generated names.
514
345
  const knownContexts = new Set(this.#isolatedContexts.values());
@@ -519,40 +350,76 @@ export class McpContext {
519
350
  contextToName.set(ctx, name);
520
351
  }
521
352
  }
522
- // Map each page to its isolated context name (if any).
523
- const isolatedContextNames = new Map();
524
- for (const page of allPages) {
525
- const ctx = page.browserContext();
526
- const name = contextToName.get(ctx);
527
- if (name) {
528
- isolatedContextNames.set(page, name);
529
- }
353
+ return contextToName;
354
+ }
355
+ async #createMcpPage(page) {
356
+ let mcpPage = this.#mcpPages.get(page);
357
+ if (!mcpPage) {
358
+ mcpPage = new McpPage(page, nextPageId++, {
359
+ locatorClass: this.#locatorClass,
360
+ hasNetworkBlockOrAllowlist: this.#hasNetworkBlockOrAllowlist,
361
+ isolatedContextName: this.#getBrowserContextToNameMap().get(page.browserContext()),
362
+ });
363
+ this.#mcpPages.set(page, mcpPage);
364
+ await mcpPage.init();
530
365
  }
531
- return { pages: allPages, isolatedContextNames };
366
+ return mcpPage;
532
367
  }
533
- async detectOpenDevToolsWindows() {
534
- this.logger?.('Detecting open DevTools windows');
535
- const { pages } = await this.#getAllPages();
536
- await Promise.all(pages.map(async (page) => {
537
- const mcpPage = this.#mcpPages.get(page);
538
- if (!mcpPage) {
539
- return;
368
+ async createPagesSnapshot() {
369
+ const allPages = await this.#fetchBrowserPages();
370
+ await Promise.allSettled(allPages.map(page => this.#createMcpPage(page)));
371
+ // Prune orphaned #mcpPages entries (pages that no longer exist).
372
+ const currentPages = new Set(allPages);
373
+ for (const [page, mcpPage] of this.#mcpPages) {
374
+ if (!currentPages.has(page)) {
375
+ mcpPage.dispose();
376
+ this.#mcpPages.delete(page);
377
+ }
378
+ }
379
+ const pages = Array.from(this.#mcpPages.values());
380
+ // Only fall back when the selected page is actually gone. Gating on
381
+ // `isClosed()` instead of `pages` membership avoids silently swapping a
382
+ // live page that is momentarily missing from the snapshot.
383
+ this.#selectedPageFallback = undefined;
384
+ if ((!this.#selectedPage || this.#selectedPage.pptrPage.isClosed()) &&
385
+ pages[0]) {
386
+ // Record the automatic change so the response can surface it. Skipped on
387
+ // first connect, when there was no prior selection to replace.
388
+ if (this.#selectedPage) {
389
+ this.#selectedPageFallback = {
390
+ wasClosed: this.#selectedPage.pptrPage.isClosed(),
391
+ };
540
392
  }
541
- // Prior to Chrome 144.0.7559.59, the command fails,
542
- // Some Electron apps still use older version
543
- // Fall back to not exposing DevTools at all.
393
+ this.selectPage(pages[0]);
394
+ }
395
+ return pages.map(p => p.pptrPage);
396
+ }
397
+ async #fetchBrowserPages() {
398
+ const allPages = (await this.browser.pages(this.#options.experimentalIncludeAllPages)).filter(page => {
399
+ return (this.#options.experimentalDevToolsDebugging ||
400
+ !page.url().startsWith('devtools://'));
401
+ });
402
+ const allTargets = this.browser.targets();
403
+ const extensionTargets = allTargets.filter(target => {
404
+ return (target.url().startsWith('chrome-extension://') &&
405
+ target.type() === 'page');
406
+ });
407
+ await Promise.allSettled(extensionTargets.map(async (target) => {
544
408
  try {
545
- if (await page.hasDevTools()) {
546
- mcpPage.devToolsPage = await page.openDevTools();
409
+ let page = await target.page();
410
+ if (!page) {
411
+ page = await target.asPage();
547
412
  }
548
- else {
549
- mcpPage.devToolsPage = undefined;
413
+ this.#extensionPages.set(target, page);
414
+ if (page && !allPages.includes(page)) {
415
+ allPages.push(page);
550
416
  }
551
417
  }
552
- catch {
553
- mcpPage.devToolsPage = undefined;
418
+ catch (e) {
419
+ this.logger?.('Failed to get page for extension target', e);
554
420
  }
555
421
  }));
422
+ return allPages;
556
423
  }
557
424
  getExtensionServiceWorkers() {
558
425
  return this.#extensionServiceWorkers;
@@ -560,34 +427,37 @@ export class McpContext {
560
427
  getExtensionServiceWorkerId(extensionServiceWorker) {
561
428
  return this.#extensionServiceWorkerMap.get(extensionServiceWorker.target);
562
429
  }
563
- getPages() {
564
- return this.#pages;
565
- }
566
- getIsolatedContextName(page) {
567
- return this.#mcpPages.get(page)?.isolatedContextName;
568
- }
569
- async saveTemporaryFile(data, filename) {
570
- const filepath = await getTempFilePath(filename);
430
+ async #writeFile(filepath, data) {
571
431
  await this.validatePath(filepath);
572
432
  try {
573
- await fs.writeFile(filepath, data);
433
+ await fs.mkdir(path.dirname(filepath), { recursive: true });
434
+ // Open the file with flags to:
435
+ // - O_WRONLY: Write-only
436
+ // - O_CREAT: Create if it doesn't exist
437
+ // - O_TRUNC: Truncate to zero length if it exists
438
+ // - O_NOFOLLOW: DO NOT follow symlinks.
439
+ // - 0o600: Permissions: read/write for owner, no permissions for others.
440
+ await fs.writeFile(filepath, data, {
441
+ flag: fs.constants.O_WRONLY |
442
+ fs.constants.O_CREAT |
443
+ fs.constants.O_TRUNC |
444
+ fs.constants.O_NOFOLLOW,
445
+ mode: 0o600,
446
+ });
574
447
  }
575
448
  catch (err) {
576
- throw new Error('Could not save a file', { cause: err });
449
+ throw new Error(`Could not write ${filepath}`, { cause: err });
577
450
  }
451
+ }
452
+ async saveTemporaryFile(data, filename) {
453
+ const filepath = await getTempFilePath(filename);
454
+ await this.#writeFile(filepath, data);
578
455
  return { filepath };
579
456
  }
580
457
  async saveFile(data, clientProvidedFilePath, extension) {
581
458
  const filePath = await this.ensureExtension(clientProvidedFilePath, extension);
582
- try {
583
- await fs.mkdir(path.dirname(filePath), { recursive: true });
584
- await fs.writeFile(filePath, data);
585
- return { filename: filePath };
586
- }
587
- catch (err) {
588
- this.logger?.(err);
589
- throw new Error('Could not save a file', { cause: err });
590
- }
459
+ await this.#writeFile(filePath, data);
460
+ return { filename: filePath };
591
461
  }
592
462
  storeTraceRecording(result) {
593
463
  // Clear the trace results because we only consume the latest trace currently.
@@ -597,44 +467,18 @@ export class McpContext {
597
467
  recordedTraces() {
598
468
  return this.#traceResults;
599
469
  }
600
- getNetworkRequestStableId(request) {
601
- return this.#networkCollector.getIdForResource(request);
602
- }
603
- waitForTextOnPage(text, timeout, targetPage) {
604
- const page = targetPage ?? this.getSelectedPptrPage();
605
- const frames = page.frames();
606
- let locator = this.#locatorClass.race(frames.flatMap(frame => text.flatMap(value => [
607
- frame.locator(`aria/${value}`),
608
- frame.locator(`text/${value}`),
609
- ])));
610
- if (timeout) {
611
- locator = locator.setTimeout(timeout);
612
- }
613
- return locator.wait();
614
- }
615
- /**
616
- * We need to ignore favicon request as they make our test flaky
617
- */
618
- async setUpNetworkCollectorForTesting() {
619
- this.#networkCollector = new NetworkCollector(this.browser, collect => {
620
- return {
621
- request: req => {
622
- if (req.url().includes('favicon.ico')) {
623
- return;
624
- }
625
- collect(req);
626
- },
627
- };
628
- });
629
- const { pages } = await this.#getAllPages();
630
- await this.#networkCollector.init(pages);
631
- }
632
470
  async installExtension(extensionPath) {
633
- const id = await this.browser.installExtension(extensionPath);
471
+ const id = await Promise.race([
472
+ this.browser.installExtension(extensionPath),
473
+ new Promise((_, rej) => setTimeout(() => rej(new Error('Timeout installing extension')), 30000)),
474
+ ]);
634
475
  return id;
635
476
  }
636
477
  async uninstallExtension(id) {
637
- await this.browser.uninstallExtension(id);
478
+ await Promise.race([
479
+ this.browser.uninstallExtension(id),
480
+ new Promise((_, rej) => setTimeout(() => rej(new Error('Timeout uninstalling extension')), 30000)),
481
+ ]);
638
482
  }
639
483
  async triggerExtensionAction(id) {
640
484
  const extensions = await this.browser.extensions();
@@ -642,7 +486,7 @@ export class McpContext {
642
486
  if (!extension) {
643
487
  throw new Error(`Extension with ID ${id} not found.`);
644
488
  }
645
- const page = this.getSelectedPptrPage();
489
+ const page = this.getSelectedMcpPage().pptrPage;
646
490
  await extension.triggerAction(page);
647
491
  }
648
492
  listExtensions() {
@@ -652,8 +496,8 @@ export class McpContext {
652
496
  const pptrExtensions = await this.browser.extensions();
653
497
  return pptrExtensions.get(id);
654
498
  }
655
- async getHeapSnapshotAggregates(filePath) {
656
- return await this.#heapSnapshotManager.getAggregates(filePath);
499
+ async getHeapSnapshotAggregates(filePath, filterName, objectId) {
500
+ return await this.#heapSnapshotManager.getAggregates(filePath, filterName, objectId);
657
501
  }
658
502
  async getHeapSnapshotDuplicateStrings(filePath) {
659
503
  return await this.#heapSnapshotManager.getDuplicateStrings(filePath);
@@ -664,14 +508,20 @@ export class McpContext {
664
508
  async getHeapSnapshotStaticData(filePath) {
665
509
  return await this.#heapSnapshotManager.getStaticData(filePath);
666
510
  }
667
- async getHeapSnapshotNodesById(filePath, id) {
668
- return await this.#heapSnapshotManager.getNodesById(filePath, id);
511
+ async getHeapSnapshotNativeContextSizes(filePath) {
512
+ return await this.#heapSnapshotManager.getNativeContextSizes(filePath);
513
+ }
514
+ async getHeapSnapshotNodesById(filePath, id, filterName, objectId) {
515
+ return await this.#heapSnapshotManager.getNodesById(filePath, id, filterName, objectId);
669
516
  }
670
517
  async getHeapSnapshotRetainers(filePath, nodeId) {
671
518
  return await this.#heapSnapshotManager.getRetainers(filePath, nodeId);
672
519
  }
520
+ async getHeapSnapshotObjectDetails(filePath, nodeId) {
521
+ return await this.#heapSnapshotManager.getObjectInfo(filePath, nodeId);
522
+ }
673
523
  async closeHeapSnapshot(filePath) {
674
- return this.#heapSnapshotManager.dispose(filePath);
524
+ return this.#heapSnapshotManager.disposeSnapshot(filePath);
675
525
  }
676
526
  hasHeapSnapshots() {
677
527
  return this.#heapSnapshotManager.hasSnapshots();
@@ -720,7 +570,7 @@ export class McpContext {
720
570
  }
721
571
  case 'file:': {
722
572
  await this.validatePath(fileURLToPath(url));
723
- return await fsPromises.readFile(url, 'utf-8');
573
+ return await fs.readFile(url, 'utf-8');
724
574
  }
725
575
  default:
726
576
  throw new Error(`Unsupported protocol for: ${url}`);