devtools-tracing 1.0.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.
- package/generate.ts +643 -0
- package/index.ts +16 -0
- package/lib/front_end/core/common/App.ts +7 -0
- package/lib/front_end/core/common/AppProvider.ts +32 -0
- package/lib/front_end/core/common/Base64.ts +47 -0
- package/lib/front_end/core/common/CharacterIdMap.ts +30 -0
- package/lib/front_end/core/common/Color.ts +2506 -0
- package/lib/front_end/core/common/ColorConverter.ts +402 -0
- package/lib/front_end/core/common/ColorUtils.ts +252 -0
- package/lib/front_end/core/common/Console.ts +114 -0
- package/lib/front_end/core/common/Debouncer.ts +15 -0
- package/lib/front_end/core/common/EventTarget.ts +52 -0
- package/lib/front_end/core/common/Gzip.ts +74 -0
- package/lib/front_end/core/common/JavaScriptMetaData.ts +29 -0
- package/lib/front_end/core/common/Lazy.ts +31 -0
- package/lib/front_end/core/common/Linkifier.ts +55 -0
- package/lib/front_end/core/common/MapWithDefault.ts +26 -0
- package/lib/front_end/core/common/Mutex.ts +55 -0
- package/lib/front_end/core/common/Object.ts +145 -0
- package/lib/front_end/core/common/ParsedURL.ts +554 -0
- package/lib/front_end/core/common/Progress.ts +180 -0
- package/lib/front_end/core/common/QueryParamHandler.ts +7 -0
- package/lib/front_end/core/common/ResolverBase.ts +85 -0
- package/lib/front_end/core/common/ResourceType.ts +588 -0
- package/lib/front_end/core/common/ReturnToPanel.ts +17 -0
- package/lib/front_end/core/common/Revealer.ts +192 -0
- package/lib/front_end/core/common/Runnable.ts +41 -0
- package/lib/front_end/core/common/SegmentedRange.ts +87 -0
- package/lib/front_end/core/common/SettingRegistration.ts +339 -0
- package/lib/front_end/core/common/Settings.ts +1497 -0
- package/lib/front_end/core/common/SimpleHistoryManager.ts +124 -0
- package/lib/front_end/core/common/StringOutputStream.ts +26 -0
- package/lib/front_end/core/common/TextDictionary.ts +48 -0
- package/lib/front_end/core/common/Throttler.ts +99 -0
- package/lib/front_end/core/common/Trie.ts +152 -0
- package/lib/front_end/core/common/Worker.ts +60 -0
- package/lib/front_end/core/common/common.ts +81 -0
- package/lib/front_end/core/host/AidaClient.ts +733 -0
- package/lib/front_end/core/host/GdpClient.ts +316 -0
- package/lib/front_end/core/host/InspectorFrontendHost.ts +648 -0
- package/lib/front_end/core/host/InspectorFrontendHostAPI.ts +551 -0
- package/lib/front_end/core/host/Platform.ts +76 -0
- package/lib/front_end/core/host/ResourceLoader.ts +282 -0
- package/lib/front_end/core/host/UserMetrics.ts +1230 -0
- package/lib/front_end/core/host/host.ts +23 -0
- package/lib/front_end/core/i18n/ByteUtilities.ts +82 -0
- package/lib/front_end/core/i18n/DevToolsLocale.ts +87 -0
- package/lib/front_end/core/i18n/NumberFormatter.ts +82 -0
- package/lib/front_end/core/i18n/i18n.ts +17 -0
- package/lib/front_end/core/i18n/i18nImpl.ts +204 -0
- package/lib/front_end/core/i18n/i18nTypes.ts +10 -0
- package/lib/front_end/core/i18n/locales.js +14 -0
- package/lib/front_end/core/i18n/time-utilities.ts +174 -0
- package/lib/front_end/core/platform/ArrayUtilities.ts +271 -0
- package/lib/front_end/core/platform/Brand.ts +23 -0
- package/lib/front_end/core/platform/Constructor.ts +10 -0
- package/lib/front_end/core/platform/DOMUtilities.ts +138 -0
- package/lib/front_end/core/platform/DateUtilities.ts +15 -0
- package/lib/front_end/core/platform/DevToolsPath.ts +53 -0
- package/lib/front_end/core/platform/KeyboardUtilities.ts +38 -0
- package/lib/front_end/core/platform/MapUtilities.ts +95 -0
- package/lib/front_end/core/platform/MimeType.ts +175 -0
- package/lib/front_end/core/platform/NumberUtilities.ts +80 -0
- package/lib/front_end/core/platform/StringUtilities.ts +588 -0
- package/lib/front_end/core/platform/Timing.ts +17 -0
- package/lib/front_end/core/platform/TypedArrayUtilities.ts +189 -0
- package/lib/front_end/core/platform/TypescriptUtilities.ts +86 -0
- package/lib/front_end/core/platform/UIString.ts +39 -0
- package/lib/front_end/core/platform/UserVisibleError.ts +28 -0
- package/lib/front_end/core/platform/platform.ts +45 -0
- package/lib/front_end/core/protocol_client/ConnectionTransport.ts +26 -0
- package/lib/front_end/core/protocol_client/InspectorBackend.ts +1050 -0
- package/lib/front_end/core/protocol_client/NodeURL.ts +42 -0
- package/lib/front_end/core/protocol_client/protocol_client.ts +13 -0
- package/lib/front_end/core/root/Runtime.ts +609 -0
- package/lib/front_end/core/root/root.ts +6 -0
- package/lib/front_end/core/sdk/AccessibilityModel.ts +353 -0
- package/lib/front_end/core/sdk/AnimationModel.ts +1041 -0
- package/lib/front_end/core/sdk/AutofillModel.ts +184 -0
- package/lib/front_end/core/sdk/CPUProfilerModel.ts +148 -0
- package/lib/front_end/core/sdk/CPUThrottlingManager.ts +282 -0
- package/lib/front_end/core/sdk/CSSContainerQuery.ts +139 -0
- package/lib/front_end/core/sdk/CSSFontFace.ts +40 -0
- package/lib/front_end/core/sdk/CSSLayer.ts +30 -0
- package/lib/front_end/core/sdk/CSSMatchedStyles.ts +1646 -0
- package/lib/front_end/core/sdk/CSSMedia.ts +121 -0
- package/lib/front_end/core/sdk/CSSMetadata.ts +1647 -0
- package/lib/front_end/core/sdk/CSSModel.ts +1128 -0
- package/lib/front_end/core/sdk/CSSProperty.ts +384 -0
- package/lib/front_end/core/sdk/CSSPropertyParser.ts +681 -0
- package/lib/front_end/core/sdk/CSSPropertyParserMatchers.ts +1395 -0
- package/lib/front_end/core/sdk/CSSQuery.ts +72 -0
- package/lib/front_end/core/sdk/CSSRule.ts +465 -0
- package/lib/front_end/core/sdk/CSSScope.ts +30 -0
- package/lib/front_end/core/sdk/CSSStartingStyle.ts +29 -0
- package/lib/front_end/core/sdk/CSSStyleDeclaration.ts +313 -0
- package/lib/front_end/core/sdk/CSSStyleSheetHeader.ts +196 -0
- package/lib/front_end/core/sdk/CSSSupports.ts +33 -0
- package/lib/front_end/core/sdk/CategorizedBreakpoint.ts +64 -0
- package/lib/front_end/core/sdk/ChildTargetManager.ts +314 -0
- package/lib/front_end/core/sdk/CompilerSourceMappingContentProvider.ts +62 -0
- package/lib/front_end/core/sdk/Connections.ts +293 -0
- package/lib/front_end/core/sdk/ConsoleModel.ts +808 -0
- package/lib/front_end/core/sdk/ConsoleModelTypes.ts +15 -0
- package/lib/front_end/core/sdk/Cookie.ts +319 -0
- package/lib/front_end/core/sdk/CookieModel.ts +239 -0
- package/lib/front_end/core/sdk/CookieParser.ts +185 -0
- package/lib/front_end/core/sdk/DOMDebuggerModel.ts +787 -0
- package/lib/front_end/core/sdk/DOMModel.ts +1961 -0
- package/lib/front_end/core/sdk/DebuggerModel.ts +1605 -0
- package/lib/front_end/core/sdk/EmulationModel.ts +648 -0
- package/lib/front_end/core/sdk/EnhancedTracesParser.ts +515 -0
- package/lib/front_end/core/sdk/EventBreakpointsModel.ts +183 -0
- package/lib/front_end/core/sdk/FrameAssociated.ts +11 -0
- package/lib/front_end/core/sdk/FrameManager.ts +259 -0
- package/lib/front_end/core/sdk/HeapProfilerModel.ts +225 -0
- package/lib/front_end/core/sdk/HttpReasonPhraseStrings.ts +77 -0
- package/lib/front_end/core/sdk/IOModel.ts +91 -0
- package/lib/front_end/core/sdk/IsolateManager.ts +257 -0
- package/lib/front_end/core/sdk/IssuesModel.ts +70 -0
- package/lib/front_end/core/sdk/LayerTreeBase.ts +169 -0
- package/lib/front_end/core/sdk/LogModel.ts +56 -0
- package/lib/front_end/core/sdk/NetworkManager.ts +2823 -0
- package/lib/front_end/core/sdk/NetworkRequest.ts +2253 -0
- package/lib/front_end/core/sdk/OverlayColorGenerator.ts +52 -0
- package/lib/front_end/core/sdk/OverlayModel.ts +1011 -0
- package/lib/front_end/core/sdk/OverlayPersistentHighlighter.ts +522 -0
- package/lib/front_end/core/sdk/PageLoad.ts +35 -0
- package/lib/front_end/core/sdk/PageResourceLoader.ts +435 -0
- package/lib/front_end/core/sdk/PaintProfiler.ts +110 -0
- package/lib/front_end/core/sdk/PerformanceMetricsModel.ts +84 -0
- package/lib/front_end/core/sdk/PreloadingModel.ts +863 -0
- package/lib/front_end/core/sdk/RehydratingConnection.ts +386 -0
- package/lib/front_end/core/sdk/RehydratingObject.ts +66 -0
- package/lib/front_end/core/sdk/RemoteObject.ts +1160 -0
- package/lib/front_end/core/sdk/Resource.ts +232 -0
- package/lib/front_end/core/sdk/ResourceTreeModel.ts +1160 -0
- package/lib/front_end/core/sdk/RuntimeModel.ts +732 -0
- package/lib/front_end/core/sdk/SDKModel.ts +65 -0
- package/lib/front_end/core/sdk/ScopeTreeCache.ts +45 -0
- package/lib/front_end/core/sdk/ScreenCaptureModel.ts +255 -0
- package/lib/front_end/core/sdk/Script.ts +534 -0
- package/lib/front_end/core/sdk/SecurityOriginManager.ts +76 -0
- package/lib/front_end/core/sdk/ServerSentEvents.ts +80 -0
- package/lib/front_end/core/sdk/ServerSentEventsProtocol.ts +122 -0
- package/lib/front_end/core/sdk/ServerTiming.ts +260 -0
- package/lib/front_end/core/sdk/ServiceWorkerCacheModel.ts +377 -0
- package/lib/front_end/core/sdk/ServiceWorkerManager.ts +605 -0
- package/lib/front_end/core/sdk/SourceMap.ts +867 -0
- package/lib/front_end/core/sdk/SourceMapCache.ts +54 -0
- package/lib/front_end/core/sdk/SourceMapFunctionRanges.ts +156 -0
- package/lib/front_end/core/sdk/SourceMapManager.ts +239 -0
- package/lib/front_end/core/sdk/SourceMapScopeChainEntry.ts +189 -0
- package/lib/front_end/core/sdk/SourceMapScopesInfo.ts +508 -0
- package/lib/front_end/core/sdk/StorageBucketsModel.ts +204 -0
- package/lib/front_end/core/sdk/StorageKeyManager.ts +98 -0
- package/lib/front_end/core/sdk/Target.ts +332 -0
- package/lib/front_end/core/sdk/TargetManager.ts +453 -0
- package/lib/front_end/core/sdk/TraceObject.ts +61 -0
- package/lib/front_end/core/sdk/WebAuthnModel.ts +104 -0
- package/lib/front_end/core/sdk/sdk.ts +174 -0
- package/lib/front_end/entrypoints/formatter_worker/FormatterActions.ts +59 -0
- package/lib/front_end/generated/InspectorBackendCommands.js +1617 -0
- package/lib/front_end/generated/SupportedCSSProperties.js +7512 -0
- package/lib/front_end/generated/protocol-proxy-api.d.ts +5022 -0
- package/lib/front_end/generated/protocol.ts +22014 -0
- package/lib/front_end/models/cpu_profile/CPUProfileDataModel.ts +571 -0
- package/lib/front_end/models/cpu_profile/ProfileTreeModel.ts +103 -0
- package/lib/front_end/models/cpu_profile/cpu_profile.ts +11 -0
- package/lib/front_end/models/formatter/FormatterWorkerPool.ts +219 -0
- package/lib/front_end/models/formatter/ScriptFormatter.ts +112 -0
- package/lib/front_end/models/formatter/formatter.ts +8 -0
- package/lib/front_end/models/text_utils/CodeMirrorUtils.ts +37 -0
- package/lib/front_end/models/text_utils/ContentData.ts +199 -0
- package/lib/front_end/models/text_utils/ContentProvider.ts +68 -0
- package/lib/front_end/models/text_utils/StaticContentProvider.ts +49 -0
- package/lib/front_end/models/text_utils/StreamingContentData.ts +108 -0
- package/lib/front_end/models/text_utils/Text.ts +90 -0
- package/lib/front_end/models/text_utils/TextCursor.ts +44 -0
- package/lib/front_end/models/text_utils/TextRange.ts +266 -0
- package/lib/front_end/models/text_utils/TextUtils.ts +401 -0
- package/lib/front_end/models/text_utils/WasmDisassembly.ts +87 -0
- package/lib/front_end/models/text_utils/text_utils.ts +27 -0
- package/lib/front_end/models/trace/EntityMapper.ts +141 -0
- package/lib/front_end/models/trace/EventsSerializer.ts +101 -0
- package/lib/front_end/models/trace/LanternComputationData.ts +438 -0
- package/lib/front_end/models/trace/ModelImpl.ts +236 -0
- package/lib/front_end/models/trace/Name.ts +136 -0
- package/lib/front_end/models/trace/Processor.ts +652 -0
- package/lib/front_end/models/trace/Styles.ts +1138 -0
- package/lib/front_end/models/trace/extras/FilmStrip.ts +78 -0
- package/lib/front_end/models/trace/extras/MainThreadActivity.ts +86 -0
- package/lib/front_end/models/trace/extras/ScriptDuplication.ts +236 -0
- package/lib/front_end/models/trace/extras/StackTraceForEvent.ts +203 -0
- package/lib/front_end/models/trace/extras/ThirdParties.ts +164 -0
- package/lib/front_end/models/trace/extras/TraceFilter.ts +62 -0
- package/lib/front_end/models/trace/extras/TraceTree.ts +701 -0
- package/lib/front_end/models/trace/extras/extras.ts +11 -0
- package/lib/front_end/models/trace/handlers/AnimationFramesHandler.ts +128 -0
- package/lib/front_end/models/trace/handlers/AnimationHandler.ts +36 -0
- package/lib/front_end/models/trace/handlers/AsyncJSCallsHandler.ts +239 -0
- package/lib/front_end/models/trace/handlers/AuctionWorkletsHandler.ts +183 -0
- package/lib/front_end/models/trace/handlers/DOMStatsHandler.ts +31 -0
- package/lib/front_end/models/trace/handlers/ExtensionTraceDataHandler.ts +306 -0
- package/lib/front_end/models/trace/handlers/FlowsHandler.ts +175 -0
- package/lib/front_end/models/trace/handlers/FramesHandler.ts +571 -0
- package/lib/front_end/models/trace/handlers/GPUHandler.ts +50 -0
- package/lib/front_end/models/trace/handlers/ImagePaintingHandler.ts +183 -0
- package/lib/front_end/models/trace/handlers/InitiatorsHandler.ts +193 -0
- package/lib/front_end/models/trace/handlers/InvalidationsHandler.ts +168 -0
- package/lib/front_end/models/trace/handlers/LargestImagePaintHandler.ts +109 -0
- package/lib/front_end/models/trace/handlers/LargestTextPaintHandler.ts +35 -0
- package/lib/front_end/models/trace/handlers/LayerTreeHandler.ts +123 -0
- package/lib/front_end/models/trace/handlers/LayoutShiftsHandler.ts +573 -0
- package/lib/front_end/models/trace/handlers/MemoryHandler.ts +31 -0
- package/lib/front_end/models/trace/handlers/MetaHandler.ts +525 -0
- package/lib/front_end/models/trace/handlers/ModelHandlers.ts +34 -0
- package/lib/front_end/models/trace/handlers/NetworkRequestsHandler.ts +672 -0
- package/lib/front_end/models/trace/handlers/PageFramesHandler.ts +52 -0
- package/lib/front_end/models/trace/handlers/PageLoadMetricsHandler.ts +460 -0
- package/lib/front_end/models/trace/handlers/RendererHandler.ts +428 -0
- package/lib/front_end/models/trace/handlers/SamplesHandler.ts +271 -0
- package/lib/front_end/models/trace/handlers/ScreenshotsHandler.ts +122 -0
- package/lib/front_end/models/trace/handlers/ScriptsHandler.ts +336 -0
- package/lib/front_end/models/trace/handlers/SelectorStatsHandler.ts +110 -0
- package/lib/front_end/models/trace/handlers/Threads.ts +139 -0
- package/lib/front_end/models/trace/handlers/UserInteractionsHandler.ts +400 -0
- package/lib/front_end/models/trace/handlers/UserTimingsHandler.ts +233 -0
- package/lib/front_end/models/trace/handlers/WarningsHandler.ts +162 -0
- package/lib/front_end/models/trace/handlers/WorkersHandler.ts +45 -0
- package/lib/front_end/models/trace/handlers/handlers.ts +8 -0
- package/lib/front_end/models/trace/handlers/helpers.ts +196 -0
- package/lib/front_end/models/trace/handlers/types.ts +75 -0
- package/lib/front_end/models/trace/helpers/Extensions.ts +54 -0
- package/lib/front_end/models/trace/helpers/Network.ts +129 -0
- package/lib/front_end/models/trace/helpers/SamplesIntegrator.ts +544 -0
- package/lib/front_end/models/trace/helpers/SyntheticEvents.ts +87 -0
- package/lib/front_end/models/trace/helpers/Timing.ts +248 -0
- package/lib/front_end/models/trace/helpers/Trace.ts +928 -0
- package/lib/front_end/models/trace/helpers/TreeHelpers.ts +320 -0
- package/lib/front_end/models/trace/helpers/helpers.ts +11 -0
- package/lib/front_end/models/trace/insights/CLSCulprits.ts +668 -0
- package/lib/front_end/models/trace/insights/Cache.ts +269 -0
- package/lib/front_end/models/trace/insights/Common.ts +453 -0
- package/lib/front_end/models/trace/insights/DOMSize.ts +223 -0
- package/lib/front_end/models/trace/insights/DocumentLatency.ts +319 -0
- package/lib/front_end/models/trace/insights/DuplicatedJavaScript.ts +126 -0
- package/lib/front_end/models/trace/insights/FontDisplay.ts +119 -0
- package/lib/front_end/models/trace/insights/ForcedReflow.ts +220 -0
- package/lib/front_end/models/trace/insights/INPBreakdown.ts +171 -0
- package/lib/front_end/models/trace/insights/ImageDelivery.ts +348 -0
- package/lib/front_end/models/trace/insights/LCPBreakdown.ts +268 -0
- package/lib/front_end/models/trace/insights/LCPDiscovery.ts +237 -0
- package/lib/front_end/models/trace/insights/LegacyJavaScript.ts +138 -0
- package/lib/front_end/models/trace/insights/Models.ts +22 -0
- package/lib/front_end/models/trace/insights/ModernHTTP.ts +257 -0
- package/lib/front_end/models/trace/insights/NetworkDependencyTree.ts +726 -0
- package/lib/front_end/models/trace/insights/RenderBlocking.ts +257 -0
- package/lib/front_end/models/trace/insights/SlowCSSSelector.ts +175 -0
- package/lib/front_end/models/trace/insights/Statistics.ts +101 -0
- package/lib/front_end/models/trace/insights/ThirdParties.ts +130 -0
- package/lib/front_end/models/trace/insights/Viewport.ts +138 -0
- package/lib/front_end/models/trace/insights/insights.ts +10 -0
- package/lib/front_end/models/trace/insights/types.ts +157 -0
- package/lib/front_end/models/trace/lantern/core/LanternError.ts +7 -0
- package/lib/front_end/models/trace/lantern/core/NetworkAnalyzer.ts +619 -0
- package/lib/front_end/models/trace/lantern/core/core.ts +6 -0
- package/lib/front_end/models/trace/lantern/graph/BaseNode.ts +345 -0
- package/lib/front_end/models/trace/lantern/graph/CPUNode.ts +80 -0
- package/lib/front_end/models/trace/lantern/graph/NetworkNode.ts +101 -0
- package/lib/front_end/models/trace/lantern/graph/PageDependencyGraph.ts +636 -0
- package/lib/front_end/models/trace/lantern/graph/graph.ts +8 -0
- package/lib/front_end/models/trace/lantern/lantern.ts +17 -0
- package/lib/front_end/models/trace/lantern/metrics/FirstContentfulPaint.ts +187 -0
- package/lib/front_end/models/trace/lantern/metrics/Interactive.ts +88 -0
- package/lib/front_end/models/trace/lantern/metrics/LargestContentfulPaint.ts +92 -0
- package/lib/front_end/models/trace/lantern/metrics/MaxPotentialFID.ts +72 -0
- package/lib/front_end/models/trace/lantern/metrics/Metric.ts +126 -0
- package/lib/front_end/models/trace/lantern/metrics/SpeedIndex.ts +126 -0
- package/lib/front_end/models/trace/lantern/metrics/TBTUtils.ts +82 -0
- package/lib/front_end/models/trace/lantern/metrics/TotalBlockingTime.ts +112 -0
- package/lib/front_end/models/trace/lantern/metrics/metrics.ts +12 -0
- package/lib/front_end/models/trace/lantern/simulation/ConnectionPool.ts +150 -0
- package/lib/front_end/models/trace/lantern/simulation/Constants.ts +46 -0
- package/lib/front_end/models/trace/lantern/simulation/DNSCache.ts +61 -0
- package/lib/front_end/models/trace/lantern/simulation/SimulationTimingMap.ts +196 -0
- package/lib/front_end/models/trace/lantern/simulation/Simulator.ts +556 -0
- package/lib/front_end/models/trace/lantern/simulation/TCPConnection.ts +192 -0
- package/lib/front_end/models/trace/lantern/simulation/simulation.ts +10 -0
- package/lib/front_end/models/trace/lantern/types/Lantern.ts +220 -0
- package/lib/front_end/models/trace/lantern/types/types.ts +5 -0
- package/lib/front_end/models/trace/trace.ts +33 -0
- package/lib/front_end/models/trace/types/Configuration.ts +110 -0
- package/lib/front_end/models/trace/types/Extensions.ts +136 -0
- package/lib/front_end/models/trace/types/File.ts +281 -0
- package/lib/front_end/models/trace/types/Overlays.ts +138 -0
- package/lib/front_end/models/trace/types/Timing.ts +30 -0
- package/lib/front_end/models/trace/types/TraceEvents.ts +3277 -0
- package/lib/front_end/models/trace/types/types.ts +10 -0
- package/lib/front_end/third_party/i18n/LICENSE +202 -0
- package/lib/front_end/third_party/i18n/README.chromium +15 -0
- package/lib/front_end/third_party/i18n/i18n-impl.ts +61 -0
- package/lib/front_end/third_party/i18n/i18n.ts +11 -0
- package/lib/front_end/third_party/i18n/localized-string-set.ts +129 -0
- package/lib/front_end/third_party/intl-messageformat/LICENSE +33 -0
- package/lib/front_end/third_party/intl-messageformat/README.chromium +24 -0
- package/lib/front_end/third_party/intl-messageformat/intl-messageformat-tsconfig.json +16 -0
- package/lib/front_end/third_party/intl-messageformat/intl-messageformat.ts +6 -0
- package/lib/front_end/third_party/intl-messageformat/package/LICENSE.md +33 -0
- package/lib/front_end/third_party/intl-messageformat/package/README.md +3 -0
- package/lib/front_end/third_party/intl-messageformat/package/index.d.ts +6 -0
- package/lib/front_end/third_party/intl-messageformat/package/index.d.ts.map +1 -0
- package/lib/front_end/third_party/intl-messageformat/package/index.js +13 -0
- package/lib/front_end/third_party/intl-messageformat/package/intl-messageformat.esm.d.ts +5 -0
- package/lib/front_end/third_party/intl-messageformat/package/intl-messageformat.esm.js +1710 -0
- package/lib/front_end/third_party/intl-messageformat/package/intl-messageformat.iife.js +1815 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/index.d.ts +6 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/index.d.ts.map +1 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/index.js +10 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/src/core.d.ts +34 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/src/core.d.ts.map +1 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/src/core.js +229 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/src/error.d.ts +28 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/src/error.d.ts.map +1 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/src/error.js +48 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/src/formatters.d.ts +34 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/src/formatters.d.ts.map +1 -0
- package/lib/front_end/third_party/intl-messageformat/package/lib/src/formatters.js +179 -0
- package/lib/front_end/third_party/intl-messageformat/package/package.json +42 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/core.d.ts +34 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/core.d.ts.map +1 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/core.js +230 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/error.d.ts +28 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/error.d.ts.map +1 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/error.js +51 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/formatters.d.ts +34 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/formatters.d.ts.map +1 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/formatters.js +182 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/error.d.ts +79 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/index.d.ts +15 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/parser.d.ts +153 -0
- package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/types.d.ts +139 -0
- package/lib/front_end/third_party/legacy-javascript/LICENSE +202 -0
- package/lib/front_end/third_party/legacy-javascript/README.chromium +13 -0
- package/lib/front_end/third_party/legacy-javascript/legacy-javascript-tsconfig.json +8 -0
- package/lib/front_end/third_party/legacy-javascript/legacy-javascript.ts +3 -0
- package/lib/front_end/third_party/legacy-javascript/lib/legacy-javascript.d.ts +18 -0
- package/lib/front_end/third_party/legacy-javascript/lib/legacy-javascript.js +943 -0
- package/lib/front_end/third_party/legacy-javascript/package.json +8 -0
- package/lib/front_end/third_party/legacy-javascript/rebuild.sh +9 -0
- package/lib/front_end/third_party/third-party-web/LICENSE +20 -0
- package/lib/front_end/third_party/third-party-web/README.chromium +13 -0
- package/lib/front_end/third_party/third-party-web/lib/nostats-subset.d.ts +2 -0
- package/lib/front_end/third_party/third-party-web/lib/nostats-subset.js +149 -0
- package/lib/front_end/third_party/third-party-web/package/LICENSE +20 -0
- package/lib/front_end/third_party/third-party-web/package/README.md +929 -0
- package/lib/front_end/third_party/third-party-web/package/dist/entities-httparchive-nostats.json +1 -0
- package/lib/front_end/third_party/third-party-web/package/dist/entities-httparchive.json +1 -0
- package/lib/front_end/third_party/third-party-web/package/dist/entities-nostats.json +1 -0
- package/lib/front_end/third_party/third-party-web/package/dist/entities.json +1 -0
- package/lib/front_end/third_party/third-party-web/package/facades.md +46 -0
- package/lib/front_end/third_party/third-party-web/package/httparchive-nostats-subset.d.ts +1 -0
- package/lib/front_end/third_party/third-party-web/package/httparchive-nostats-subset.js +1 -0
- package/lib/front_end/third_party/third-party-web/package/httparchive-subset.d.ts +1 -0
- package/lib/front_end/third_party/third-party-web/package/httparchive-subset.js +1 -0
- package/lib/front_end/third_party/third-party-web/package/lib/__snapshots__/index.test.js.snap +1006 -0
- package/lib/front_end/third_party/third-party-web/package/lib/create-entity-finder-api.js +139 -0
- package/lib/front_end/third_party/third-party-web/package/lib/create-entity-finder-api.test.js +44 -0
- package/lib/front_end/third_party/third-party-web/package/lib/entities.test.js +27 -0
- package/lib/front_end/third_party/third-party-web/package/lib/index.d.ts +34 -0
- package/lib/front_end/third_party/third-party-web/package/lib/index.js +3 -0
- package/lib/front_end/third_party/third-party-web/package/lib/index.test.js +246 -0
- package/lib/front_end/third_party/third-party-web/package/lib/markdown/faqs.partial.md +36 -0
- package/lib/front_end/third_party/third-party-web/package/lib/markdown/goals.partial.md +9 -0
- package/lib/front_end/third_party/third-party-web/package/lib/markdown/methodology.partial.md +5 -0
- package/lib/front_end/third_party/third-party-web/package/lib/markdown/template.md +151 -0
- package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-02-01.md +1 -0
- package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-03-01.md +1 -0
- package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-05-06.md +1 -0
- package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-05-13.md +14 -0
- package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2021-01-01.md +1 -0
- package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2024-07-01.md +3 -0
- package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive-nostats.d.ts +1 -0
- package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive-nostats.js +3 -0
- package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive.d.ts +1 -0
- package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive.js +3 -0
- package/lib/front_end/third_party/third-party-web/package/lib/subsets/nostats.d.ts +1 -0
- package/lib/front_end/third_party/third-party-web/package/lib/subsets/nostats.js +3 -0
- package/lib/front_end/third_party/third-party-web/package/nostats-subset.d.ts +1 -0
- package/lib/front_end/third_party/third-party-web/package/nostats-subset.js +1 -0
- package/lib/front_end/third_party/third-party-web/package/package.json +46 -0
- package/lib/front_end/third_party/third-party-web/package.json +8 -0
- package/lib/front_end/third_party/third-party-web/rebuild.sh +13 -0
- package/lib/front_end/third_party/third-party-web/third-party-web-tsconfig.json +8 -0
- package/lib/front_end/third_party/third-party-web/third-party-web.ts +3 -0
- package/package.json +24 -0
- package/patches/chrome-devtools-frontend+1.0.1533544.patch +187 -0
|
@@ -0,0 +1,1050 @@
|
|
|
1
|
+
// Copyright 2011 The Chromium Authors
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import * as InspectorBackendCommands from '../../generated/InspectorBackendCommands.js';
|
|
6
|
+
import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js';
|
|
7
|
+
import type * as Protocol from '../../generated/protocol.js';
|
|
8
|
+
import type * as Platform from '../platform/platform.js';
|
|
9
|
+
|
|
10
|
+
import {ConnectionTransport} from './ConnectionTransport.js';
|
|
11
|
+
import {NodeURL} from './NodeURL.js';
|
|
12
|
+
|
|
13
|
+
export const DevToolsStubErrorCode = -32015;
|
|
14
|
+
// TODO(dgozman): we are not reporting generic errors in tests, but we should
|
|
15
|
+
// instead report them and just have some expected errors in test expectations.
|
|
16
|
+
const GenericErrorCode = -32000;
|
|
17
|
+
const ConnectionClosedErrorCode = -32001;
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
type MessageParams = Record<string, any>;
|
|
21
|
+
|
|
22
|
+
type ProtocolDomainName = ProtocolProxyApi.ProtocolDomainName;
|
|
23
|
+
|
|
24
|
+
export interface MessageError {
|
|
25
|
+
code: number;
|
|
26
|
+
message: string;
|
|
27
|
+
data?: string|null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface Message {
|
|
31
|
+
sessionId?: string;
|
|
32
|
+
url?: Platform.DevToolsPath.UrlString;
|
|
33
|
+
id?: number;
|
|
34
|
+
error?: MessageError|null;
|
|
35
|
+
result?: Object|null;
|
|
36
|
+
method?: QualifiedName;
|
|
37
|
+
params?: MessageParams|null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface EventMessage extends Message {
|
|
41
|
+
method: QualifiedName;
|
|
42
|
+
params?: MessageParams|null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A qualified name, e.g. Domain.method */
|
|
46
|
+
export type QualifiedName = string&{qualifiedEventNameTag: string | undefined};
|
|
47
|
+
/** A qualified name, e.g. method */
|
|
48
|
+
export type UnqualifiedName = string&{unqualifiedEventNameTag: string | undefined};
|
|
49
|
+
|
|
50
|
+
export const splitQualifiedName = (string: QualifiedName): [string, UnqualifiedName] => {
|
|
51
|
+
const [domain, eventName] = string.split('.');
|
|
52
|
+
return [domain, eventName as UnqualifiedName];
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const qualifyName = (domain: string, name: UnqualifiedName): QualifiedName => {
|
|
56
|
+
return `${domain}.${name}` as QualifiedName;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
type EventParameterNames = Map<QualifiedName, string[]>;
|
|
60
|
+
type ReadonlyEventParameterNames = ReadonlyMap<QualifiedName, string[]>;
|
|
61
|
+
|
|
62
|
+
interface CommandParameter {
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
optional: boolean;
|
|
66
|
+
description: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type Callback = (error: MessageError|null, arg1: Object|null) => void;
|
|
70
|
+
|
|
71
|
+
interface CallbackWithDebugInfo {
|
|
72
|
+
callback: Callback;
|
|
73
|
+
method: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class InspectorBackend {
|
|
77
|
+
readonly agentPrototypes = new Map<ProtocolDomainName, AgentPrototype>();
|
|
78
|
+
#initialized = false;
|
|
79
|
+
#eventParameterNamesForDomain = new Map<ProtocolDomainName, EventParameterNames>();
|
|
80
|
+
readonly typeMap = new Map<QualifiedName, CommandParameter[]>();
|
|
81
|
+
readonly enumMap = new Map<QualifiedName, Record<string, string>>();
|
|
82
|
+
|
|
83
|
+
constructor() {
|
|
84
|
+
// Create the global here because registering commands will involve putting
|
|
85
|
+
// items onto the global.
|
|
86
|
+
// @ts-expect-error Global namespace instantiation
|
|
87
|
+
globalThis.Protocol ||= {};
|
|
88
|
+
|
|
89
|
+
InspectorBackendCommands.registerCommands(this);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private getOrCreateEventParameterNamesForDomain(domain: ProtocolDomainName): EventParameterNames {
|
|
93
|
+
let map = this.#eventParameterNamesForDomain.get(domain);
|
|
94
|
+
if (!map) {
|
|
95
|
+
map = new Map();
|
|
96
|
+
this.#eventParameterNamesForDomain.set(domain, map);
|
|
97
|
+
}
|
|
98
|
+
return map;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getOrCreateEventParameterNamesForDomainForTesting(domain: ProtocolDomainName): EventParameterNames {
|
|
102
|
+
return this.getOrCreateEventParameterNamesForDomain(domain);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
getEventParameterNames(): ReadonlyMap<ProtocolDomainName, ReadonlyEventParameterNames> {
|
|
106
|
+
return this.#eventParameterNamesForDomain;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static reportProtocolError(error: string, messageObject: Object): void {
|
|
110
|
+
console.error(error + ': ' + JSON.stringify(messageObject));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static reportProtocolWarning(error: string, messageObject: Object): void {
|
|
114
|
+
console.warn(error + ': ' + JSON.stringify(messageObject));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
isInitialized(): boolean {
|
|
118
|
+
return this.#initialized;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private agentPrototype(domain: ProtocolDomainName): AgentPrototype {
|
|
122
|
+
let prototype = this.agentPrototypes.get(domain);
|
|
123
|
+
if (!prototype) {
|
|
124
|
+
prototype = new AgentPrototype(domain);
|
|
125
|
+
this.agentPrototypes.set(domain, prototype);
|
|
126
|
+
}
|
|
127
|
+
return prototype;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
registerCommand(method: QualifiedName, parameters: CommandParameter[], replyArgs: string[], description: string):
|
|
131
|
+
void {
|
|
132
|
+
const [domain, command] = splitQualifiedName(method);
|
|
133
|
+
this.agentPrototype(domain as ProtocolDomainName).registerCommand(command, parameters, replyArgs, description);
|
|
134
|
+
this.#initialized = true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
registerEnum(type: QualifiedName, values: Record<string, string>): void {
|
|
138
|
+
const [domain, name] = splitQualifiedName(type);
|
|
139
|
+
// @ts-expect-error globalThis global namespace pollution
|
|
140
|
+
if (!globalThis.Protocol[domain]) {
|
|
141
|
+
// @ts-expect-error globalThis global namespace pollution
|
|
142
|
+
globalThis.Protocol[domain] = {};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// @ts-expect-error globalThis global namespace pollution
|
|
146
|
+
globalThis.Protocol[domain][name] = values;
|
|
147
|
+
this.enumMap.set(type, values);
|
|
148
|
+
this.#initialized = true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
registerType(method: QualifiedName, parameters: CommandParameter[]): void {
|
|
152
|
+
this.typeMap.set(method, parameters);
|
|
153
|
+
this.#initialized = true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
registerEvent(eventName: QualifiedName, params: string[]): void {
|
|
157
|
+
const domain = eventName.split('.')[0];
|
|
158
|
+
const eventParameterNames = this.getOrCreateEventParameterNamesForDomain(domain as ProtocolDomainName);
|
|
159
|
+
eventParameterNames.set(eventName, params);
|
|
160
|
+
this.#initialized = true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
type SendRawMessageCallback = (...args: unknown[]) => void;
|
|
165
|
+
|
|
166
|
+
export const test = {
|
|
167
|
+
/**
|
|
168
|
+
* This will get called for every protocol message.
|
|
169
|
+
* ProtocolClient.test.dumpProtocol = console.log
|
|
170
|
+
*/
|
|
171
|
+
dumpProtocol: null as ((arg0: string) => void) | null,
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Runs a function when no protocol activity is present.
|
|
175
|
+
* ProtocolClient.test.deprecatedRunAfterPendingDispatches(() => console.log('done'))
|
|
176
|
+
*/
|
|
177
|
+
deprecatedRunAfterPendingDispatches: null as ((arg0: () => void) => void) | null,
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Sends a raw message over main connection.
|
|
181
|
+
* ProtocolClient.test.sendRawMessage('Page.enable', {}, console.log)
|
|
182
|
+
*/
|
|
183
|
+
sendRawMessage: null as ((method: QualifiedName, args: Object|null, arg2: SendRawMessageCallback) => void) | null,
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Set to true to not log any errors.
|
|
187
|
+
*/
|
|
188
|
+
suppressRequestErrors: false as boolean,
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Set to get notified about any messages sent over protocol.
|
|
192
|
+
*/
|
|
193
|
+
onMessageSent: null as
|
|
194
|
+
((message: {domain: string, method: string, params: Object, id: number, sessionId?: string}) => void) |
|
|
195
|
+
null,
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Set to get notified about any messages received over protocol.
|
|
199
|
+
*/
|
|
200
|
+
onMessageReceived: null as ((message: Object) => void) | null,
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const LongPollingMethods = new Set<string>(['CSS.takeComputedStyleUpdates']);
|
|
204
|
+
|
|
205
|
+
export class SessionRouter {
|
|
206
|
+
readonly #connection: ConnectionTransport;
|
|
207
|
+
#lastMessageId = 1;
|
|
208
|
+
#pendingResponsesCount = 0;
|
|
209
|
+
readonly #pendingLongPollingMessageIds = new Set<number>();
|
|
210
|
+
readonly #sessions = new Map<string, {
|
|
211
|
+
target: TargetBase,
|
|
212
|
+
callbacks: Map<number, CallbackWithDebugInfo>,
|
|
213
|
+
proxyConnection: ConnectionTransport|undefined|null,
|
|
214
|
+
}>();
|
|
215
|
+
#pendingScripts: Array<() => void> = [];
|
|
216
|
+
|
|
217
|
+
constructor(connection: ConnectionTransport) {
|
|
218
|
+
this.#connection = connection;
|
|
219
|
+
|
|
220
|
+
test.deprecatedRunAfterPendingDispatches = this.deprecatedRunAfterPendingDispatches.bind(this);
|
|
221
|
+
test.sendRawMessage = this.sendRawMessageForTesting.bind(this);
|
|
222
|
+
|
|
223
|
+
this.#connection.setOnMessage(this.onMessage.bind(this));
|
|
224
|
+
|
|
225
|
+
this.#connection.setOnDisconnect(reason => {
|
|
226
|
+
const session = this.#sessions.get('');
|
|
227
|
+
if (session) {
|
|
228
|
+
session.target.dispose(reason);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
registerSession(target: TargetBase, sessionId: string, proxyConnection?: ConnectionTransport|null): void {
|
|
234
|
+
// Only the Audits panel uses proxy connections. If it is ever possible to have multiple active at the
|
|
235
|
+
// same time, it should be tested thoroughly.
|
|
236
|
+
if (proxyConnection) {
|
|
237
|
+
for (const session of this.#sessions.values()) {
|
|
238
|
+
if (session.proxyConnection) {
|
|
239
|
+
console.error('Multiple simultaneous proxy connections are currently unsupported');
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
this.#sessions.set(sessionId, {target, callbacks: new Map(), proxyConnection});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
unregisterSession(sessionId: string): void {
|
|
249
|
+
const session = this.#sessions.get(sessionId);
|
|
250
|
+
if (!session) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
for (const callback of session.callbacks.values()) {
|
|
254
|
+
SessionRouter.dispatchUnregisterSessionError(callback);
|
|
255
|
+
}
|
|
256
|
+
this.#sessions.delete(sessionId);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
private nextMessageId(): number {
|
|
260
|
+
return this.#lastMessageId++;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
connection(): ConnectionTransport {
|
|
264
|
+
return this.#connection;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
sendMessage(sessionId: string, domain: string, method: QualifiedName, params: Object|null, callback: Callback): void {
|
|
268
|
+
const messageId = this.nextMessageId();
|
|
269
|
+
const messageObject: Message = {
|
|
270
|
+
id: messageId,
|
|
271
|
+
method,
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
if (params) {
|
|
275
|
+
messageObject.params = params;
|
|
276
|
+
}
|
|
277
|
+
if (sessionId) {
|
|
278
|
+
messageObject.sessionId = sessionId;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (test.dumpProtocol) {
|
|
282
|
+
test.dumpProtocol('frontend: ' + JSON.stringify(messageObject));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (test.onMessageSent) {
|
|
286
|
+
const paramsObject = JSON.parse(JSON.stringify(params || {}));
|
|
287
|
+
test.onMessageSent({domain, method, params: (paramsObject as Object), id: messageId, sessionId});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
++this.#pendingResponsesCount;
|
|
291
|
+
if (LongPollingMethods.has(method)) {
|
|
292
|
+
this.#pendingLongPollingMessageIds.add(messageId);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const session = this.#sessions.get(sessionId);
|
|
296
|
+
if (!session) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
session.callbacks.set(messageId, {callback, method});
|
|
300
|
+
this.#connection.sendRawMessage(JSON.stringify(messageObject));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private sendRawMessageForTesting(method: QualifiedName, params: Object|null, callback: Callback|null, sessionId = ''):
|
|
304
|
+
void {
|
|
305
|
+
const domain = method.split('.')[0];
|
|
306
|
+
this.sendMessage(sessionId, domain, method, params, callback || (() => {}));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
private onMessage(message: string|Object): void {
|
|
310
|
+
if (test.dumpProtocol) {
|
|
311
|
+
test.dumpProtocol('backend: ' + ((typeof message === 'string') ? message : JSON.stringify(message)));
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (test.onMessageReceived) {
|
|
315
|
+
const messageObjectCopy = JSON.parse((typeof message === 'string') ? message : JSON.stringify(message));
|
|
316
|
+
test.onMessageReceived(messageObjectCopy);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const messageObject = ((typeof message === 'string') ? JSON.parse(message) : message) as Message;
|
|
320
|
+
|
|
321
|
+
// Send all messages to proxy connections.
|
|
322
|
+
let suppressUnknownMessageErrors = false;
|
|
323
|
+
for (const session of this.#sessions.values()) {
|
|
324
|
+
if (!session.proxyConnection) {
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (!session.proxyConnection.onMessage) {
|
|
329
|
+
InspectorBackend.reportProtocolError(
|
|
330
|
+
'Protocol Error: the session has a proxyConnection with no _onMessage', messageObject);
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
session.proxyConnection.onMessage(messageObject);
|
|
335
|
+
suppressUnknownMessageErrors = true;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const sessionId = messageObject.sessionId || '';
|
|
339
|
+
const session = this.#sessions.get(sessionId);
|
|
340
|
+
if (!session) {
|
|
341
|
+
// In the DevTools MCP case, we may share the transport with puppeteer so we silently
|
|
342
|
+
// ignore unknown sessions.
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// If this message is directly for the target controlled by the proxy connection, don't handle it.
|
|
347
|
+
if (session.proxyConnection) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (session.target.getNeedsNodeJSPatching()) {
|
|
352
|
+
NodeURL.patch(messageObject);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (messageObject.id !== undefined) { // just a response for some request
|
|
356
|
+
const callback = session.callbacks.get(messageObject.id);
|
|
357
|
+
session.callbacks.delete(messageObject.id);
|
|
358
|
+
if (!callback) {
|
|
359
|
+
if (messageObject.error?.code === ConnectionClosedErrorCode) {
|
|
360
|
+
// Ignore the errors that are sent as responses after the session closes.
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (!suppressUnknownMessageErrors) {
|
|
364
|
+
InspectorBackend.reportProtocolError('Protocol Error: the message with wrong id', messageObject);
|
|
365
|
+
}
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
callback.callback(messageObject.error || null, messageObject.result || null);
|
|
370
|
+
--this.#pendingResponsesCount;
|
|
371
|
+
this.#pendingLongPollingMessageIds.delete(messageObject.id);
|
|
372
|
+
|
|
373
|
+
if (this.#pendingScripts.length && !this.hasOutstandingNonLongPollingRequests()) {
|
|
374
|
+
this.deprecatedRunAfterPendingDispatches();
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
if (messageObject.method === undefined) {
|
|
378
|
+
InspectorBackend.reportProtocolError('Protocol Error: the message without method', messageObject);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
// This cast is justified as we just checked for the presence of messageObject.method.
|
|
382
|
+
const eventMessage = messageObject as EventMessage;
|
|
383
|
+
session.target.dispatch(eventMessage);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
private hasOutstandingNonLongPollingRequests(): boolean {
|
|
388
|
+
return this.#pendingResponsesCount - this.#pendingLongPollingMessageIds.size > 0;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
private deprecatedRunAfterPendingDispatches(script?: (() => void)): void {
|
|
392
|
+
if (script) {
|
|
393
|
+
this.#pendingScripts.push(script);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Execute all promises.
|
|
397
|
+
window.setTimeout(() => {
|
|
398
|
+
if (!this.hasOutstandingNonLongPollingRequests()) {
|
|
399
|
+
this.executeAfterPendingDispatches();
|
|
400
|
+
} else {
|
|
401
|
+
this.deprecatedRunAfterPendingDispatches();
|
|
402
|
+
}
|
|
403
|
+
}, 0);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
private executeAfterPendingDispatches(): void {
|
|
407
|
+
if (!this.hasOutstandingNonLongPollingRequests()) {
|
|
408
|
+
const scripts = this.#pendingScripts;
|
|
409
|
+
this.#pendingScripts = [];
|
|
410
|
+
for (let id = 0; id < scripts.length; ++id) {
|
|
411
|
+
scripts[id]();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
static dispatchConnectionError(callback: Callback, method: string): void {
|
|
417
|
+
const error = {
|
|
418
|
+
message: `Connection is closed, can\'t dispatch pending call to ${method}`,
|
|
419
|
+
code: ConnectionClosedErrorCode,
|
|
420
|
+
data: null,
|
|
421
|
+
};
|
|
422
|
+
window.setTimeout(() => callback(error, null), 0);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
static dispatchUnregisterSessionError({callback, method}: CallbackWithDebugInfo): void {
|
|
426
|
+
const error = {
|
|
427
|
+
message: `Session is unregistering, can\'t dispatch pending call to ${method}`,
|
|
428
|
+
code: ConnectionClosedErrorCode,
|
|
429
|
+
data: null,
|
|
430
|
+
};
|
|
431
|
+
window.setTimeout(() => callback(error, null), 0);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Make sure that `Domain` in get/set is only ever instantiated with one protocol domain
|
|
437
|
+
* name, because if `Domain` allows multiple domains, the type is unsound.
|
|
438
|
+
*/
|
|
439
|
+
interface AgentsMap extends Map<ProtocolDomainName, ProtocolProxyApi.ProtocolApi[ProtocolDomainName]> {
|
|
440
|
+
get<Domain extends ProtocolDomainName>(key: Domain): ProtocolProxyApi.ProtocolApi[Domain]|undefined;
|
|
441
|
+
set<Domain extends ProtocolDomainName>(key: Domain, value: ProtocolProxyApi.ProtocolApi[Domain]): this;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Make sure that `Domain` in get/set is only ever instantiated with one protocol domain
|
|
446
|
+
* name, because if `Domain` allows multiple domains, the type is unsound.
|
|
447
|
+
*/
|
|
448
|
+
interface DispatcherMap extends Map<ProtocolDomainName, ProtocolProxyApi.ProtocolDispatchers[ProtocolDomainName]> {
|
|
449
|
+
get<Domain extends ProtocolDomainName>(key: Domain): DispatcherManager<Domain>|undefined;
|
|
450
|
+
set<Domain extends ProtocolDomainName>(key: Domain, value: DispatcherManager<Domain>): this;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export class TargetBase {
|
|
454
|
+
needsNodeJSPatching: boolean;
|
|
455
|
+
readonly sessionId: string;
|
|
456
|
+
#router: SessionRouter|null;
|
|
457
|
+
#agents: AgentsMap = new Map();
|
|
458
|
+
#dispatchers: DispatcherMap = new Map();
|
|
459
|
+
|
|
460
|
+
constructor(
|
|
461
|
+
needsNodeJSPatching: boolean, parentTarget: TargetBase|null, sessionId: string,
|
|
462
|
+
connection: ConnectionTransport|null) {
|
|
463
|
+
this.needsNodeJSPatching = needsNodeJSPatching;
|
|
464
|
+
this.sessionId = sessionId;
|
|
465
|
+
|
|
466
|
+
if (parentTarget && !sessionId) {
|
|
467
|
+
throw new Error('Specifying a parent target requires a session ID');
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
let router: SessionRouter;
|
|
471
|
+
if (parentTarget && parentTarget.#router) {
|
|
472
|
+
router = parentTarget.#router;
|
|
473
|
+
} else if (connection) {
|
|
474
|
+
router = new SessionRouter(connection);
|
|
475
|
+
} else {
|
|
476
|
+
router = new SessionRouter(ConnectionTransport.getFactory()());
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
this.#router = router;
|
|
480
|
+
|
|
481
|
+
router.registerSession(this, this.sessionId);
|
|
482
|
+
|
|
483
|
+
for (const [domain, agentPrototype] of inspectorBackend.agentPrototypes) {
|
|
484
|
+
const agent = Object.create((agentPrototype));
|
|
485
|
+
agent.target = this;
|
|
486
|
+
this.#agents.set(domain, agent);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
for (const [domain, eventParameterNames] of inspectorBackend.getEventParameterNames().entries()) {
|
|
490
|
+
this.#dispatchers.set(domain, new DispatcherManager(eventParameterNames));
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
dispatch(eventMessage: EventMessage): void {
|
|
495
|
+
const [domainName, method] = splitQualifiedName(eventMessage.method);
|
|
496
|
+
const dispatcher = this.#dispatchers.get(domainName as ProtocolDomainName);
|
|
497
|
+
if (!dispatcher) {
|
|
498
|
+
InspectorBackend.reportProtocolError(
|
|
499
|
+
`Protocol Error: the message ${eventMessage.method} is for non-existing domain '${domainName}'`,
|
|
500
|
+
eventMessage);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
dispatcher.dispatch(method, eventMessage);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
dispose(_reason: string): void {
|
|
507
|
+
if (!this.#router) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
this.#router.unregisterSession(this.sessionId);
|
|
511
|
+
this.#router = null;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
isDisposed(): boolean {
|
|
515
|
+
return !this.#router;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
markAsNodeJSForTest(): void {
|
|
519
|
+
this.needsNodeJSPatching = true;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
router(): SessionRouter|null {
|
|
523
|
+
return this.#router;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// Agent accessors, keep alphabetically sorted.
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Make sure that `Domain` is only ever instantiated with one protocol domain
|
|
530
|
+
* name, because if `Domain` allows multiple domains, the type is unsound.
|
|
531
|
+
*/
|
|
532
|
+
private getAgent<Domain extends ProtocolDomainName>(domain: Domain): ProtocolProxyApi.ProtocolApi[Domain] {
|
|
533
|
+
const agent = this.#agents.get<Domain>(domain);
|
|
534
|
+
if (!agent) {
|
|
535
|
+
throw new Error('Accessing undefined agent');
|
|
536
|
+
}
|
|
537
|
+
return agent;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
accessibilityAgent(): ProtocolProxyApi.AccessibilityApi {
|
|
541
|
+
return this.getAgent('Accessibility');
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
animationAgent(): ProtocolProxyApi.AnimationApi {
|
|
545
|
+
return this.getAgent('Animation');
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
auditsAgent(): ProtocolProxyApi.AuditsApi {
|
|
549
|
+
return this.getAgent('Audits');
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
autofillAgent(): ProtocolProxyApi.AutofillApi {
|
|
553
|
+
return this.getAgent('Autofill');
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
browserAgent(): ProtocolProxyApi.BrowserApi {
|
|
557
|
+
return this.getAgent('Browser');
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
backgroundServiceAgent(): ProtocolProxyApi.BackgroundServiceApi {
|
|
561
|
+
return this.getAgent('BackgroundService');
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
cacheStorageAgent(): ProtocolProxyApi.CacheStorageApi {
|
|
565
|
+
return this.getAgent('CacheStorage');
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
cssAgent(): ProtocolProxyApi.CSSApi {
|
|
569
|
+
return this.getAgent('CSS');
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
debuggerAgent(): ProtocolProxyApi.DebuggerApi {
|
|
573
|
+
return this.getAgent('Debugger');
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
deviceOrientationAgent(): ProtocolProxyApi.DeviceOrientationApi {
|
|
577
|
+
return this.getAgent('DeviceOrientation');
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
domAgent(): ProtocolProxyApi.DOMApi {
|
|
581
|
+
return this.getAgent('DOM');
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
domdebuggerAgent(): ProtocolProxyApi.DOMDebuggerApi {
|
|
585
|
+
return this.getAgent('DOMDebugger');
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
domsnapshotAgent(): ProtocolProxyApi.DOMSnapshotApi {
|
|
589
|
+
return this.getAgent('DOMSnapshot');
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
domstorageAgent(): ProtocolProxyApi.DOMStorageApi {
|
|
593
|
+
return this.getAgent('DOMStorage');
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
emulationAgent(): ProtocolProxyApi.EmulationApi {
|
|
597
|
+
return this.getAgent('Emulation');
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
eventBreakpointsAgent(): ProtocolProxyApi.EventBreakpointsApi {
|
|
601
|
+
return this.getAgent('EventBreakpoints');
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
extensionsAgent(): ProtocolProxyApi.ExtensionsApi {
|
|
605
|
+
return this.getAgent('Extensions');
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
fetchAgent(): ProtocolProxyApi.FetchApi {
|
|
609
|
+
return this.getAgent('Fetch');
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
heapProfilerAgent(): ProtocolProxyApi.HeapProfilerApi {
|
|
613
|
+
return this.getAgent('HeapProfiler');
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
indexedDBAgent(): ProtocolProxyApi.IndexedDBApi {
|
|
617
|
+
return this.getAgent('IndexedDB');
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
inputAgent(): ProtocolProxyApi.InputApi {
|
|
621
|
+
return this.getAgent('Input');
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
ioAgent(): ProtocolProxyApi.IOApi {
|
|
625
|
+
return this.getAgent('IO');
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
inspectorAgent(): ProtocolProxyApi.InspectorApi {
|
|
629
|
+
return this.getAgent('Inspector');
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
layerTreeAgent(): ProtocolProxyApi.LayerTreeApi {
|
|
633
|
+
return this.getAgent('LayerTree');
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
logAgent(): ProtocolProxyApi.LogApi {
|
|
637
|
+
return this.getAgent('Log');
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
mediaAgent(): ProtocolProxyApi.MediaApi {
|
|
641
|
+
return this.getAgent('Media');
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
memoryAgent(): ProtocolProxyApi.MemoryApi {
|
|
645
|
+
return this.getAgent('Memory');
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
networkAgent(): ProtocolProxyApi.NetworkApi {
|
|
649
|
+
return this.getAgent('Network');
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
overlayAgent(): ProtocolProxyApi.OverlayApi {
|
|
653
|
+
return this.getAgent('Overlay');
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
pageAgent(): ProtocolProxyApi.PageApi {
|
|
657
|
+
return this.getAgent('Page');
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
preloadAgent(): ProtocolProxyApi.PreloadApi {
|
|
661
|
+
return this.getAgent('Preload');
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
profilerAgent(): ProtocolProxyApi.ProfilerApi {
|
|
665
|
+
return this.getAgent('Profiler');
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
performanceAgent(): ProtocolProxyApi.PerformanceApi {
|
|
669
|
+
return this.getAgent('Performance');
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
runtimeAgent(): ProtocolProxyApi.RuntimeApi {
|
|
673
|
+
return this.getAgent('Runtime');
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
securityAgent(): ProtocolProxyApi.SecurityApi {
|
|
677
|
+
return this.getAgent('Security');
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
serviceWorkerAgent(): ProtocolProxyApi.ServiceWorkerApi {
|
|
681
|
+
return this.getAgent('ServiceWorker');
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
storageAgent(): ProtocolProxyApi.StorageApi {
|
|
685
|
+
return this.getAgent('Storage');
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
systemInfo(): ProtocolProxyApi.SystemInfoApi {
|
|
689
|
+
return this.getAgent('SystemInfo');
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
targetAgent(): ProtocolProxyApi.TargetApi {
|
|
693
|
+
return this.getAgent('Target');
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
tracingAgent(): ProtocolProxyApi.TracingApi {
|
|
697
|
+
return this.getAgent('Tracing');
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
webAudioAgent(): ProtocolProxyApi.WebAudioApi {
|
|
701
|
+
return this.getAgent('WebAudio');
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
webAuthnAgent(): ProtocolProxyApi.WebAuthnApi {
|
|
705
|
+
return this.getAgent('WebAuthn');
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// Dispatcher registration and de-registration, keep alphabetically sorted.
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Make sure that `Domain` is only ever instantiated with one protocol domain
|
|
712
|
+
* name, because if `Domain` allows multiple domains, the type is unsound.
|
|
713
|
+
*/
|
|
714
|
+
private registerDispatcher<Domain extends ProtocolDomainName>(
|
|
715
|
+
domain: Domain, dispatcher: ProtocolProxyApi.ProtocolDispatchers[Domain]): void {
|
|
716
|
+
const manager = this.#dispatchers.get(domain);
|
|
717
|
+
if (!manager) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
manager.addDomainDispatcher(dispatcher);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Make sure that `Domain` is only ever instantiated with one protocol domain
|
|
725
|
+
* name, because if `Domain` allows multiple domains, the type is unsound.
|
|
726
|
+
*/
|
|
727
|
+
private unregisterDispatcher<Domain extends ProtocolDomainName>(
|
|
728
|
+
domain: Domain, dispatcher: ProtocolProxyApi.ProtocolDispatchers[Domain]): void {
|
|
729
|
+
const manager = this.#dispatchers.get(domain);
|
|
730
|
+
if (!manager) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
manager.removeDomainDispatcher(dispatcher);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
registerAccessibilityDispatcher(dispatcher: ProtocolProxyApi.AccessibilityDispatcher): void {
|
|
737
|
+
this.registerDispatcher('Accessibility', dispatcher);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
registerAutofillDispatcher(dispatcher: ProtocolProxyApi.AutofillDispatcher): void {
|
|
741
|
+
this.registerDispatcher('Autofill', dispatcher);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
registerAnimationDispatcher(dispatcher: ProtocolProxyApi.AnimationDispatcher): void {
|
|
745
|
+
this.registerDispatcher('Animation', dispatcher);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
registerAuditsDispatcher(dispatcher: ProtocolProxyApi.AuditsDispatcher): void {
|
|
749
|
+
this.registerDispatcher('Audits', dispatcher);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
registerCSSDispatcher(dispatcher: ProtocolProxyApi.CSSDispatcher): void {
|
|
753
|
+
this.registerDispatcher('CSS', dispatcher);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
registerBackgroundServiceDispatcher(dispatcher: ProtocolProxyApi.BackgroundServiceDispatcher): void {
|
|
757
|
+
this.registerDispatcher('BackgroundService', dispatcher);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
registerDebuggerDispatcher(dispatcher: ProtocolProxyApi.DebuggerDispatcher): void {
|
|
761
|
+
this.registerDispatcher('Debugger', dispatcher);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
unregisterDebuggerDispatcher(dispatcher: ProtocolProxyApi.DebuggerDispatcher): void {
|
|
765
|
+
this.unregisterDispatcher('Debugger', dispatcher);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
registerDOMDispatcher(dispatcher: ProtocolProxyApi.DOMDispatcher): void {
|
|
769
|
+
this.registerDispatcher('DOM', dispatcher);
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
registerDOMStorageDispatcher(dispatcher: ProtocolProxyApi.DOMStorageDispatcher): void {
|
|
773
|
+
this.registerDispatcher('DOMStorage', dispatcher);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
registerFetchDispatcher(dispatcher: ProtocolProxyApi.FetchDispatcher): void {
|
|
777
|
+
this.registerDispatcher('Fetch', dispatcher);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
registerHeapProfilerDispatcher(dispatcher: ProtocolProxyApi.HeapProfilerDispatcher): void {
|
|
781
|
+
this.registerDispatcher('HeapProfiler', dispatcher);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
registerInspectorDispatcher(dispatcher: ProtocolProxyApi.InspectorDispatcher): void {
|
|
785
|
+
this.registerDispatcher('Inspector', dispatcher);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
registerLayerTreeDispatcher(dispatcher: ProtocolProxyApi.LayerTreeDispatcher): void {
|
|
789
|
+
this.registerDispatcher('LayerTree', dispatcher);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
registerLogDispatcher(dispatcher: ProtocolProxyApi.LogDispatcher): void {
|
|
793
|
+
this.registerDispatcher('Log', dispatcher);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
registerMediaDispatcher(dispatcher: ProtocolProxyApi.MediaDispatcher): void {
|
|
797
|
+
this.registerDispatcher('Media', dispatcher);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
registerNetworkDispatcher(dispatcher: ProtocolProxyApi.NetworkDispatcher): void {
|
|
801
|
+
this.registerDispatcher('Network', dispatcher);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
registerOverlayDispatcher(dispatcher: ProtocolProxyApi.OverlayDispatcher): void {
|
|
805
|
+
this.registerDispatcher('Overlay', dispatcher);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
registerPageDispatcher(dispatcher: ProtocolProxyApi.PageDispatcher): void {
|
|
809
|
+
this.registerDispatcher('Page', dispatcher);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
registerPreloadDispatcher(dispatcher: ProtocolProxyApi.PreloadDispatcher): void {
|
|
813
|
+
this.registerDispatcher('Preload', dispatcher);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
registerProfilerDispatcher(dispatcher: ProtocolProxyApi.ProfilerDispatcher): void {
|
|
817
|
+
this.registerDispatcher('Profiler', dispatcher);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
registerRuntimeDispatcher(dispatcher: ProtocolProxyApi.RuntimeDispatcher): void {
|
|
821
|
+
this.registerDispatcher('Runtime', dispatcher);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
registerSecurityDispatcher(dispatcher: ProtocolProxyApi.SecurityDispatcher): void {
|
|
825
|
+
this.registerDispatcher('Security', dispatcher);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
registerServiceWorkerDispatcher(dispatcher: ProtocolProxyApi.ServiceWorkerDispatcher): void {
|
|
829
|
+
this.registerDispatcher('ServiceWorker', dispatcher);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
registerStorageDispatcher(dispatcher: ProtocolProxyApi.StorageDispatcher): void {
|
|
833
|
+
this.registerDispatcher('Storage', dispatcher);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
registerTargetDispatcher(dispatcher: ProtocolProxyApi.TargetDispatcher): void {
|
|
837
|
+
this.registerDispatcher('Target', dispatcher);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
registerTracingDispatcher(dispatcher: ProtocolProxyApi.TracingDispatcher): void {
|
|
841
|
+
this.registerDispatcher('Tracing', dispatcher);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
registerWebAudioDispatcher(dispatcher: ProtocolProxyApi.WebAudioDispatcher): void {
|
|
845
|
+
this.registerDispatcher('WebAudio', dispatcher);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
registerWebAuthnDispatcher(dispatcher: ProtocolProxyApi.WebAuthnDispatcher): void {
|
|
849
|
+
this.registerDispatcher('WebAuthn', dispatcher);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
getNeedsNodeJSPatching(): boolean {
|
|
853
|
+
return this.needsNodeJSPatching;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* This is a class that serves as the prototype for a domains #agents (every target
|
|
859
|
+
* has it's own set of #agents). The InspectorBackend keeps an instance of this class
|
|
860
|
+
* per domain, and each TargetBase creates its #agents (via Object.create) and installs
|
|
861
|
+
* this instance as prototype.
|
|
862
|
+
*
|
|
863
|
+
* The reasons this is done is so that on the prototypes we can install the implementations
|
|
864
|
+
* of the invoke_enable, etc. methods that the front-end uses.
|
|
865
|
+
*/
|
|
866
|
+
class AgentPrototype {
|
|
867
|
+
replyArgs: Record<string, string[]>;
|
|
868
|
+
description = '';
|
|
869
|
+
metadata: Record<string, {parameters: CommandParameter[], description: string, replyArgs: string[]}>;
|
|
870
|
+
readonly domain: string;
|
|
871
|
+
target!: TargetBase;
|
|
872
|
+
constructor(domain: string) {
|
|
873
|
+
this.replyArgs = {};
|
|
874
|
+
this.domain = domain;
|
|
875
|
+
this.metadata = {};
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
registerCommand(
|
|
879
|
+
methodName: UnqualifiedName, parameters: CommandParameter[], replyArgs: string[], description: string): void {
|
|
880
|
+
const domainAndMethod = qualifyName(this.domain, methodName);
|
|
881
|
+
function sendMessagePromise(this: AgentPrototype, ...args: unknown[]): Promise<unknown> {
|
|
882
|
+
return AgentPrototype.prototype.sendMessageToBackendPromise.call(this, domainAndMethod, parameters, args);
|
|
883
|
+
}
|
|
884
|
+
// @ts-expect-error Method code generation
|
|
885
|
+
this[methodName] = sendMessagePromise;
|
|
886
|
+
this.metadata[domainAndMethod] = {parameters, description, replyArgs};
|
|
887
|
+
|
|
888
|
+
function invoke(this: AgentPrototype, request: Object|undefined = {}): Promise<Protocol.ProtocolResponseWithError> {
|
|
889
|
+
return this.invoke(domainAndMethod, request);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// @ts-expect-error Method code generation
|
|
893
|
+
this['invoke_' + methodName] = invoke;
|
|
894
|
+
this.replyArgs[domainAndMethod] = replyArgs;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
private prepareParameters(
|
|
898
|
+
method: string, parameters: CommandParameter[], args: unknown[], errorCallback: (arg0: string) => void): Object
|
|
899
|
+
|null {
|
|
900
|
+
const params: Record<string, unknown> = {};
|
|
901
|
+
let hasParams = false;
|
|
902
|
+
|
|
903
|
+
for (const param of parameters) {
|
|
904
|
+
const paramName = param.name;
|
|
905
|
+
const typeName = param.type;
|
|
906
|
+
const optionalFlag = param.optional;
|
|
907
|
+
|
|
908
|
+
if (!args.length && !optionalFlag) {
|
|
909
|
+
errorCallback(
|
|
910
|
+
`Protocol Error: Invalid number of arguments for method '${method}' call. ` +
|
|
911
|
+
`It must have the following arguments ${JSON.stringify(parameters)}'.`);
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
const value = args.shift();
|
|
916
|
+
if (optionalFlag && typeof value === 'undefined') {
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
const expectedJSType = typeName === 'array' ? 'object' : typeName;
|
|
920
|
+
if (typeof value !== expectedJSType) {
|
|
921
|
+
errorCallback(
|
|
922
|
+
`Protocol Error: Invalid type of argument '${paramName}' for method '${method}' call. ` +
|
|
923
|
+
`It must be '${typeName}' but it is '${typeof value}'.`);
|
|
924
|
+
return null;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
params[paramName] = value;
|
|
928
|
+
hasParams = true;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
if (args.length) {
|
|
932
|
+
errorCallback(`Protocol Error: Extra ${args.length} arguments in a call to method '${method}'.`);
|
|
933
|
+
return null;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
return hasParams ? params : null;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
private sendMessageToBackendPromise(method: QualifiedName, parameters: CommandParameter[], args: unknown[]):
|
|
940
|
+
Promise<unknown> {
|
|
941
|
+
let errorMessage;
|
|
942
|
+
function onError(message: string): void {
|
|
943
|
+
console.error(message);
|
|
944
|
+
errorMessage = message;
|
|
945
|
+
}
|
|
946
|
+
const params = this.prepareParameters(method, parameters, args, onError);
|
|
947
|
+
if (errorMessage) {
|
|
948
|
+
return Promise.resolve(null);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
return new Promise(resolve => {
|
|
952
|
+
// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
|
|
953
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
954
|
+
const callback: Callback = (error: MessageError|null, result: any|null): void => {
|
|
955
|
+
if (error) {
|
|
956
|
+
if (!test.suppressRequestErrors && error.code !== DevToolsStubErrorCode && error.code !== GenericErrorCode &&
|
|
957
|
+
error.code !== ConnectionClosedErrorCode) {
|
|
958
|
+
console.error('Request ' + method + ' failed. ' + JSON.stringify(error));
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
resolve(null);
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
const args = this.replyArgs[method];
|
|
966
|
+
resolve(result && args.length ? result[args[0]] : undefined);
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
const router = this.target.router();
|
|
970
|
+
if (!router) {
|
|
971
|
+
SessionRouter.dispatchConnectionError(callback, method);
|
|
972
|
+
} else {
|
|
973
|
+
router.sendMessage(this.target.sessionId, this.domain, method, params, callback);
|
|
974
|
+
}
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
private invoke(method: QualifiedName, request: Object|null): Promise<Protocol.ProtocolResponseWithError> {
|
|
979
|
+
return new Promise(fulfill => {
|
|
980
|
+
const callback: Callback = (error: MessageError|undefined|null, result: Object|null): void => {
|
|
981
|
+
if (error && !test.suppressRequestErrors && error.code !== DevToolsStubErrorCode &&
|
|
982
|
+
error.code !== GenericErrorCode && error.code !== ConnectionClosedErrorCode) {
|
|
983
|
+
console.error('Request ' + method + ' failed. ' + JSON.stringify(error));
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
const errorMessage = error?.message;
|
|
987
|
+
fulfill({...result, getError: () => errorMessage});
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
const router = this.target.router();
|
|
991
|
+
if (!router) {
|
|
992
|
+
SessionRouter.dispatchConnectionError(callback, method);
|
|
993
|
+
} else {
|
|
994
|
+
router.sendMessage(this.target.sessionId, this.domain, method, request, callback);
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* A `DispatcherManager` has a collection of #dispatchers that implement one of the
|
|
1002
|
+
* `ProtocolProxyApi.{Foo}Dispatcher` interfaces. Each target uses one of these per
|
|
1003
|
+
* domain to manage the registered #dispatchers. The class knows the parameter names
|
|
1004
|
+
* of the events via `#eventArgs`, which is a map managed by the inspector back-end
|
|
1005
|
+
* so that there is only one map per domain that is shared among all DispatcherManagers.
|
|
1006
|
+
*/
|
|
1007
|
+
class DispatcherManager<Domain extends ProtocolDomainName> {
|
|
1008
|
+
readonly #eventArgs: ReadonlyEventParameterNames;
|
|
1009
|
+
readonly #dispatchers: Array<ProtocolProxyApi.ProtocolDispatchers[Domain]> = [];
|
|
1010
|
+
|
|
1011
|
+
constructor(eventArgs: ReadonlyEventParameterNames) {
|
|
1012
|
+
this.#eventArgs = eventArgs;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
addDomainDispatcher(dispatcher: ProtocolProxyApi.ProtocolDispatchers[Domain]): void {
|
|
1016
|
+
this.#dispatchers.push(dispatcher);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
removeDomainDispatcher(dispatcher: ProtocolProxyApi.ProtocolDispatchers[Domain]): void {
|
|
1020
|
+
const index = this.#dispatchers.indexOf(dispatcher);
|
|
1021
|
+
if (index === -1) {
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
this.#dispatchers.splice(index, 1);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
dispatch(event: UnqualifiedName, messageObject: EventMessage): void {
|
|
1028
|
+
if (!this.#dispatchers.length) {
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
if (!this.#eventArgs.has(messageObject.method)) {
|
|
1033
|
+
InspectorBackend.reportProtocolWarning(
|
|
1034
|
+
`Protocol Warning: Attempted to dispatch an unspecified event '${messageObject.method}'`, messageObject);
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
for (let index = 0; index < this.#dispatchers.length; ++index) {
|
|
1039
|
+
const dispatcher = this.#dispatchers[index];
|
|
1040
|
+
|
|
1041
|
+
if (event in dispatcher) {
|
|
1042
|
+
const f = dispatcher[event as string as keyof ProtocolProxyApi.ProtocolDispatchers[Domain]];
|
|
1043
|
+
// @ts-expect-error Can't type check the dispatch.
|
|
1044
|
+
f.call(dispatcher, messageObject.params);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
export const inspectorBackend = new InspectorBackend();
|