chrome-devtools-mcp 0.17.2 → 0.17.3
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.
- package/build/src/DevToolsConnectionAdapter.js +69 -0
- package/build/src/DevtoolsUtils.js +340 -0
- package/build/src/McpContext.js +603 -0
- package/build/src/McpResponse.js +482 -0
- package/build/src/Mutex.js +37 -0
- package/build/src/PageCollector.js +309 -0
- package/build/src/WaitForHelper.js +139 -0
- package/build/src/browser.js +182 -0
- package/build/src/cli.js +295 -0
- package/build/src/formatters/ConsoleFormatter.js +240 -0
- package/build/src/formatters/IssueFormatter.js +190 -0
- package/build/src/formatters/NetworkFormatter.js +218 -0
- package/build/src/formatters/SnapshotFormatter.js +134 -0
- package/build/src/index.js +21 -0
- package/build/src/issue-descriptions.js +39 -0
- package/build/src/logger.js +36 -0
- package/build/src/main.js +196 -0
- package/build/src/polyfill.js +7 -0
- package/build/src/telemetry/ClearcutLogger.js +102 -0
- package/build/src/telemetry/WatchdogClient.js +60 -0
- package/build/src/telemetry/flagUtils.js +45 -0
- package/build/src/telemetry/metricUtils.js +14 -0
- package/build/src/telemetry/persistence.js +53 -0
- package/build/src/telemetry/types.js +33 -0
- package/build/src/telemetry/watchdog/ClearcutSender.js +201 -0
- package/build/src/telemetry/watchdog/main.js +127 -0
- package/build/src/third_party/THIRD_PARTY_NOTICES +2011 -0
- package/build/src/third_party/bundled-packages.json +8 -0
- package/build/src/third_party/devtools-formatter-worker.js +15449 -0
- package/build/src/third_party/index.js +172791 -0
- package/build/src/third_party/issue-descriptions/CoepCoopSandboxedIframeCannotNavigateToCoopPage.md +4 -0
- package/build/src/third_party/issue-descriptions/CoepCorpNotSameOrigin.md +8 -0
- package/build/src/third_party/issue-descriptions/CoepCorpNotSameOriginAfterDefaultedToSameOriginByCoep.md +18 -0
- package/build/src/third_party/issue-descriptions/CoepCorpNotSameSite.md +7 -0
- package/build/src/third_party/issue-descriptions/CoepFrameResourceNeedsCoepHeader.md +10 -0
- package/build/src/third_party/issue-descriptions/CompatibilityModeQuirks.md +5 -0
- package/build/src/third_party/issue-descriptions/CookieAttributeValueExceedsMaxSize.md +5 -0
- package/build/src/third_party/issue-descriptions/LowTextContrast.md +5 -0
- package/build/src/third_party/issue-descriptions/SameSiteExcludeContextDowngradeRead.md +8 -0
- package/build/src/third_party/issue-descriptions/SameSiteExcludeContextDowngradeSet.md +8 -0
- package/build/src/third_party/issue-descriptions/SameSiteExcludeNavigationContextDowngrade.md +8 -0
- package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureErrorRead.md +8 -0
- package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureErrorSet.md +8 -0
- package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureWarnRead.md +8 -0
- package/build/src/third_party/issue-descriptions/SameSiteNoneInsecureWarnSet.md +8 -0
- package/build/src/third_party/issue-descriptions/SameSiteUnspecifiedLaxAllowUnsafeRead.md +9 -0
- package/build/src/third_party/issue-descriptions/SameSiteUnspecifiedLaxAllowUnsafeSet.md +9 -0
- package/build/src/third_party/issue-descriptions/SameSiteWarnCrossDowngradeRead.md +8 -0
- package/build/src/third_party/issue-descriptions/SameSiteWarnCrossDowngradeSet.md +8 -0
- package/build/src/third_party/issue-descriptions/SameSiteWarnStrictLaxDowngradeStrict.md +8 -0
- package/build/src/third_party/issue-descriptions/arInsecureContext.md +7 -0
- package/build/src/third_party/issue-descriptions/arInvalidInfoHeader.md +5 -0
- package/build/src/third_party/issue-descriptions/arInvalidRegisterOsSourceHeader.md +5 -0
- package/build/src/third_party/issue-descriptions/arInvalidRegisterOsTriggerHeader.md +5 -0
- package/build/src/third_party/issue-descriptions/arInvalidRegisterSourceHeader.md +5 -0
- package/build/src/third_party/issue-descriptions/arInvalidRegisterTriggerHeader.md +5 -0
- package/build/src/third_party/issue-descriptions/arNavigationRegistrationUniqueScopeAlreadySet.md +5 -0
- package/build/src/third_party/issue-descriptions/arNavigationRegistrationWithoutTransientUserActivation.md +6 -0
- package/build/src/third_party/issue-descriptions/arNoRegisterOsSourceHeader.md +5 -0
- package/build/src/third_party/issue-descriptions/arNoRegisterOsTriggerHeader.md +5 -0
- package/build/src/third_party/issue-descriptions/arNoRegisterSourceHeader.md +5 -0
- package/build/src/third_party/issue-descriptions/arNoRegisterTriggerHeader.md +5 -0
- package/build/src/third_party/issue-descriptions/arNoWebOrOsSupport.md +4 -0
- package/build/src/third_party/issue-descriptions/arOsSourceIgnored.md +18 -0
- package/build/src/third_party/issue-descriptions/arOsTriggerIgnored.md +19 -0
- package/build/src/third_party/issue-descriptions/arPermissionPolicyDisabled.md +8 -0
- package/build/src/third_party/issue-descriptions/arSourceAndTriggerHeaders.md +9 -0
- package/build/src/third_party/issue-descriptions/arSourceIgnored.md +13 -0
- package/build/src/third_party/issue-descriptions/arTriggerIgnored.md +12 -0
- package/build/src/third_party/issue-descriptions/arUntrustworthyReportingOrigin.md +10 -0
- package/build/src/third_party/issue-descriptions/arWebAndOsHeaders.md +11 -0
- package/build/src/third_party/issue-descriptions/bounceTrackingMitigations.md +3 -0
- package/build/src/third_party/issue-descriptions/clientHintMetaTagAllowListInvalidOrigin.md +4 -0
- package/build/src/third_party/issue-descriptions/clientHintMetaTagModifiedHTML.md +4 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowlistItemType.md +12 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidHeader.md +12 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidUrlPattern.md +8 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistItemNotInnerList.md +12 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistMoreThanOneList.md +7 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistReportingEndpointNotToken.md +10 -0
- package/build/src/third_party/issue-descriptions/cookieCrossSiteRedirectDowngrade.md +12 -0
- package/build/src/third_party/issue-descriptions/cookieExcludeBlockedWithinRelatedWebsiteSet.md +4 -0
- package/build/src/third_party/issue-descriptions/cookieExcludeDomainNonAscii.md +11 -0
- package/build/src/third_party/issue-descriptions/cookieExcludePortMismatch.md +8 -0
- package/build/src/third_party/issue-descriptions/cookieExcludeSchemeMismatch.md +7 -0
- package/build/src/third_party/issue-descriptions/cookieExcludeThirdPartyPhaseoutRead.md +6 -0
- package/build/src/third_party/issue-descriptions/cookieExcludeThirdPartyPhaseoutSet.md +6 -0
- package/build/src/third_party/issue-descriptions/cookieWarnDomainNonAscii.md +11 -0
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantRead.md +4 -0
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSet.md +4 -0
- package/build/src/third_party/issue-descriptions/cookieWarnThirdPartyPhaseoutRead.md +6 -0
- package/build/src/third_party/issue-descriptions/cookieWarnThirdPartyPhaseoutSet.md +6 -0
- package/build/src/third_party/issue-descriptions/corsAllowCredentialsRequired.md +6 -0
- package/build/src/third_party/issue-descriptions/corsDisabledScheme.md +7 -0
- package/build/src/third_party/issue-descriptions/corsDisallowedByMode.md +7 -0
- package/build/src/third_party/issue-descriptions/corsHeaderDisallowedByPreflightResponse.md +5 -0
- package/build/src/third_party/issue-descriptions/corsInsecurePrivateNetwork.md +10 -0
- package/build/src/third_party/issue-descriptions/corsInvalidHeaderValues.md +7 -0
- package/build/src/third_party/issue-descriptions/corsLocalNetworkAccessPermissionDenied.md +19 -0
- package/build/src/third_party/issue-descriptions/corsMethodDisallowedByPreflightResponse.md +5 -0
- package/build/src/third_party/issue-descriptions/corsNoCorsRedirectModeNotFollow.md +5 -0
- package/build/src/third_party/issue-descriptions/corsOriginMismatch.md +6 -0
- package/build/src/third_party/issue-descriptions/corsPreflightAllowPrivateNetworkError.md +10 -0
- package/build/src/third_party/issue-descriptions/corsPreflightResponseInvalid.md +5 -0
- package/build/src/third_party/issue-descriptions/corsPrivateNetworkPermissionDenied.md +10 -0
- package/build/src/third_party/issue-descriptions/corsRedirectContainsCredentials.md +5 -0
- package/build/src/third_party/issue-descriptions/corsWildcardOriginNotAllowed.md +8 -0
- package/build/src/third_party/issue-descriptions/cspEvalViolation.md +9 -0
- package/build/src/third_party/issue-descriptions/cspInlineViolation.md +10 -0
- package/build/src/third_party/issue-descriptions/cspTrustedTypesPolicyViolation.md +5 -0
- package/build/src/third_party/issue-descriptions/cspTrustedTypesSinkViolation.md +8 -0
- package/build/src/third_party/issue-descriptions/cspURLViolation.md +10 -0
- package/build/src/third_party/issue-descriptions/deprecation.md +3 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsHttpNotFound.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsInvalidResponse.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsNoResponse.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestApprovalDeclined.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestCanceled.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestErrorFetchingSignin.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestErrorIdToken.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenHttpNotFound.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenInvalidRequest.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenInvalidResponse.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenNoResponse.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestInvalidSigninResponse.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestHttpNotFound.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestInvalidResponse.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestManifestNoResponse.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestTooManyRequests.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestInvalidAccountsResponse.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestInvalidConfigOrWellKnown.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoAccountSharingPermission.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoApiPermission.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNoReturningUserFromFetchedAccounts.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotIframe.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotPotentiallyTrustworthy.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotSameOrigin.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthUserInfoRequestNotSignedInWithIdp.md +1 -0
- package/build/src/third_party/issue-descriptions/fetchingPartitionedBlobURL.md +7 -0
- package/build/src/third_party/issue-descriptions/genericFormAriaLabelledByToNonExistingIdError.md +8 -0
- package/build/src/third_party/issue-descriptions/genericFormAutocompleteAttributeEmptyError.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormDuplicateIdForInputError.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormEmptyIdAndNameAttributesForInputError.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormInputAssignedAutocompleteValueToIdOrNameAttributeError.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormInputHasWrongButWellIntendedAutocompleteValueError.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormInputWithNoLabelError.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormLabelForMatchesNonExistingIdError.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormLabelForNameError.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormLabelHasNeitherForNorNestedInputError.md +5 -0
- package/build/src/third_party/issue-descriptions/genericNavigationEntryMarkedSkippable.md +7 -0
- package/build/src/third_party/issue-descriptions/genericResponseWasBlockedByORB.md +4 -0
- package/build/src/third_party/issue-descriptions/heavyAd.md +10 -0
- package/build/src/third_party/issue-descriptions/mixedContent.md +5 -0
- package/build/src/third_party/issue-descriptions/navigatingPartitionedBlobURL.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementActivationDisabled.md +7 -0
- package/build/src/third_party/issue-descriptions/permissionElementActivationDisabledWithOccluder.md +9 -0
- package/build/src/third_party/issue-descriptions/permissionElementActivationDisabledWithOccluderParent.md +9 -0
- package/build/src/third_party/issue-descriptions/permissionElementCspFrameAncestorsMissing.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementFencedFrameDisallowed.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementFontSizeTooLarge.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementFontSizeTooSmall.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementGeolocationDeprecated.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementInsetBoxShadowUnsupported.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementInvalidDisplayStyle.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementInvalidSizeValue.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementInvalidType.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementInvalidTypeActivation.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementLowContrast.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementNonOpaqueColor.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementPaddingBottomUnsupported.md +6 -0
- package/build/src/third_party/issue-descriptions/permissionElementPaddingRightUnsupported.md +6 -0
- package/build/src/third_party/issue-descriptions/permissionElementPermissionsPolicyBlocked.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementRegistrationFailed.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementRequestInProgress.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementSecurityChecksFailed.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementTypeNotSupported.md +5 -0
- package/build/src/third_party/issue-descriptions/permissionElementUntrustedEvent.md +7 -0
- package/build/src/third_party/issue-descriptions/placeholderDescriptionForInvisibleIssues.md +3 -0
- package/build/src/third_party/issue-descriptions/propertyRuleInvalidNameIssue.md +3 -0
- package/build/src/third_party/issue-descriptions/propertyRuleIssue.md +7 -0
- package/build/src/third_party/issue-descriptions/selectElementAccessibilityDisallowedOptGroupChild.md +7 -0
- package/build/src/third_party/issue-descriptions/selectElementAccessibilityDisallowedSelectChild.md +7 -0
- package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentAttributesSelectDescendant.md +3 -0
- package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentLegendChild.md +3 -0
- package/build/src/third_party/issue-descriptions/selectElementAccessibilityInteractiveContentOptionChild.md +3 -0
- package/build/src/third_party/issue-descriptions/selectElementAccessibilityNonPhrasingContentOptionChild.md +3 -0
- package/build/src/third_party/issue-descriptions/sharedArrayBuffer.md +7 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorCrossOriginNoCorsRequest.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorDictionaryLoadFailure.md +3 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorMatchingDictionaryNotUsed.md +3 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryUseErrorUnexpectedContentDictionaryHeader.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorCossOriginNoCorsRequest.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorDisallowedBySettings.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorExpiredResponse.md +3 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorFeatureDisabled.md +3 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorInsufficientResources.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorInvalidMatchField.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorInvalidStructuredHeader.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorInvalidTTLField.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNavigationRequest.md +3 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNoMatchField.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonIntegerTTLField.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonListMatchDestField.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonSecureContext.md +3 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonStringIdField.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonStringInMatchDestList.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonStringMatchField.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorNonTokenTypeField.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorRequestAborted.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorShuttingDown.md +1 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorTooLongIdField.md +3 -0
- package/build/src/third_party/issue-descriptions/sharedDictionaryWriteErrorUnsupportedType.md +3 -0
- package/build/src/third_party/issue-descriptions/sriInvalidSignatureHeader.md +14 -0
- package/build/src/third_party/issue-descriptions/sriInvalidSignatureInputHeader.md +15 -0
- package/build/src/third_party/issue-descriptions/sriMissingSignatureHeader.md +8 -0
- package/build/src/third_party/issue-descriptions/sriMissingSignatureInputHeader.md +7 -0
- package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsIncorrectLength.md +11 -0
- package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsNotByteSequence.md +14 -0
- package/build/src/third_party/issue-descriptions/sriSignatureHeaderValueIsParameterized.md +15 -0
- package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidComponentName.md +8 -0
- package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidComponentType.md +13 -0
- package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidDerivedComponentParameter.md +4 -0
- package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidHeaderComponentParameter.md +5 -0
- package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderInvalidParameter.md +11 -0
- package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderKeyIdLength.md +12 -0
- package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderMissingLabel.md +6 -0
- package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderMissingRequiredParameters.md +8 -0
- package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderValueMissingComponents.md +11 -0
- package/build/src/third_party/issue-descriptions/sriSignatureInputHeaderValueNotInnerList.md +11 -0
- package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +10 -0
- package/build/src/third_party/issue-descriptions/sriValidationFailedInvalidLength.md +5 -0
- package/build/src/third_party/issue-descriptions/sriValidationFailedSignatureExpired.md +6 -0
- package/build/src/third_party/issue-descriptions/sriValidationFailedSignatureMismatch.md +11 -0
- package/build/src/third_party/issue-descriptions/stylesheetLateImport.md +4 -0
- package/build/src/third_party/issue-descriptions/stylesheetRequestFailed.md +3 -0
- package/build/src/third_party/issue-descriptions/summaryElementAccessibilityInteractiveContentSummaryDescendant.md +3 -0
- package/build/src/third_party/issue-descriptions/unencodedDigestIncorrectDigestLength.md +12 -0
- package/build/src/third_party/issue-descriptions/unencodedDigestIncorrectDigestType.md +17 -0
- package/build/src/third_party/issue-descriptions/unencodedDigestMalformedDictionary.md +14 -0
- package/build/src/third_party/issue-descriptions/unencodedDigestUnknownAlgorithm.md +15 -0
- package/build/src/tools/ToolDefinition.js +20 -0
- package/build/src/tools/categories.js +24 -0
- package/build/src/tools/console.js +85 -0
- package/build/src/tools/emulation.js +169 -0
- package/build/src/tools/extensions.js +79 -0
- package/build/src/tools/input.js +348 -0
- package/build/src/tools/network.js +120 -0
- package/build/src/tools/pages.js +323 -0
- package/build/src/tools/performance.js +188 -0
- package/build/src/tools/screenshot.js +84 -0
- package/build/src/tools/script.js +71 -0
- package/build/src/tools/snapshot.js +52 -0
- package/build/src/tools/tools.js +31 -0
- package/build/src/trace-processing/parse.js +84 -0
- package/build/src/utils/ExtensionRegistry.js +35 -0
- package/build/src/utils/keyboard.js +296 -0
- package/build/src/utils/pagination.js +49 -0
- package/build/src/utils/string.js +36 -0
- package/build/src/utils/types.js +6 -0
- package/package.json +2 -2
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { ConsoleFormatter } from './formatters/ConsoleFormatter.js';
|
|
7
|
+
import { IssueFormatter } from './formatters/IssueFormatter.js';
|
|
8
|
+
import { NetworkFormatter } from './formatters/NetworkFormatter.js';
|
|
9
|
+
import { SnapshotFormatter } from './formatters/SnapshotFormatter.js';
|
|
10
|
+
import { UncaughtError } from './PageCollector.js';
|
|
11
|
+
import { DevTools } from './third_party/index.js';
|
|
12
|
+
import { handleDialog } from './tools/pages.js';
|
|
13
|
+
import { getInsightOutput, getTraceSummary } from './trace-processing/parse.js';
|
|
14
|
+
import { paginate } from './utils/pagination.js';
|
|
15
|
+
export class McpResponse {
|
|
16
|
+
#includePages = false;
|
|
17
|
+
#snapshotParams;
|
|
18
|
+
#attachedNetworkRequestId;
|
|
19
|
+
#attachedNetworkRequestOptions;
|
|
20
|
+
#attachedConsoleMessageId;
|
|
21
|
+
#attachedTraceSummary;
|
|
22
|
+
#attachedTraceInsight;
|
|
23
|
+
#textResponseLines = [];
|
|
24
|
+
#images = [];
|
|
25
|
+
#networkRequestsOptions;
|
|
26
|
+
#consoleDataOptions;
|
|
27
|
+
#listExtensions;
|
|
28
|
+
#devToolsData;
|
|
29
|
+
#tabId;
|
|
30
|
+
attachDevToolsData(data) {
|
|
31
|
+
this.#devToolsData = data;
|
|
32
|
+
}
|
|
33
|
+
setTabId(tabId) {
|
|
34
|
+
this.#tabId = tabId;
|
|
35
|
+
}
|
|
36
|
+
setIncludePages(value) {
|
|
37
|
+
this.#includePages = value;
|
|
38
|
+
}
|
|
39
|
+
includeSnapshot(params) {
|
|
40
|
+
this.#snapshotParams = params ?? {
|
|
41
|
+
verbose: false,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
setListExtensions() {
|
|
45
|
+
this.#listExtensions = true;
|
|
46
|
+
}
|
|
47
|
+
setIncludeNetworkRequests(value, options) {
|
|
48
|
+
if (!value) {
|
|
49
|
+
this.#networkRequestsOptions = undefined;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.#networkRequestsOptions = {
|
|
53
|
+
include: value,
|
|
54
|
+
pagination: options?.pageSize || options?.pageIdx
|
|
55
|
+
? {
|
|
56
|
+
pageSize: options.pageSize,
|
|
57
|
+
pageIdx: options.pageIdx,
|
|
58
|
+
}
|
|
59
|
+
: undefined,
|
|
60
|
+
resourceTypes: options?.resourceTypes,
|
|
61
|
+
includePreservedRequests: options?.includePreservedRequests,
|
|
62
|
+
networkRequestIdInDevToolsUI: options?.networkRequestIdInDevToolsUI,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
setIncludeConsoleData(value, options) {
|
|
66
|
+
if (!value) {
|
|
67
|
+
this.#consoleDataOptions = undefined;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.#consoleDataOptions = {
|
|
71
|
+
include: value,
|
|
72
|
+
pagination: options?.pageSize || options?.pageIdx
|
|
73
|
+
? {
|
|
74
|
+
pageSize: options.pageSize,
|
|
75
|
+
pageIdx: options.pageIdx,
|
|
76
|
+
}
|
|
77
|
+
: undefined,
|
|
78
|
+
types: options?.types,
|
|
79
|
+
includePreservedMessages: options?.includePreservedMessages,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
attachNetworkRequest(reqid, options) {
|
|
83
|
+
this.#attachedNetworkRequestId = reqid;
|
|
84
|
+
this.#attachedNetworkRequestOptions = options;
|
|
85
|
+
}
|
|
86
|
+
attachConsoleMessage(msgid) {
|
|
87
|
+
this.#attachedConsoleMessageId = msgid;
|
|
88
|
+
}
|
|
89
|
+
attachTraceSummary(result) {
|
|
90
|
+
this.#attachedTraceSummary = result;
|
|
91
|
+
}
|
|
92
|
+
attachTraceInsight(trace, insightSetId, insightName) {
|
|
93
|
+
this.#attachedTraceInsight = {
|
|
94
|
+
trace,
|
|
95
|
+
insightSetId,
|
|
96
|
+
insightName,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
get includePages() {
|
|
100
|
+
return this.#includePages;
|
|
101
|
+
}
|
|
102
|
+
get attachedTraceSummary() {
|
|
103
|
+
return this.#attachedTraceSummary;
|
|
104
|
+
}
|
|
105
|
+
get attachedTracedInsight() {
|
|
106
|
+
return this.#attachedTraceInsight;
|
|
107
|
+
}
|
|
108
|
+
get includeNetworkRequests() {
|
|
109
|
+
return this.#networkRequestsOptions?.include ?? false;
|
|
110
|
+
}
|
|
111
|
+
get includeConsoleData() {
|
|
112
|
+
return this.#consoleDataOptions?.include ?? false;
|
|
113
|
+
}
|
|
114
|
+
get attachedNetworkRequestId() {
|
|
115
|
+
return this.#attachedNetworkRequestId;
|
|
116
|
+
}
|
|
117
|
+
get networkRequestsPageIdx() {
|
|
118
|
+
return this.#networkRequestsOptions?.pagination?.pageIdx;
|
|
119
|
+
}
|
|
120
|
+
get consoleMessagesPageIdx() {
|
|
121
|
+
return this.#consoleDataOptions?.pagination?.pageIdx;
|
|
122
|
+
}
|
|
123
|
+
get consoleMessagesTypes() {
|
|
124
|
+
return this.#consoleDataOptions?.types;
|
|
125
|
+
}
|
|
126
|
+
appendResponseLine(value) {
|
|
127
|
+
this.#textResponseLines.push(value);
|
|
128
|
+
}
|
|
129
|
+
attachImage(value) {
|
|
130
|
+
this.#images.push(value);
|
|
131
|
+
}
|
|
132
|
+
get responseLines() {
|
|
133
|
+
return this.#textResponseLines;
|
|
134
|
+
}
|
|
135
|
+
get images() {
|
|
136
|
+
return this.#images;
|
|
137
|
+
}
|
|
138
|
+
get snapshotParams() {
|
|
139
|
+
return this.#snapshotParams;
|
|
140
|
+
}
|
|
141
|
+
async handle(toolName, context) {
|
|
142
|
+
if (this.#includePages) {
|
|
143
|
+
await context.createPagesSnapshot();
|
|
144
|
+
}
|
|
145
|
+
let snapshot;
|
|
146
|
+
if (this.#snapshotParams) {
|
|
147
|
+
await context.createTextSnapshot(this.#snapshotParams.verbose, this.#devToolsData);
|
|
148
|
+
const textSnapshot = context.getTextSnapshot();
|
|
149
|
+
if (textSnapshot) {
|
|
150
|
+
const formatter = new SnapshotFormatter(textSnapshot);
|
|
151
|
+
if (this.#snapshotParams.filePath) {
|
|
152
|
+
await context.saveFile(new TextEncoder().encode(formatter.toString()), this.#snapshotParams.filePath);
|
|
153
|
+
snapshot = this.#snapshotParams.filePath;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
snapshot = formatter;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
let detailedNetworkRequest;
|
|
161
|
+
if (this.#attachedNetworkRequestId) {
|
|
162
|
+
const request = context.getNetworkRequestById(this.#attachedNetworkRequestId);
|
|
163
|
+
const formatter = await NetworkFormatter.from(request, {
|
|
164
|
+
requestId: this.#attachedNetworkRequestId,
|
|
165
|
+
requestIdResolver: req => context.getNetworkRequestStableId(req),
|
|
166
|
+
fetchData: true,
|
|
167
|
+
requestFilePath: this.#attachedNetworkRequestOptions?.requestFilePath,
|
|
168
|
+
responseFilePath: this.#attachedNetworkRequestOptions?.responseFilePath,
|
|
169
|
+
saveFile: (data, filename) => context.saveFile(data, filename),
|
|
170
|
+
});
|
|
171
|
+
detailedNetworkRequest = formatter;
|
|
172
|
+
}
|
|
173
|
+
let detailedConsoleMessage;
|
|
174
|
+
if (this.#attachedConsoleMessageId) {
|
|
175
|
+
const message = context.getConsoleMessageById(this.#attachedConsoleMessageId);
|
|
176
|
+
const consoleMessageStableId = this.#attachedConsoleMessageId;
|
|
177
|
+
if ('args' in message || message instanceof UncaughtError) {
|
|
178
|
+
const consoleMessage = message;
|
|
179
|
+
const devTools = context.getDevToolsUniverse();
|
|
180
|
+
detailedConsoleMessage = await ConsoleFormatter.from(consoleMessage, {
|
|
181
|
+
id: consoleMessageStableId,
|
|
182
|
+
fetchDetailedData: true,
|
|
183
|
+
devTools: devTools ?? undefined,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else if (message instanceof DevTools.AggregatedIssue) {
|
|
187
|
+
const formatter = new IssueFormatter(message, {
|
|
188
|
+
id: consoleMessageStableId,
|
|
189
|
+
requestIdResolver: context.resolveCdpRequestId.bind(context),
|
|
190
|
+
elementIdResolver: context.resolveCdpElementId.bind(context),
|
|
191
|
+
});
|
|
192
|
+
if (!formatter.isValid()) {
|
|
193
|
+
throw new Error("Can't provide detals for the msgid " + consoleMessageStableId);
|
|
194
|
+
}
|
|
195
|
+
detailedConsoleMessage = formatter;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
let extensions;
|
|
199
|
+
if (this.#listExtensions) {
|
|
200
|
+
extensions = context.listExtensions();
|
|
201
|
+
}
|
|
202
|
+
let consoleMessages;
|
|
203
|
+
if (this.#consoleDataOptions?.include) {
|
|
204
|
+
let messages = context.getConsoleData(this.#consoleDataOptions.includePreservedMessages);
|
|
205
|
+
if (this.#consoleDataOptions.types?.length) {
|
|
206
|
+
const normalizedTypes = new Set(this.#consoleDataOptions.types);
|
|
207
|
+
messages = messages.filter(message => {
|
|
208
|
+
if ('type' in message) {
|
|
209
|
+
return normalizedTypes.has(message.type());
|
|
210
|
+
}
|
|
211
|
+
if (message instanceof DevTools.AggregatedIssue) {
|
|
212
|
+
return normalizedTypes.has('issue');
|
|
213
|
+
}
|
|
214
|
+
return normalizedTypes.has('error');
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
consoleMessages = (await Promise.all(messages.map(async (item) => {
|
|
218
|
+
const consoleMessageStableId = context.getConsoleMessageStableId(item);
|
|
219
|
+
if ('args' in item || item instanceof UncaughtError) {
|
|
220
|
+
const consoleMessage = item;
|
|
221
|
+
const devTools = context.getDevToolsUniverse();
|
|
222
|
+
return await ConsoleFormatter.from(consoleMessage, {
|
|
223
|
+
id: consoleMessageStableId,
|
|
224
|
+
fetchDetailedData: false,
|
|
225
|
+
devTools: devTools ?? undefined,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
if (item instanceof DevTools.AggregatedIssue) {
|
|
229
|
+
const formatter = new IssueFormatter(item, {
|
|
230
|
+
id: consoleMessageStableId,
|
|
231
|
+
});
|
|
232
|
+
if (!formatter.isValid()) {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
return formatter;
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}))).filter(item => item !== null);
|
|
239
|
+
}
|
|
240
|
+
let networkRequests;
|
|
241
|
+
if (this.#networkRequestsOptions?.include) {
|
|
242
|
+
let requests = context.getNetworkRequests(this.#networkRequestsOptions?.includePreservedRequests);
|
|
243
|
+
// Apply resource type filtering if specified
|
|
244
|
+
if (this.#networkRequestsOptions.resourceTypes?.length) {
|
|
245
|
+
const normalizedTypes = new Set(this.#networkRequestsOptions.resourceTypes);
|
|
246
|
+
requests = requests.filter(request => {
|
|
247
|
+
const type = request.resourceType();
|
|
248
|
+
return normalizedTypes.has(type);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
if (requests.length) {
|
|
252
|
+
networkRequests = await Promise.all(requests.map(request => NetworkFormatter.from(request, {
|
|
253
|
+
requestId: context.getNetworkRequestStableId(request),
|
|
254
|
+
selectedInDevToolsUI: context.getNetworkRequestStableId(request) ===
|
|
255
|
+
this.#networkRequestsOptions?.networkRequestIdInDevToolsUI,
|
|
256
|
+
fetchData: false,
|
|
257
|
+
saveFile: (data, filename) => context.saveFile(data, filename),
|
|
258
|
+
})));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return this.format(toolName, context, {
|
|
262
|
+
detailedConsoleMessage,
|
|
263
|
+
consoleMessages,
|
|
264
|
+
snapshot,
|
|
265
|
+
detailedNetworkRequest,
|
|
266
|
+
networkRequests,
|
|
267
|
+
traceInsight: this.#attachedTraceInsight,
|
|
268
|
+
traceSummary: this.#attachedTraceSummary,
|
|
269
|
+
extensions,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
format(toolName, context, data) {
|
|
273
|
+
const structuredContent = {};
|
|
274
|
+
const response = [`# ${toolName} response`];
|
|
275
|
+
if (this.#textResponseLines.length) {
|
|
276
|
+
structuredContent.message = this.#textResponseLines.join('\n');
|
|
277
|
+
response.push(...this.#textResponseLines);
|
|
278
|
+
}
|
|
279
|
+
const networkConditions = context.getNetworkConditions();
|
|
280
|
+
if (networkConditions) {
|
|
281
|
+
response.push(`## Network emulation`);
|
|
282
|
+
response.push(`Emulating: ${networkConditions}`);
|
|
283
|
+
response.push(`Default navigation timeout set to ${context.getNavigationTimeout()} ms`);
|
|
284
|
+
structuredContent.networkConditions = networkConditions;
|
|
285
|
+
structuredContent.navigationTimeout = context.getNavigationTimeout();
|
|
286
|
+
}
|
|
287
|
+
const viewport = context.getViewport();
|
|
288
|
+
if (viewport) {
|
|
289
|
+
response.push(`## Viewport emulation`);
|
|
290
|
+
response.push(`Emulating viewport: ${JSON.stringify(viewport)}`);
|
|
291
|
+
structuredContent.viewport = viewport;
|
|
292
|
+
}
|
|
293
|
+
const userAgent = context.getUserAgent();
|
|
294
|
+
if (userAgent) {
|
|
295
|
+
response.push(`## UserAgent emulation`);
|
|
296
|
+
response.push(`Emulating userAgent: ${userAgent}`);
|
|
297
|
+
structuredContent.userAgent = userAgent;
|
|
298
|
+
}
|
|
299
|
+
const cpuThrottlingRate = context.getCpuThrottlingRate();
|
|
300
|
+
if (cpuThrottlingRate > 1) {
|
|
301
|
+
response.push(`## CPU emulation`);
|
|
302
|
+
response.push(`Emulating: ${cpuThrottlingRate}x slowdown`);
|
|
303
|
+
structuredContent.cpuThrottlingRate = cpuThrottlingRate;
|
|
304
|
+
}
|
|
305
|
+
const colorScheme = context.getColorScheme();
|
|
306
|
+
if (colorScheme) {
|
|
307
|
+
response.push(`## Color Scheme emulation`);
|
|
308
|
+
response.push(`Emulating: ${colorScheme}`);
|
|
309
|
+
structuredContent.colorScheme = colorScheme;
|
|
310
|
+
}
|
|
311
|
+
const dialog = context.getDialog();
|
|
312
|
+
if (dialog) {
|
|
313
|
+
const defaultValueIfNeeded = dialog.type() === 'prompt'
|
|
314
|
+
? ` (default value: "${dialog.defaultValue()}")`
|
|
315
|
+
: '';
|
|
316
|
+
response.push(`# Open dialog
|
|
317
|
+
${dialog.type()}: ${dialog.message()}${defaultValueIfNeeded}.
|
|
318
|
+
Call ${handleDialog.name} to handle it before continuing.`);
|
|
319
|
+
structuredContent.dialog = {
|
|
320
|
+
type: dialog.type(),
|
|
321
|
+
message: dialog.message(),
|
|
322
|
+
defaultValue: dialog.defaultValue(),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
if (this.#includePages) {
|
|
326
|
+
const parts = [`## Pages`];
|
|
327
|
+
for (const page of context.getPages()) {
|
|
328
|
+
parts.push(`${context.getPageId(page)}: ${page.url()}${context.isPageSelected(page) ? ' [selected]' : ''}`);
|
|
329
|
+
}
|
|
330
|
+
response.push(...parts);
|
|
331
|
+
structuredContent.pages = context.getPages().map(page => {
|
|
332
|
+
return {
|
|
333
|
+
id: context.getPageId(page),
|
|
334
|
+
url: page.url(),
|
|
335
|
+
selected: context.isPageSelected(page),
|
|
336
|
+
};
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
if (this.#tabId) {
|
|
340
|
+
structuredContent.tabId = this.#tabId;
|
|
341
|
+
}
|
|
342
|
+
if (data.traceSummary) {
|
|
343
|
+
const summary = getTraceSummary(data.traceSummary);
|
|
344
|
+
response.push(summary);
|
|
345
|
+
structuredContent.traceSummary = summary;
|
|
346
|
+
structuredContent.traceInsights = [];
|
|
347
|
+
for (const insightSet of data.traceSummary.insights?.values() ?? []) {
|
|
348
|
+
for (const [insightName, model] of Object.entries(insightSet.model)) {
|
|
349
|
+
structuredContent.traceInsights.push({
|
|
350
|
+
insightName,
|
|
351
|
+
insightKey: model.insightKey,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (data.traceInsight) {
|
|
357
|
+
const insightOutput = getInsightOutput(data.traceInsight.trace, data.traceInsight.insightSetId, data.traceInsight.insightName);
|
|
358
|
+
if ('error' in insightOutput) {
|
|
359
|
+
response.push(insightOutput.error);
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
response.push(insightOutput.output);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (data.snapshot) {
|
|
366
|
+
if (typeof data.snapshot === 'string') {
|
|
367
|
+
response.push(`Saved snapshot to ${data.snapshot}.`);
|
|
368
|
+
structuredContent.snapshotFilePath = data.snapshot;
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
response.push('## Latest page snapshot');
|
|
372
|
+
response.push(data.snapshot.toString());
|
|
373
|
+
structuredContent.snapshot = data.snapshot.toJSON();
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (data.detailedNetworkRequest) {
|
|
377
|
+
response.push(data.detailedNetworkRequest.toStringDetailed());
|
|
378
|
+
structuredContent.networkRequest =
|
|
379
|
+
data.detailedNetworkRequest.toJSONDetailed();
|
|
380
|
+
}
|
|
381
|
+
if (data.detailedConsoleMessage) {
|
|
382
|
+
response.push(data.detailedConsoleMessage.toStringDetailed());
|
|
383
|
+
structuredContent.consoleMessage =
|
|
384
|
+
data.detailedConsoleMessage.toJSONDetailed();
|
|
385
|
+
}
|
|
386
|
+
if (data.extensions) {
|
|
387
|
+
structuredContent.extensions = data.extensions;
|
|
388
|
+
response.push('## Extensions');
|
|
389
|
+
if (data.extensions.length === 0) {
|
|
390
|
+
response.push('No extensions installed.');
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
const extensionsMessage = data.extensions
|
|
394
|
+
.map(extension => {
|
|
395
|
+
return `id=${extension.id} "${extension.name}" v${extension.version} ${extension.isEnabled ? 'Enabled' : 'Disabled'}`;
|
|
396
|
+
})
|
|
397
|
+
.join('\n');
|
|
398
|
+
response.push(extensionsMessage);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (this.#networkRequestsOptions?.include && data.networkRequests) {
|
|
402
|
+
const requests = data.networkRequests;
|
|
403
|
+
response.push('## Network requests');
|
|
404
|
+
if (requests.length) {
|
|
405
|
+
const paginationData = this.#dataWithPagination(requests, this.#networkRequestsOptions.pagination);
|
|
406
|
+
structuredContent.pagination = paginationData.pagination;
|
|
407
|
+
response.push(...paginationData.info);
|
|
408
|
+
if (data.networkRequests) {
|
|
409
|
+
structuredContent.networkRequests = [];
|
|
410
|
+
for (const formatter of paginationData.items) {
|
|
411
|
+
response.push(formatter.toString());
|
|
412
|
+
structuredContent.networkRequests.push(formatter.toJSON());
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
response.push('No requests found.');
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (this.#consoleDataOptions?.include) {
|
|
421
|
+
const messages = data.consoleMessages ?? [];
|
|
422
|
+
response.push('## Console messages');
|
|
423
|
+
if (messages.length) {
|
|
424
|
+
const paginationData = this.#dataWithPagination(messages, this.#consoleDataOptions.pagination);
|
|
425
|
+
structuredContent.pagination = paginationData.pagination;
|
|
426
|
+
response.push(...paginationData.info);
|
|
427
|
+
response.push(...paginationData.items.map(message => message.toString()));
|
|
428
|
+
structuredContent.consoleMessages = paginationData.items.map(message => message.toJSON());
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
response.push('<no console messages found>');
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const text = {
|
|
435
|
+
type: 'text',
|
|
436
|
+
text: response.join('\n'),
|
|
437
|
+
};
|
|
438
|
+
const images = this.#images.map(imageData => {
|
|
439
|
+
return {
|
|
440
|
+
type: 'image',
|
|
441
|
+
...imageData,
|
|
442
|
+
};
|
|
443
|
+
});
|
|
444
|
+
return {
|
|
445
|
+
content: [text, ...images],
|
|
446
|
+
structuredContent,
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
#dataWithPagination(data, pagination) {
|
|
450
|
+
const response = [];
|
|
451
|
+
const paginationResult = paginate(data, pagination);
|
|
452
|
+
if (paginationResult.invalidPage) {
|
|
453
|
+
response.push('Invalid page number provided. Showing first page.');
|
|
454
|
+
}
|
|
455
|
+
const { startIndex, endIndex, currentPage, totalPages } = paginationResult;
|
|
456
|
+
response.push(`Showing ${startIndex + 1}-${endIndex} of ${data.length} (Page ${currentPage + 1} of ${totalPages}).`);
|
|
457
|
+
if (pagination) {
|
|
458
|
+
if (paginationResult.hasNextPage) {
|
|
459
|
+
response.push(`Next page: ${currentPage + 1}`);
|
|
460
|
+
}
|
|
461
|
+
if (paginationResult.hasPreviousPage) {
|
|
462
|
+
response.push(`Previous page: ${currentPage - 1}`);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
info: response,
|
|
467
|
+
items: paginationResult.items,
|
|
468
|
+
pagination: {
|
|
469
|
+
currentPage: paginationResult.currentPage,
|
|
470
|
+
totalPages: paginationResult.totalPages,
|
|
471
|
+
hasNextPage: paginationResult.hasNextPage,
|
|
472
|
+
hasPreviousPage: paginationResult.hasPreviousPage,
|
|
473
|
+
startIndex: paginationResult.startIndex,
|
|
474
|
+
endIndex: paginationResult.endIndex,
|
|
475
|
+
invalidPage: paginationResult.invalidPage,
|
|
476
|
+
},
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
resetResponseLineForTesting() {
|
|
480
|
+
this.#textResponseLines = [];
|
|
481
|
+
}
|
|
482
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google Inc.
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export class Mutex {
|
|
7
|
+
static Guard = class Guard {
|
|
8
|
+
#mutex;
|
|
9
|
+
constructor(mutex) {
|
|
10
|
+
this.#mutex = mutex;
|
|
11
|
+
}
|
|
12
|
+
dispose() {
|
|
13
|
+
return this.#mutex.release();
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
#locked = false;
|
|
17
|
+
#acquirers = [];
|
|
18
|
+
// This is FIFO.
|
|
19
|
+
async acquire() {
|
|
20
|
+
if (!this.#locked) {
|
|
21
|
+
this.#locked = true;
|
|
22
|
+
return new Mutex.Guard(this);
|
|
23
|
+
}
|
|
24
|
+
const { resolve, promise } = Promise.withResolvers();
|
|
25
|
+
this.#acquirers.push(resolve);
|
|
26
|
+
await promise;
|
|
27
|
+
return new Mutex.Guard(this);
|
|
28
|
+
}
|
|
29
|
+
release() {
|
|
30
|
+
const resolve = this.#acquirers.shift();
|
|
31
|
+
if (!resolve) {
|
|
32
|
+
this.#locked = false;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
resolve();
|
|
36
|
+
}
|
|
37
|
+
}
|